summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/labels.py22
3 files changed, 22 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 4a45c3018..c0b559baf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -42,8 +42,9 @@ CHANGES
previously it was detecting DBAPI types and converting regardless).
should fix [ticket:800]
-- Firebird dialect now uses SingletonThreadPool as poolclass.
+- fix to anonymous label generation of long table/column names [ticket:806]
+- Firebird dialect now uses SingletonThreadPool as poolclass.
0.4.0beta6
----------
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 3afd3fdc3..50664db16 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -415,7 +415,7 @@ class DefaultCompiler(engine.Compiled, visitors.ClauseVisitor):
if len(anonname) > self.dialect.max_identifier_length:
counter = self.generated_ids.get(ident_class, 1)
- truncname = name[0:self.dialect.max_identifier_length - 6] + "_" + hex(counter)[2:]
+ truncname = anonname[0:self.dialect.max_identifier_length - 6] + "_" + hex(counter)[2:]
self.generated_ids[ident_class] = counter + 1
else:
truncname = anonname
diff --git a/test/sql/labels.py b/test/sql/labels.py
index 6588c4da4..6f94956dc 100644
--- a/test/sql/labels.py
+++ b/test/sql/labels.py
@@ -1,11 +1,13 @@
import testbase
from sqlalchemy import *
from testlib import *
-
+from sqlalchemy.engine import default
# TODO: either create a mock dialect with named paramstyle and a short identifier length,
# or find a way to just use sqlite dialect and make those changes
+IDENT_LENGTH = 29
+
class LabelTypeTest(PersistTest):
def test_type(self):
m = MetaData()
@@ -15,7 +17,7 @@ class LabelTypeTest(PersistTest):
assert isinstance(t.c.col1.label('hi').type, Integer)
assert isinstance(select([t.c.col2], scalar=True).label('lala').type, Float)
-class LongLabelsTest(PersistTest):
+class LongLabelsTest(SQLCompileTest):
def setUpAll(self):
global metadata, table1, maxlen
metadata = MetaData(testbase.db)
@@ -27,7 +29,7 @@ class LongLabelsTest(PersistTest):
metadata.create_all()
maxlen = testbase.db.dialect.max_identifier_length
- testbase.db.dialect.max_identifier_length = 29
+ testbase.db.dialect.max_identifier_length = IDENT_LENGTH
def tearDown(self):
table1.delete().execute()
@@ -84,6 +86,20 @@ class LongLabelsTest(PersistTest):
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
x = select([q])
print x.execute().fetchall()
+
+ def test_anon_alias(self):
+ compile_dialect = default.DefaultDialect()
+ compile_dialect.max_identifier_length = IDENT_LENGTH
+
+ q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias()
+ x = select([q], use_labels=True)
+
+ self.assert_compile(x, "SELECT anon_1.this_is_the_primarykey_column AS anon_1_this_is_the_prim_1, anon_1.this_is_the_data_column AS anon_1_this_is_the_data_2 "
+ "FROM (SELECT some_large_named_table.this_is_the_primarykey_column AS this_is_the_primarykey_column, some_large_named_table.this_is_the_data_column AS this_is_the_data_column "
+ "FROM some_large_named_table "
+ "WHERE some_large_named_table.this_is_the_primarykey_column = :some_large_named_table__1) AS anon_1", dialect=compile_dialect)
+
+ print x.execute().fetchall()
def test_oid(self):
"""test that a primary key column compiled as the 'oid' column gets proper length truncation"""