On Tue, Apr 5, 2011 at 9:59 PM, michael scott <[email protected]> wrote:
> Hello guys,
>
> Since sqlite gives an error if you try to create a table that's already
> there, how do I test if a table is already present?
>
>
> for example in
>
> def database(info):
> import sqlite3
>
> connection = sqlite3.connect("test.db")
> cursor = connection.cursor()
> if table not in test.db: #with this being my test that I'm not sure how
> to implement
> cursor.execute(""" CREATE TABLE stuff (id INTEGER PRIMARY KEY, name
> TEXT)""")
> cursor.execute("""INSERT INTO stuff VALUES (null, ?)""",(info))
> cursor.commit()
> cursor.close()
> connection.close()
>
>
> How would I properly test if table not in test.db: ? Is it something as
> simple as having a method of cursor check it for me, or should I just create
> my table in the beginning of my code(outside of this function) and leave it
> out of the function all together, so I can just have my function focusing on
> inserting data?
>
> Uhm, in the immediate example I'm using, this is a function, thats inside
> of a function used by a tkinter button, a save button if you will. So I want
> it to save whatever is in the entry widget to the database. Keeping this in
> mind, am I going about it the wrong way? Should I be trying to save a
> different way?
>
>
>
>
>
>
> ----
> What is it about you... that intrigues me so?
>
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Is this really a python tutor question? Oh, well, try this:
http://lmgtfy.com/?q=sqlite+test+if+table+exists
--
Joel Goldstick
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor