1

I am having a .sql file containing all SQL queries. To run them using python script I did something like this :

cursor=cnx.cursor()
for line in open("queries_data.sql").read().split(';\n'):
    cursor.execute(line)

Now what I want to do is to store the verbose or results of each query in a log file or for time being simply print them in console.

How it can be done ? Please help.

Is there some argument available in python SQL connector ?

I want this kind of thing with each query :

Query OK, 5 rows affected (0.61 sec)
Records: 5  Duplicates: 0  Warnings: 0
mat7
  • 297
  • 3
  • 11
  • 1
    See this answer: http://stackoverflow.com/a/2511718/4770399. You can then format your print result as you want with `cursor.rowcount`. – Jean Jung Jul 10 '15 at 20:04
  • @JeanJung Isnt it something different ? – mat7 Jul 11 '15 at 04:23
  • @JeanJung It will only tell number of row affected. iSNT IT ? – mat7 Jul 11 '15 at 04:35
  • Yes, only the affected rows. But you can format your string. Looking at MySQL documentation (http://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html) you can find a way to obtain warnings too, hope this helps. The only thing i can not help you now is with duplicates. – Jean Jung Jul 11 '15 at 22:21

0 Answers0