Python Forum
using paramater markers - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: using paramater markers (/thread-23462.html)



using paramater markers - masmithrpg - Dec-31-2019

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