]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix to long name generation when using oid_column as an order by
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 May 2007 20:29:26 +0000 (20:29 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 May 2007 20:29:26 +0000 (20:29 +0000)
(oids used heavily in mapper queries)

CHANGES
lib/sqlalchemy/ansisql.py
test/sql/labels.py

diff --git a/CHANGES b/CHANGES
index 64f59d05c0cba1d47ba32a7a5c6db784fb3f7d46..193025ab297097d10852984f44d396c7d53d7e1f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
     - _Label class overrides compare_self to return its ultimate object.
       meaning, if you say someexpr.label('foo') == 5, it produces
       the correct "someexpr == 5".
+    - fix to long name generation when using oid_column as an order by
+      (oids used heavily in mapper queries)
 - orm
     - "delete-orphan" no longer implies "delete". ongoing effort to 
       separate the behavior of these two operations.
index cd6e0858fae7b87efedb602e3edea00957e838bf..ab043f3ec963a88dbac1456e8a53ffa8ae1d8dca 100644 (file)
@@ -265,7 +265,7 @@ class ANSICompiler(sql.Compiled):
             name = self._truncated_identifier("colident", column.name)
         else:
             name = column.name
-                
+
         if column.table is None or not column.table.named_with_column():
             self.strings[column] = self.preparer.format_column(column, name=name)
         else:
@@ -274,7 +274,9 @@ class ANSICompiler(sql.Compiled):
                 if n is not None:
                     self.strings[column] = "%s.%s" % (self.preparer.format_table(column.table, use_schema=False), n)
                 elif len(column.table.primary_key) != 0:
-                    self.strings[column] = self.preparer.format_column_with_table(list(column.table.primary_key)[0])
+                    pk = list(column.table.primary_key)[0]
+                    pkname = (pk.is_literal and name or self._truncated_identifier("colident", pk.name))
+                    self.strings[column] = self.preparer.format_column_with_table(list(column.table.primary_key)[0], column_name=pkname)
                 else:
                     self.strings[column] = None
             else:
index 7d458da06f5181590f1647f57c4b510af4801569..ee9fa6bc50f029e202d1bbbd77edffbe2b7b5b2c 100644 (file)
@@ -22,6 +22,7 @@ class LongLabelsTest(testbase.PersistTest):
             Column("this_is_the_primarykey_column", Integer, Sequence("this_is_some_large_seq"), primary_key=True),
             Column("this_is_the_data_column", String(30))
             )
+            
         metadata.create_all()
     def tearDown(self):
         table1.delete().execute()
@@ -77,6 +78,17 @@ class LongLabelsTest(testbase.PersistTest):
       q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
       x = select([q])
       print x.execute().fetchall()
-      
+    
+    def test_oid(self):
+        """test that a primary key column compiled as the 'oid' column gets proper length truncation"""
+        from sqlalchemy.databases import postgres
+        dialect = postgres.PGDialect()
+        dialect.max_identifier_length = lambda: 30
+        tt = table1.select(use_labels=True).alias('foo')
+        x = select([tt], use_labels=True, order_by=tt.oid_column).compile(dialect=dialect)
+        #print x
+        # assert it doesnt end with "ORDER BY foo.some_large_named_table_this_is_the_primarykey_column"
+        assert str(x).endswith("""ORDER BY foo.some_large_named_table_t_1""")
+
 if __name__ == '__main__':
     testbase.main()