Re: Opening a DB Connection

Rich Shepard <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 30 Sep 2006, Gerhard Häring wrote:

> try:
>    con = sqlite3.connect("name.db")
> except sqlite3.Error:
>    pass # handle case where database file could not be opened

Gerhard,

   Ah, that's what I wanted confirmed. Thank you.

> Note that if the database file does not exist, SQLite tries to create an
> empty database instead.

   This I read. And I have the schema set up waiting for this situation with
each new project.

> You would then typically try to detect this case and create the database
> schema (quick sketch):
>
> cur = con.cursor()
> cur.execute("select count(*) from sqlite_master")
> numtables = cur.fetchone()[0]
> if numtables == 0:
>    create_schema(con)
>
> ...
>
> def create_schema(con):
>    cur = con.cursor()
>    cur.execute("create ...")

   Also, is there a man page somewhere of the cursor methods? I see
.fetchone()[0], but I don't understand the end part. What other methods are
available for navigating through a set returned by a SELECT statement?

Thanks,

Rich

- -- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.(TM)    |            Accelerator
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFHarrugEIjC001L0RAjLRAJ9/IQKG+NJmC1twJWE8BOYkHl0pjwCeMTTs
vvYplZPQK3KJ97xvIfI/f74=
=SyBo
-----END PGP SIGNATURE-----

_______________________________________________
pysqlite mailing list
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/pysqlite
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.