Thread: [SQLObject] Checking if a table exists ?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Markus J. <mar...@ya...> - 2004-09-19 09:38:45
|
hello what is the best way in SQLObject to check if a table already exists. lets say I have a table of authors and a class Author. for creating the table I would call Author.createTable() now I want to check everytime I start my programm if the table already exists and if not it should be created. is there a way to this ? I could't find anything in the documentation. thanks regards Markus ___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 100MB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de |
From: <pa...@su...> - 2004-09-19 13:43:29
|
Markus Jais wrote: > hello > > what is the best way in SQLObject to check if > a table already exists. > > lets say I have a table of authors and a > class Author. > > for creating the table I would call > Author.createTable() > > now I want to check everytime I start my programm > if the table already exists and if not it should > be created. Author.createTable(ifNotExists=True) hth Paul |
From: Hendrik M. <he...@ma...> - 2004-09-19 15:07:35
|
> Author.createTable(ifNotExists=True) IMO, it would still be very handy to be able to have SQLObject check if a table exists. In fact, I think it would be very cool if SQLObject provided a method that compares an existing database table scheme to the scheme defined in an SQLObject class and returns True if they match. - Hendrik -- http://www.mans.de |
From: Ian B. <ia...@co...> - 2004-09-20 01:28:21
|
paul kölle wrote: >> now I want to check everytime I start my programm >> if the table already exists and if not it should >> be created. > > Author.createTable(ifNotExists=True) Besides this you can also do __connection__.tableExists('author'). And you could try something like: if __connection__.tableExists('author'): class DBAuthor(SQLObject): _table = 'author' _fromDatabase = True And then you could compare DBAuthor._columns with Author._columns, to make sure the schema was up-to-date. From there you might just signal an error if not, or you could try to do something more sophisticated. But be warned that this introspection is getting into undocumented portions of SQLObject, that might change in the future. -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |
From: Markus J. <mar...@ya...> - 2004-09-20 07:36:34
|
thanks.this is what I was looking for. regards markus --- Ian Bicking <ia...@co...> schrieb: > paul kölle wrote: > >> now I want to check everytime I start my programm > >> if the table already exists and if not it should > >> be created. > > > > Author.createTable(ifNotExists=True) > > Besides this you can also do > __connection__.tableExists('author'). And > you could try something like: > > if __connection__.tableExists('author'): > class DBAuthor(SQLObject): > _table = 'author' > _fromDatabase = True > > And then you could compare DBAuthor._columns with > Author._columns, to > make sure the schema was up-to-date. From there you > might just signal > an error if not, or you could try to do something > more sophisticated. > But be warned that this introspection is getting > into undocumented > portions of SQLObject, that might change in the > future. > > -- > Ian Bicking / ia...@co... / > http://blog.ianbicking.org > > > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. > Be one of 170 > Project Admins to receive an Apple iPod Mini FREE > for your judgement on > who ports your project to Linux PPC the best. > Sponsored by IBM. > Deadline: Sept. 24. Go here: > http://sf.net/ppc_contest.php > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > ___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 100MB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de |