Python Forum

Full Version: using paramater markers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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