[sqlalchemy] Problem with table reflection (version 0.6.6) with mysql database
Hello, I have a table with the following schema: +-+---+--+-+-++ | Field | Type | Null | Key | Default | Extra | +-+---+--+-+-++ | acc | varchar(1024) | YES | | NULL|| | is_obsolete | int(11) | YES | | NULL|| | is_root | int(11) | YES | | NULL|| | term_type | varchar(1024) | YES | | NULL|| | id | int(11) | YES | | NULL|| | cid | int(11) | NO | PRI | NULL| auto_increment | | name| varchar(1024) | YES | | NULL|| +-+---+--+-+-++ When attempting to run the following code to obtain column information programmatically... from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.engine import reflection dburi = mysql://... engine = create_engine(dburi) meta = MetaData(dburi) user_table = Table('term', meta,useexisting=True) engine.reflecttable(user_table,include_columns=True) # More verbose error trace insp = reflection.Inspector.from_engine(engine) insp.reflecttable(user_table, include_columns=True) I get the following problem: python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/reflection.pyc in reflecttable(self, table, include_columns) 383 found_table = True 384 name = col_d['name'] -- 385 if include_columns and name not in include_columns: 386 continue 387 TypeError: argument of type 'bool' is not iterable Is there a better way of obtaining table schemas? Thanks, Paul -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Problem with table reflection (version 0.6.6) with mysql database
Hello, The same error happens with version 0.6.0 as well as 0.5.8. Although for 0.5.8, the error message is different (see below). Note also that the version of the Mysql python driver is 1.2.3. Thanks!!! QLAlchemy-0.5.8-py2.6.egg/sqlalchemy/databases/mysql.pyc in reflect(self, connection, table, show_create, charset, only) 2133 2134 if only: - 2135 only = set(only) 2136 2137 for line in re.split(r'\r?\n', show_create): TypeError: 'bool' object is not iterable Cheers, Paul On Tue, Feb 8, 2011 at 1:36 PM, Paul Rigor paulri...@gmail.com wrote: Hello, I have a table with the following schema: +-+---+--+-+-++ | Field | Type | Null | Key | Default | Extra | +-+---+--+-+-++ | acc | varchar(1024) | YES | | NULL|| | is_obsolete | int(11) | YES | | NULL|| | is_root | int(11) | YES | | NULL|| | term_type | varchar(1024) | YES | | NULL|| | id | int(11) | YES | | NULL|| | cid | int(11) | NO | PRI | NULL| auto_increment | | name| varchar(1024) | YES | | NULL|| +-+---+--+-+-++ When attempting to run the following code to obtain column information programmatically... from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.engine import reflection dburi = mysql://... engine = create_engine(dburi) meta = MetaData(dburi) user_table = Table('term', meta,useexisting=True) engine.reflecttable(user_table,include_columns=True) # More verbose error trace insp = reflection.Inspector.from_engine(engine) insp.reflecttable(user_table, include_columns=True) I get the following problem: python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/reflection.pyc in reflecttable(self, table, include_columns) 383 found_table = True 384 name = col_d['name'] -- 385 if include_columns and name not in include_columns: 386 continue 387 TypeError: argument of type 'bool' is not iterable Is there a better way of obtaining table schemas? Thanks, Paul -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] reflecting schema just on a single table
Hi, Is there anyway to use a metadata object just to obtain the schema of a single table? I have a database of hundreds of tables, and calling MetaData.reflect() retrieves the schema for all of the tables. This unnecessarily uses up memory and incurs additional time for i/o to complete. Thanks, Paul -- Paul Rigor Pre-doctoral BIT Fellow and Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California, Irvine http://www.ics.uci.edu/~prigor -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: obtaining a table schema
Thanks Mike, Like I mentioned for my particular application, I won't be using the usual ORM but just the bare engine/connection. I'll just be provided with a table name and a connection. I did a little bit of research but was only able to figure out how to obtain the primary for a mysql database (ie, through the mysql dialect instance). I was just wondering if there was a transparent interface regardless of the database dialect. Paul On Wed, Apr 29, 2009 at 5:35 AM, Mike Conley mconl...@gmail.com wrote: Look at the primary_key attribute of the table instance. uu = Table('u',meta, Column('id',Integer,primary_key=True), Column('data',Integer)) print uu.primary_key.columns ['u.id'] Mike On Tue, Apr 28, 2009 at 7:53 PM, Paul Rigor (gmail) paulri...@gmail.comwrote: Hi gang, I've recently started using sqlalchemy, so hopefully this isn't a stupid question... I was wondering whether there was an easy way to obtain a particular table's schema if one is using just bare connection (ie, not using any special orm's). Specifically, is there a utility method somewhere which allows one to obtain the primary key of a table? Thanks!! paul -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: obtaining a table schema
Thanks, FYI that link you sent was very useful. For anyone else interested, here's my code snippet. I've tested this with both mysql and sqlite databases. def get_primary_key(tablename,*args,**kwargs): from sqlalchemy import MetaData metadata = MetaData(*args,**kwargs) # uri similar to instantiating an engine metadata.reflect() try: table = metadata.tables[tablename] except KeyError: table = metadata.tables.values()[0] except IndexError: raise(Exception(Error: The database does not contain any tables.)) try: primary_key = table.primary_key.keys()[0] except IndexError: raise(Exception(Error: The specified table has no primary key!)) return primary_key On Wed, Apr 29, 2009 at 12:33 PM, Michael Bayer mike...@zzzcomputing.comwrote: the Table object as well as the primary_key attribute are transparent as far as what DBAPI and database is in use. Its also not part of the ORM. there is a more fine-grained interface called the Inspector available in 0.6, but you can get the same results by reflecting a Table. On Apr 29, 2009, at 3:09 PM, Paul Rigor (gmail) wrote: Thanks Mike, Like I mentioned for my particular application, I won't be using the usual ORM but just the bare engine/connection. I'll just be provided with a table name and a connection. I did a little bit of research but was only able to figure out how to obtain the primary for a mysql database (ie, through the mysql dialect instance). I was just wondering if there was a transparent interface regardless of the database dialect. Paul On Wed, Apr 29, 2009 at 5:35 AM, Mike Conley mconl...@gmail.com wrote: Look at the primary_key attribute of the table instance. uu = Table('u',meta, Column('id',Integer,primary_key=True), Column('data',Integer)) print uu.primary_key.columns ['u.id'] Mike On Tue, Apr 28, 2009 at 7:53 PM, Paul Rigor (gmail) paulri...@gmail.comwrote: Hi gang, I've recently started using sqlalchemy, so hopefully this isn't a stupid question... I was wondering whether there was an easy way to obtain a particular table's schema if one is using just bare connection (ie, not using any special orm's). Specifically, is there a utility method somewhere which allows one to obtain the primary key of a table? Thanks!! paul -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] obtaining a table schema
Hi gang, I've recently started using sqlalchemy, so hopefully this isn't a stupid question... I was wondering whether there was an easy way to obtain a particular table's schema if one is using just bare connection (ie, not using any special orm's). Specifically, is there a utility method somewhere which allows one to obtain the primary key of a table? Thanks!! paul -- Paul Rigor Graduate Student Institute for Genomics and Bioinformatics Donald Bren School of Information and Computer Sciences University of California in Irvine 248 ICS2 Bldg. +1 (760) 536 - 6767 (skype) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---