summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-10-29 19:31:45 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-10-29 19:31:45 +0000
commita4ce639293ddddab6ec724b0776b49a624d90a32 (patch)
treebb6edcf23f937bdd35adf1c7ac5adb2f94ff605a /lib/sqlalchemy
parent90a886cc9073138324797525821e25e82d06915e (diff)
downloadsqlalchemy-a4ce639293ddddab6ec724b0776b49a624d90a32.tar.gz
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/databases/postgres.py66
-rw-r--r--lib/sqlalchemy/schema.py8
2 files changed, 39 insertions, 35 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index ce81cd7d6..6a20e1704 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -77,6 +77,30 @@ ischema_names = {
'bytea' : PGBinary,
}
+generic_engine = ansisql.engine()
+gen_columns = schema.Table("columns", generic_engine,
+ Column("table_schema", String),
+ Column("table_name", String),
+ Column("column_name", String),
+ Column("is_nullable", Integer),
+ Column("data_type", String),
+ Column("ordinal_position", Integer),
+ schema="information_schema")
+
+gen_constraints = schema.Table("table_constraints", generic_engine,
+ Column("table_schema", String),
+ Column("table_name", String),
+ Column("constraint_name", String),
+ Column("constraint_type", String),
+ schema="information_schema")
+
+gen_column_constraints = schema.Table("constraint_column_usage", generic_engine,
+ Column("table_schema", String),
+ Column("table_name", String),
+ Column("column_name", String),
+ Column("constraint_name", String),
+ schema="information_schema")
+
def engine(opts, **params):
return PGSQLEngine(opts, **params)
@@ -178,29 +202,9 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
return self.module
def reflecttable(self, table):
-
- columns = schema.Table("columns", table.engine,
- Column("table_schema", String),
- Column("table_name", String),
- Column("column_name", String),
- Column("is_nullable", Integer),
- Column("data_type", String),
- Column("ordinal_position", Integer),
- schema="information_schema")
-
- constraints = schema.Table("table_constraints", table.engine,
- Column("table_schema", String),
- Column("table_name", String),
- Column("constraint_name", String),
- Column("constraint_type", String),
- schema="information_schema")
-
- column_constraints = schema.Table("constraint_column_usage", table.engine,
- Column("table_schema", String),
- Column("table_name", String),
- Column("column_name", String),
- Column("constraint_name", String),
- schema="information_schema")
+ columns = gen_columns.toengine(table.engine)
+ constraints = gen_constraints.toengine(table.engine)
+ column_constraints = gen_column_constraints.toengine(table.engine)
s = columns.select(columns.c.table_name==table.name, order_by=[columns.c.ordinal_position])
@@ -231,20 +235,16 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
if row is None:
break
print "row! " + repr(row)
- continue
- (name, type, nullable, primary_key) = (row[1], row[2].upper(), not row[3], row[5])
+ (name, type, nullable, primary_key) = (row[columns.c.column_name], row[columns.c.data_type], not row[columns.c.is_nullable], row[constraints.c.constraint_type] is not None)
- match = re.match(r'(\w+)(\(.*?\))?', type)
- coltype = match.group(1)
- args = match.group(2)
+ #match = re.match(r'(\w+)(\(.*?\))?', type)
+ #coltype = match.group(1)
+ #args = match.group(2)
#print "coltype: " + repr(coltype) + " args: " + repr(args)
- coltype = pragma_names[coltype]
- if args is not None:
- args = re.findall(r'(\d+)', args)
- #print "args! " +repr(args)
- coltype = coltype(*args)
+ coltype = ischema_names[type]
table.append_item(schema.Column(name, coltype, primary_key = primary_key, nullable = nullable))
+ return
c = self.execute("PRAGMA foreign_key_list(" + table.name + ")", {})
while True:
row = c.fetchone()
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 17755676b..825fbe4a7 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -120,7 +120,7 @@ class Table(SchemaItem):
args = []
for c in self.columns:
args.append(c.copy())
- return Table(self.name, engine, *args)
+ return Table(self.name, engine, schema=self.schema, *args)
class Column(SchemaItem):
"""represents a column in a database table."""
@@ -155,7 +155,11 @@ class Column(SchemaItem):
def copy(self):
"""creates a copy of this Column, unitialized"""
- return Column(self.name, self.type, key = self.key, primary_key = self.primary_key, foreign_key = self.foreign_key.copy(), sequence = self.sequence)
+ if self.foreign_key is None:
+ fk = None
+ else:
+ fk = self.foreign_key.copy()
+ return Column(self.name, self.type, key = self.key, primary_key = self.primary_key, foreign_key = fk, sequence = self.sequence)
def _make_proxy(self, selectable, name = None):
"""creates a copy of this Column, initialized the way this Column is"""