ameliabob Posted July 13, 2018 Share Posted July 13, 2018 In all the examples they all seem to create a table before accessing it. How would I go about accessing one that has already been created the following code import sqlite3 conn = sqlite3.connect('earnings.db') cur = conn.cursor() DROP TABLE closed cur.execute('CREATE TABLE closed (rowId INTEGER PRIMARY KEY AUTOINCREMENT, nature TEXT) This generates a Syntax Error with TABLE highlighted in Red. If I remove the DROP line then I get the error that the table already exists ????? Link to comment Share on other sites More sharing options...
niche Posted July 13, 2018 Share Posted July 13, 2018 Do a 'SELECT * FROM closed' . If no error, it's still there unless corrupted. closed is not a reserved word, but close is. Link to comment Share on other sites More sharing options...
Ingolme Posted July 13, 2018 Share Posted July 13, 2018 You can't just mix SQL and Python, you have to put the SQL in a string and pass the string into a database method. Try passing the "DROP TABLE" line as a string into the execute() method. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 13, 2018 Share Posted July 13, 2018 That's a syntax error because you wrote the SQL code in the middle of your python code. Link to comment Share on other sites More sharing options...
ameliabob Posted July 13, 2018 Author Share Posted July 13, 2018 Actually I am executing this from within the sqlite "idle" shell Link to comment Share on other sites More sharing options...
justsomeguy Posted July 13, 2018 Share Posted July 13, 2018 And inside the SQLite shell, you need to import the sqlite3 package? I'm pretty sure you showed python code there. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now