- _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.
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:
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:
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()
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()