0

I had a dump *.sql file of some database. I took a recipe of reading from here. Briefly, I create empty database, fill it in from the commands in the *.sql file and run some sql command to check it worked, close the database. When I reopen the databse it seems to be empty:

conn = sqlite3.connect('mine.db') #create empty database
c = conn.cursor() #coursor for the databse
fd = open('file.sql', 'r')
sqlFile = fd.read()
fd.close()
sqlCommands = sqlFile.split(';')
for command in sqlCommands:
   #here read *.sql into my database..if I understood correctly
   c.execute(command)
result = c.execute("SELECT * FROM phenotype;",conn)

But when I open my database again and try to execute sql command it says that there is no such table

    conn = sqlite3.connect('mine.db') #create empty database
    c = conn.cursor() #coursor for the databse
    result = c.execute("SELECT * FROM phenotype;",conn)
MStikh
  • 368
  • 4
  • 21
  • 1
    I think python requires an explicit commit to save the current transaction. An explicit close won't hurt either. See examples: https://docs.python.org/3/library/sqlite3.html – Shawn Oct 12 '18 at 15:51
  • I close cursor and connection after program finishes – MStikh Oct 12 '18 at 15:56
  • conn.commit() worked!! Thank you very much! I was thinking that there should be some separate command to save changes, but did not find it.. – MStikh Oct 12 '18 at 16:01

0 Answers0