Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using paramater markers
#1
I'm just beginning learning Python. I am connecting to DB2
I'm currently using version 3.6.9

I am trying to build excel spreadsheets with parameters passed into the Python3 script.
I can successfully create the .xlsx file with no parms, but i'm struggling with the parms.

So i have a script i'm calling with the following

python3 actchgdt.py 49490 20190101 20190201

i can print the parms using
print(sys.argv[1])
print(sys.argv[2])
print(sys.argv[3])
Note: it seems odd to me that if i print(sys.argv[0]) i get the program name.

now i set up my query
query = ("select bhuact, bhubld, bhuutl, rvdes, bhuuse, bhuamt, bhutax "
"from ublhu inner join urvc on bhurvc = rvrvc  "              
"and bhuact = ? and bhubld between ? and ? "
"and bhurvc <> '  '      "                                    
"order by bhubld, bhuact, bhurvc ",sys.argv[1],sys.argv[2],sys.argv[3] )  
all 3 of the fields with parameter markers are numeric in my database.

This is the error i receive
Error:
File "actchgdt.py", line 17, in <module> cursor.execute(query) File "/QOpenSys/pkgs/lib/python3.6/site-packages/ibm_db_dbi.py", line 1386, in execute self.messages.append(InterfaceError("execute expects the first argument [%s] to be of type String or Unicode." % operation ))
I've also tried coverting the parms to ints via int(sys.argv[1]) etc

how should i be handling this?

thanks

do
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to conditionally specify markers in matplotlib graph Mark17 3 3,119 Mar-03-2022, 07:42 PM
Last Post: Mark17
  How to Find & Count String Patterns Between two Markers in a HTML file ahmedwaqas92 3 2,903 Aug-19-2019, 10:12 AM
Last Post: ahmedwaqas92
  My function won't return the sum unless the last paramater is an odd number. Maximuskiller78 1 2,291 Sep-29-2018, 03:11 AM
Last Post: ichabod801
  Detecting multiple markers based on bright spots detection on raspberry pi 3 malinowydyplom 6 11,777 Nov-29-2016, 06:12 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020