mickt
asked on
How can I check the result of mysql query in python?
I've seen lines like op.execute("CREATE LANGUAGE plpgsql") in other scripts in my system so thought I could do similar with the following.
op.execute("SHOW TABLES LIKE 'table_name'")
How can I check the result from this and then do stuff based on existence or not?
I tried result = op.fetchone() but this is incorrect.
AttributeError: 'module' object has no attribute 'fetchone'
and
if not op.execute("SHOW TABLES LIKE 'agents'"):
op.execute("SHOW TABLES LIKE 'table_name'")
How can I check the result from this and then do stuff based on existence or not?
I tried result = op.fetchone() but this is incorrect.
AttributeError: 'module' object has no attribute 'fetchone'
and
if not op.execute("SHOW TABLES LIKE 'agents'"):
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I believe you have to process 'SHOW TABLES' and similar queries just like a SELECT query because that is what they are.
ASKER
Sorry, I'm not following, can you please clarify for me?
ASKER
I cam across this too.
cursor.execute("SHOW TABLES LIKE 'table_name'")
result = cursor.fetchone()
if result:
"There is a table named table_name."
else:
do stuff
but it complains about cursor
cursor.execute("SHOW TABLES LIKE 'table_name'")
result = cursor.fetchone()
if result:
"There is a table named table_name."
else:
do stuff
but it complains about cursor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad you got it figured out. I had to get some sleep.
ASKER
Answers question.
ASKER
Multiple DB and all working.
Trying to do/not do something based on the existence of a table.