![]() |
sqlite newbie question - how to know if a table exists?
Hello,
Another newbie question: How do I know if there is a table with certain name in a sqlite database? What i'm doing now is just create the table with that name, if exception occurs, that means the table is already created. Am i correct? Any better way? Thank you. kelie |
Re: sqlite newbie question - how to know if a table exists?
kf9150@gmail.com wrote:
> Hello, > > Another newbie question: How do I know if there is a table with > certain name in a sqlite database? What i'm doing now is just create > the table with that name, if exception occurs, that means the table is > already created. Am i correct? Any better way? Thank you. That approach is ok. If your SQLite library is recent enough (I don't know the exact version), you can use "create table if not exists ...". For older SQLite releases, you can check like this: len(con.execute("pragma table_info(?)", ("tablename",)).fetchall()) > 0 or con.execute("select count(*) from sqlite_master where name=?", ("tablename" ,)).fetchone() -- Gerhard |
Re: sqlite newbie question - how to know if a table exists?
On Jun 22, 12:07 am, Gerhard Häring <g...@ghaering.de> wrote:
> That approach is ok. If your SQLite library is recent enough (I don't > know the exact version), you can use "create table if not exists ...". > > -- Gerhard Thanks Gerhard. I'm using sqlite3 that came with Python2.5 installation. So "create table if not exists" works. |
| All times are GMT. The time now is 03:38 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.