Let's say I have the following code:
with open('saved_response.json') as data_file:
#data_ordered = json.load(data_file, object_pairs_hook=OrderedDict)
response=json.load(data_file)
for user_data in response['itemList']:
field_names=""
field_values=[]
for i in user_data:
field_names+=","+i
field_values.append(user_data[i])
print(field_names[1:])
print(field_values)
with con.cursor() as c:
c.execute("INSERT into user(%s) values(%s);",(field_names[1:],field_values))
I am getting the following error:
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id,parentId,username,creationTime,role,state,userProfile') values((562949953421' at line 1")
Is there any way to print the SQL query being sent to MySQL for execution so that we can resolve syntax errors like this? Also, a solution to this error will be appreciated.