I am taking a Python course at Coursera.org. While doing one of the homeworks, I was able to get a successful connection to the database and using a cursor loaded the data into a table in SQLite. It looked like it was loading fine. But, SQLite Browser did not show anything in the table.
Typically, this could mean, you forgot to commit the transaction. There I have conn.commit. So that’s not it. Or is it?
I started printing debug messages to see before and after. SELECT from the table being inserted. I even tried wrapping the code inside try..except block. No errors!! All pointed to the rows being in the table. But it only showed up inside but outside the program.
Again, from my experience with other databases, it pointed to COMMIT not being there. Is SQLite broken?? I moved around my commit statement to no avail. Then I looked at the commit statement itself. I had:
Wait! Is there a problem with my commit statement? In SQLite, the SQL operations are done through API functions. So, isn’t commit a method in Connection object? Should I include ()? I did that and the transaction did COMMIT!!!!
Some other languages make it optional (I think, Perl for e.g., accepts function calls without parantheses). I got spoiled by that. Not so with Python! This is what I call the culture of a particular language. Python silently ignored the identifier commit and the program behavior is totally unpredictable.
The lesson is don’t miss your parantheses in a function/method call!