diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-06 00:11:54 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-06 00:11:54 +0000 |
commit | bdb41655d14caed41e93225f79e5554925a15e20 (patch) | |
tree | 7e7ecf0d0dfb59b14bc34f77c5ae29e37f9f1755 /lib/sqlalchemy/databases | |
parent | e69fa9c45d77b2c27311d54155c78ee44ce551f9 (diff) | |
download | sqlalchemy-bdb41655d14caed41e93225f79e5554925a15e20.tar.gz |
added "NonExistentTable" exception throw to reflection, courtesy lbruno@republico.estv.ipv.pt, for [ticket:138]
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r-- | lib/sqlalchemy/databases/firebird.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/information_schema.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 9 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 13 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/oracle.py | 6 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 6 |
6 files changed, 37 insertions, 9 deletions
diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py index b25d62c2d..3eb287d9c 100644 --- a/lib/sqlalchemy/databases/firebird.py +++ b/lib/sqlalchemy/databases/firebird.py @@ -195,9 +195,11 @@ class FireBirdDialect(ansisql.ANSIDialect): #import pdb;pdb.set_trace() # get all of the fields for this table c = connection.execute(tblqry, [table.name.upper()]) + found_table = False while True: row = c.fetchone() if not row: break + found_table = True args = [row['FNAME']] kw = {} # get the data types and lengths @@ -208,6 +210,9 @@ class FireBirdDialect(ansisql.ANSIDialect): # is it a primary key? table.append_item(schema.Column(*args, **kw)) # does the field have indexes + + if not found_table: + raise exceptions.NoSuchTableError(table.name) def last_inserted_ids(self): return self.context.last_inserted_ids diff --git a/lib/sqlalchemy/databases/information_schema.py b/lib/sqlalchemy/databases/information_schema.py index 55c522558..3dc4a337b 100644 --- a/lib/sqlalchemy/databases/information_schema.py +++ b/lib/sqlalchemy/databases/information_schema.py @@ -3,7 +3,7 @@ import sqlalchemy.engine as engine import sqlalchemy.schema as schema import sqlalchemy.ansisql as ansisql import sqlalchemy.types as sqltypes -from sqlalchemy.exceptions import * +import sqlalchemy.exceptions as exceptions from sqlalchemy import * from sqlalchemy.ansisql import * @@ -119,12 +119,14 @@ def reflecttable(connection, table, ischema_names, use_mysql=False): order_by=[columns.c.ordinal_position]) c = connection.execute(s) + found_table = False while True: row = c.fetchone() if row is None: break #print "row! " + repr(row) # continue + found_table = True (name, type, nullable, charlen, numericprec, numericscale, default) = ( row[columns.c.column_name], row[columns.c.data_type], @@ -146,6 +148,9 @@ def reflecttable(connection, table, ischema_names, use_mysql=False): if default is not None: colargs.append(PassiveDefault(sql.text(default))) table.append_item(schema.Column(name, coltype, nullable=nullable, *colargs)) + + if not found_table: + raise exceptions.NoSuchTableError(table.name) s = select([constraints.c.constraint_name, constraints.c.constraint_type, constraints.c.table_name, key_constraints], use_labels=True, from_obj=[constraints.join(column_constraints, column_constraints.c.constraint_name==constraints.c.constraint_name).join(key_constraints, key_constraints.c.constraint_name==column_constraints.c.constraint_name)]) if not use_mysql: diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 94fbd622f..03197b00f 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -345,11 +345,12 @@ class MSSQLDialect(ansisql.ANSIDialect): order_by=[columns.c.ordinal_position]) c = connection.execute(s) + found_table = False while True: row = c.fetchone() if row is None: break - + found_table = True (name, type, nullable, charlen, numericprec, numericscale, default) = ( row[columns.c.column_name], row[columns.c.data_type], @@ -371,8 +372,10 @@ class MSSQLDialect(ansisql.ANSIDialect): colargs.append(PassiveDefault(sql.text(default))) table.append_item(schema.Column(name, coltype, nullable=nullable, *colargs)) - - + + if not found_table: + raise exceptions.NoSuchTableError(table.name) + # We also run an sp_columns to check for identity columns: # FIXME: note that this only fetches the existence of an identity column, not it's properties like (seed, increment) # also, add a check to make sure we specify the schema name of the table diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 0a480ec11..aa05134d0 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -182,15 +182,18 @@ class MySQLDialect(ansisql.ANSIDialect): # to use information_schema: #ischema.reflecttable(self, table, ischema_names, use_mysql=True) - tabletype, foreignkeyD = self.moretableinfo(connection, table=table) - table.kwargs['mysql_engine'] = tabletype - c = connection.execute("describe " + table.name, {}) + found_table = False while True: row = c.fetchone() if row is None: break #print "row! " + repr(row) + if not found_table: + tabletype, foreignkeyD = self.moretableinfo(connection, table=table) + table.kwargs['mysql_engine'] = tabletype + found_table = True + (name, type, nullable, primary_key, default) = (row[0], row[1], row[2] == 'YES', row[3] == 'PRI', row[4]) match = re.match(r'(\w+)(\(.*?\))?', type) @@ -214,6 +217,8 @@ class MySQLDialect(ansisql.ANSIDialect): nullable=nullable, default=default ))) + if not found_table: + raise exceptions.NoSuchTableError(table.name) def moretableinfo(self, connection, table): """Return (tabletype, {colname:foreignkey,...}) @@ -286,4 +291,4 @@ class MySQLSchemaDropper(ansisql.ANSISchemaDropper): self.append("\nDROP INDEX " + index.name + " ON " + index.table.name) self.execute() -dialect = MySQLDialect
\ No newline at end of file +dialect = MySQLDialect diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 167059ed2..bf6c1fd8d 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -168,10 +168,12 @@ class OracleDialect(ansisql.ANSIDialect): def reflecttable(self, connection, table): c = connection.execute ("select COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT from ALL_TAB_COLUMNS where TABLE_NAME = :table_name", {'table_name':table.name.upper()}) + found_table = False while True: row = c.fetchone() if row is None: break + found_table = True #print "ROW:" , row (name, coltype, length, precision, scale, nullable, default) = (row[0], row[1], row[2], row[3], row[4], row[5]=='Y', row[6]) @@ -201,7 +203,9 @@ class OracleDialect(ansisql.ANSIDialect): table.append_item (schema.Column(name, coltype, nullable=nullable, *colargs)) - + if not found_table: + raise exceptions.NoSuchTableError(table.name) + c = connection.execute(constraintSQL, {'table_name' : table.name.upper()}) while True: row = c.fetchone() diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index f074d02fa..b2aeb75fd 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -158,11 +158,13 @@ class SQLiteDialect(ansisql.ANSIDialect): def reflecttable(self, connection, table): c = connection.execute("PRAGMA table_info(" + table.name + ")", {}) + found_table = False while True: row = c.fetchone() if row is None: break #print "row! " + repr(row) + found_table = True (name, type, nullable, primary_key) = (row[1], row[2].upper(), not row[3], row[5]) match = re.match(r'(\w+)(\(.*?\))?', type) @@ -176,6 +178,10 @@ class SQLiteDialect(ansisql.ANSIDialect): #print "args! " +repr(args) coltype = coltype(*[int(a) for a in args]) table.append_item(schema.Column(name, coltype, primary_key = primary_key, nullable = nullable)) + + if not found_table: + raise exceptions.NoSuchTableError(table.name) + c = connection.execute("PRAGMA foreign_key_list(" + table.name + ")", {}) while True: row = c.fetchone() |