Re: creating tables needed for a query on-demand
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <OFDAB67920.47F224B1-ON85257276.004B9923-85257276.004BE053@bankofny.com> |
Here is how I do it I use the try except construct to determine if a
table exists then create it if I get a DatabaseError exception:
def createZipTable(self):
try:
cur.execute('SELECT * FROM Zip')
except sqlite.DatabaseError:
columnNames = ('Zip', \
'ID', \
'PostalCode')
cur.execute('CREATE TABLE %s \
(%s INTEGER PRIMARY KEY, \
%s VARCHAR(10))', columnNames)
self.logger.info('Created Zip Table')
Thanks,
Greg Givler
Information Technology
Lockwood®
10 Valley Stream Parkway
Malvern, PA 19355
Phone: (484) 605-4826
Email: [email protected]
Ryan Blazecka
<rblazecka-Y8iDqJfwfq2w5LPnMra/[email protected] To: [email protected]
> cc:
Sent by: Subject: [pysqlite] creating tables needed for a query on-demand
pysqlite-bounces@list
s.initd.org
02/01/2007 06:33 PM
Please respond to
"For users of the
pysqlite database
module."
hello all,
I'm wanting my application to be able to construct tables on-demand,
based on the user's queries. so for example, if the user types:
SELECT * FROM foo;
when this statement gets evaluated, my application should then check to
see if this table exists, and if not create & populate it, then execute
the query. now, I could do this by parsing the query myself to extract
any referenced table names, but this seems error-prone, and unnecessary
as SQLite is already parsing it anyways.
I've tried using an authorizer to do this, but the authorizer never sees
the requested table's name, and thus can't do anything about it (at
least not that I can see).
I could not find anything in the archives about how to make this work.
is this possible?
thanx,
ryan
_______________________________________________
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
______________________________________________________________________