Re: Threads, introspection, sharing of :memory: databases
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <OFFF52B5F4.99BDB2FF-ON85257385.004E4B3E-85257385.004EBB9B@bankofny.com> |
I am sure there are better ways of doing it, but what I do is simple:
def CreateTableFunction()
try:
select ID from foo
except sqlite.DatabaseError:
cur.execute("""CREATE TABLE foo (ID INTEGER PRIMARY KEY, FIELD1
VARCHAR(50), FIELD2 VARCHAR(30)""")
Works like a charm, of course you have to keep it in mind if your tables
are going to have lots of rows that startup will be slower. Of course most
of my uses for sqlite are just that the need of a lite database, if I am
going to have hundreds of thousands of rows, I use SQL Server..., because
we are a SQL Server shop...
Thanks,
Greg Givler
Information Technology
Lockwood®
10 Valley Stream Parkway
Malvern, PA 19355
Phone: (484) 605-4826
Email: [email protected]
Skip Montanaro <[email protected]>
Sent by: pysqlite-bounces-IAPFreCvJWPBWskQ1e/[email protected]
10/31/2007 09:28 AM
Please respond to
pysqlite list <pysqlite-IAPFreCvJWPBWskQ1e/[email protected]>
To
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
cc
Subject
[pysqlite] Threads, introspection, sharing of :memory: databases
I'm using pysqlite in some multi-threaded software. All I need is the
:memory:database. If I understand the errors I've received thusfar, I
can't
share a single connection in multiple threads. Accordingly, I need
self.connection = sqlite3.connect(":memory:")
in each thread. If I execute that in different threads is one ini-memory
database created which is shared across all threads?
Let's assume that's the case. I then need to create tables, e.g.:
cursor = self.connection.cursor()
cursor.execute("create table foo ...")
cursor.commit()
Executing that multiple times in the same thread yields an
OperationalError.
Is there not some way of introspecting the database for its tables, or do
I
just have to catch the exception?
Thanks,
Skip Montanaro
_______________________________________________
pysqlite mailing list
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/pysqlite
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please call the help desk at ext 4850
______________________________________________________________________
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
_______________________________________________
pysqlite mailing list
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/pysqlite