2005/12/17, Michael Bayer <[EMAIL PROTECTED]>:
>
> On Dec 15, 2005, at 7:41 PM, limodou wrote:
> >
> > I think if I can test the table exist as:
> >
> > if not table.name in sqlite_engine.tables:
> >      table.create()
> >
> > This code is ok?
>
>
I'v tried again, If I didn't define the table metadata first, the
sqlite_engine's talbes will be {}. So the code can not work correctly.

> well that doesnt do any kind of SQL to actually ask the database for
> a table.
>
> I think what would happen now if a table doesnt exist, is that youd
> get a Table with no columns, since for the 3 engines that do
> reflection right now its querying a view that returns zero or more rows.
>
> so maybe you could  do:
>
>         t = Table('mytable', engine, autoload=True)
>
>         exists = len(t.columns) > 0
>
> if you are really writing code where you want to create the table if
> it doesnt exist, i guess you could do the above, then if it doesnt
> exist, say:
>
>         t = Table('mytable', engine,
>                 Column('col1' ...),
>                 Column('col2', ...),
>                 ...
>                 redefine=True
>         )
>         t.create()
>
> "redefine" means to take the table thats currently in the 'tables'
> dictionary and replace its columns with the new ones.
>
> I guess what we are really looking for here is a method called
> create_if_needed(), right ?
>

Yeah, it would be great. Or may be set a option in create() just like:

t.create(notexists=True)

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to