[Tutor] (sqlite3) Testing if a table has been created.
michael scott
jigenbakuda at yahoo.com
Wed Apr 6 16:06:58 CEST 2011
________________________________
From: Joel Goldstick <joel.goldstick at gmail.com>
To: michael scott <jigenbakuda at yahoo.com>
Cc: tutor at python.org
Sent: Wed, April 6, 2011 8:30:17 AM
Subject: Re: [Tutor] (sqlite3) Testing if a table has been created.
On Tue, Apr 5, 2011 at 9:59 PM, michael scott <jigenbakuda at yahoo.com> 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 - Tutor at python.org
>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
My apologies, I was not aware that there were questions I could and could not
ask. I understand now that this is an unnacceptible question. But could you tell
me why? Was it too simple in nature? Too difficult? Did I violate some rule in
my question formatting? This was not homework or anything like that. I went
back to the tutor website to make sure I did not blatantly break one of the
rules. I only found this regarding participation.
About Tutor English (USA)
This list is for folks who want to ask questions regarding how to learn computer
programming with the Python language.
Python (http://www.python.org/) is a programming language which many feel is a
good first language, because it makes it easy to express the fundamental
concepts of programming such as data structures and algorithms with a syntax
which many find easy to read and write.
Folks interested in learning about programming with Python are encouraged to
join, as are folks interested in helping others learn. While the list is
called tutor, anyone, whether novice or expert, can answer questions.
If individuals wish to start off-line conversations about a particular concept
and become one-on-one tutor/tutee, that's fine. If either party wants to
summarize what they learned for others to benefit, that's fine too.
There is a searchable interface to archived Tutor messages on Activestate's web
site and another one at Gmane.
There are many on-line resources that can help you get started with Python. See
the Beginners Guide for a list of some good ones.
To see the collection of prior postings to the list, visit the Tutor
Archives.
So that I can avoid posting questions that don't belong on the tutor list, or so
I can have a clearer picture of what a python tutor question is, could someone
please help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110406/68b7f50c/attachment.html>
More information about the Tutor
mailing list