]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Oct 2005 03:03:30 +0000 (03:03 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Oct 2005 03:03:30 +0000 (03:03 +0000)
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/sql.py

index ed98fedc43fd48ca2ec288a1d2fbb3efb15c784b..36cb421d5a45661307d8e59fbabe787f1cbca35c 100644 (file)
@@ -85,6 +85,9 @@ gen_columns = schema.Table("columns", generic_engine,
     Column("is_nullable", Integer),
     Column("data_type", String),
     Column("ordinal_position", Integer),
+    Column("character_maximum_length", Integer),
+    Column("numeric_precision", Integer),
+    Column("numeric_precision_radix", Integer),
     schema="information_schema")
     
 gen_constraints = schema.Table("table_constraints", generic_engine,
@@ -208,24 +211,24 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
         
         s = select([columns, constraints.c.constraint_type], 
             columns.c.table_name==table.name, 
-            order_by=[columns.c.ordinal_position],
-            from_obj=[sql.join(columns, column_constraints, 
+            order_by=[columns.c.ordinal_position])
+            
+        s.append_from(sql.outerjoin(columns, column_constraints, 
                               sql.and_(
                                       columns.c.table_name==column_constraints.c.table_name,
                                       columns.c.table_schema==column_constraints.c.table_schema,
                                       columns.c.column_name==column_constraints.c.column_name,
-                                  ), 
-                              isouter=True).join(constraints, 
+                                  )).outerjoin(constraints, 
                                   sql.and_(
                                       column_constraints.c.table_schema==constraints.c.table_schema,
                                       column_constraints.c.constraint_name==constraints.c.constraint_name,
                                       constraints.c.constraint_type=='PRIMARY KEY'
-                                  ), isouter=True)])
+                                  )))
 
         if table.schema is not None:
             s.append_whereclause(columns.c.table_schema==table.schema)
         else:
-            current_schema = text("select current_schema()", table.engine).execute().fetchone()[0]
+            current_schema = text("select current_schema()", table.engine).scalar()
             s.append_whereclause(columns.c.table_schema==current_schema)
 
         c = s.execute()
@@ -233,8 +236,16 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
             row = c.fetchone()
             if row is None:
                 break
-            print "row! " + repr(row)
-            (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)
+            #print "row! " + repr(row)
+            (name, type, nullable, primary_key, charlen, numericprec, numericradix) = (
+                row[columns.c.column_name], 
+                row[columns.c.data_type], 
+                not row[columns.c.is_nullable], 
+                row[constraints.c.constraint_type] is not None,
+                row[columns.c.character_maximum_length],
+                row[columns.c.numeric_precision],
+                row[columns.c.numeric_precision_radix],
+                )
 
             #match = re.match(r'(\w+)(\(.*?\))?', type)
             #coltype = match.group(1)
index 6262cc3ad5e13c32f0eaa2b6efa6480603b5cf10..6ea444b29beee058f804e5a8d8907630a53f6b9e 100644 (file)
@@ -208,6 +208,12 @@ class Compiled(ClauseVisitor):
             params = self.get_params(**params)
         return self.engine.execute(str(self), params, compiled = self, typemap = self.typemap)
 
+    def scalar(self, *multiparams, **params):
+        """executes this compiled object via the execute() method, then 
+        returns the first column of the first row.  Useful for executing functions,
+        sequences, rowcounts, etc."""
+        return self.execute(*multiparams, **params).fetchone()[0]
+        
 class ClauseElement(object):
     """base class for elements of a programmatically constructed SQL expression.
     
@@ -277,9 +283,11 @@ class ClauseElement(object):
         c = self.compile(e, bindparams = bindparams)
         return c.execute(*multiparams, **params)
 
-    def result(self, **params):
-        """the same as execute(), except a RowProxy object is returned instead of a DBAPI cursor."""
-        raise NotImplementedError()
+    def scalar(self, *multiparams, **params):
+        """executes this SQL expression via the execute() method, then 
+        returns the first column of the first row.  Useful for executing functions,
+        sequences, rowcounts, etc."""
+        return self.execute(*multiparams, **params).fetchone()[0]
 
 class CompareMixin(object):
     def __lt__(self, other):