1
from test.lib.testing import assert_raises, assert_raises_message, eq_
2
from test.lib.engines import testing_engine
3
from test.lib import fixtures, AssertsCompiledSQL, testing
4
from sqlalchemy import *
5
from sqlalchemy import exc as exceptions
1
from sqlalchemy import exc as exceptions, select, MetaData, Integer, or_
6
2
from sqlalchemy.engine import default
7
3
from sqlalchemy.sql import table, column
8
from test.lib.schema import Table, Column
4
from sqlalchemy.testing import AssertsCompiledSQL, assert_raises, engines,\
6
from sqlalchemy.testing.schema import Table, Column
12
class LabelTypeTest(fixtures.TestBase):
15
t = Table('sometable', m,
16
Column('col1', Integer),
17
Column('col2', Float))
18
assert isinstance(t.c.col1.label('hi').type, Integer)
19
assert isinstance(select([t.c.col2]).as_scalar().label('lala').type,
22
class LongLabelsTest(fixtures.TablesTest, AssertsCompiledSQL):
27
def define_tables(cls, metadata):
28
table1 = Table("some_large_named_table", metadata,
29
Column("this_is_the_primarykey_column", Integer,
31
test_needs_autoincrement=True),
32
Column("this_is_the_data_column", String(30))
35
table2 = Table("table_with_exactly_29_characs", metadata,
36
Column("this_is_the_primarykey_column", Integer,
38
test_needs_autoincrement=True),
39
Column("this_is_the_data_column", String(30))
41
cls.tables.table1 = table1
42
cls.tables.table2 = table2
46
table1 = cls.tables.table1
47
table2 = cls.tables.table2
49
{"this_is_the_primarykey_column":1,
50
"this_is_the_data_column":"data1"},
51
{"this_is_the_primarykey_column":2,
52
"this_is_the_data_column":"data2"},
53
{"this_is_the_primarykey_column":3,
54
"this_is_the_data_column":"data3"},
55
{"this_is_the_primarykey_column":4,
56
"this_is_the_data_column":"data4"}
64
{"this_is_the_primary_key_column":1,
65
"this_is_the_data_column":"data"}
70
super(LongLabelsTest, cls).setup_class()
71
cls.maxlen = testing.db.dialect.max_identifier_length
72
testing.db.dialect.max_identifier_length = IDENT_LENGTH
75
def teardown_class(cls):
76
testing.db.dialect.max_identifier_length = cls.maxlen
77
super(LongLabelsTest, cls).teardown_class()
11
class MaxIdentTest(fixtures.TestBase, AssertsCompiledSQL):
12
__dialect__ = 'DefaultDialect'
14
table1 = table('some_large_named_table',
15
column('this_is_the_primarykey_column'),
16
column('this_is_the_data_column')
19
table2 = table('table_with_exactly_29_characs',
20
column('this_is_the_primarykey_column'),
21
column('this_is_the_data_column')
24
def _length_fixture(self, length=IDENT_LENGTH, positional=False):
25
dialect = default.DefaultDialect()
26
dialect.max_identifier_length = length
28
dialect.paramstyle = 'format'
29
dialect.positional = True
32
def _engine_fixture(self, length=IDENT_LENGTH):
33
eng = engines.testing_engine()
34
eng.dialect.max_identifier_length = length
37
def test_table_alias_1(self):
39
self.table2.alias().select(),
41
'table_with_exactly_29_c_1.'
42
'this_is_the_primarykey_column, '
43
'table_with_exactly_29_c_1.this_is_the_data_column '
45
'table_with_exactly_29_characs '
46
'AS table_with_exactly_29_c_1',
47
dialect=self._length_fixture()
50
def test_table_alias_2(self):
54
on = table1.c.this_is_the_data_column == ta.c.this_is_the_data_column
56
select([table1, ta]).select_from(table1.join(ta, on)).
57
where(ta.c.this_is_the_data_column == 'data3'),
59
'some_large_named_table.this_is_the_primarykey_column, '
60
'some_large_named_table.this_is_the_data_column, '
61
'table_with_exactly_29_c_1.this_is_the_primarykey_column, '
62
'table_with_exactly_29_c_1.this_is_the_data_column '
64
'some_large_named_table '
66
'table_with_exactly_29_characs '
68
'table_with_exactly_29_c_1 '
70
'some_large_named_table.this_is_the_data_column = '
71
'table_with_exactly_29_c_1.this_is_the_data_column '
73
'table_with_exactly_29_c_1.this_is_the_data_column = '
74
':this_is_the_data_column_1',
75
dialect=self._length_fixture()
79
78
def test_too_long_name_disallowed(self):
80
m = MetaData(testing.db)
81
t1 = Table("this_name_is_too_long_for_what_were_doing_in_this_test",
80
t = Table('this_name_is_too_long_for_what_were_doing_in_this_test',
82
81
m, Column('foo', Integer))
83
assert_raises(exceptions.IdentifierError, m.create_all)
84
assert_raises(exceptions.IdentifierError, m.drop_all)
85
assert_raises(exceptions.IdentifierError, t1.create)
86
assert_raises(exceptions.IdentifierError, t1.drop)
88
def test_basic_result(self):
89
table1 = self.tables.table1
90
s = table1.select(use_labels=True,
91
order_by=[table1.c.this_is_the_primarykey_column])
94
(row[table1.c.this_is_the_primarykey_column],
95
row[table1.c.this_is_the_data_column])
96
for row in testing.db.execute(s)
105
def test_result_limit(self):
106
table1 = self.tables.table1
107
# some dialects such as oracle (and possibly ms-sql
108
# in a future version)
109
# generate a subquery for limits/offsets.
110
# ensure that the generated result map corresponds
111
# to the selected table, not
82
eng = self._engine_fixture()
83
methods = (t.create, t.drop, m.create_all, m.drop_all)
85
assert_raises(exceptions.IdentifierError, meth, eng)
87
def _assert_labeled_table1_select(self, s):
89
compiled = s.compile(dialect=self._length_fixture())
91
assert set(compiled.result_map['some_large_named_table__2'][1]).\
94
'some_large_named_table_this_is_the_data_column',
95
'some_large_named_table__2',
96
table1.c.this_is_the_data_column
100
assert set(compiled.result_map['some_large_named_table__1'][1]).\
103
'some_large_named_table_this_is_the_primarykey_column',
104
'some_large_named_table__1',
105
table1.c.this_is_the_primarykey_column
109
def test_result_map_use_labels(self):
111
s = table1.select().apply_labels().\
112
order_by(table1.c.this_is_the_primarykey_column)
114
self._assert_labeled_table1_select(s)
116
def test_result_map_limit(self):
118
# some dialects such as oracle (and possibly ms-sql in a future
119
# version) generate a subquery for limits/offsets. ensure that the
120
# generated result map corresponds to the selected table, not the
113
122
s = table1.select(use_labels=True,
114
123
order_by=[table1.c.this_is_the_primarykey_column]).\
118
(row[table1.c.this_is_the_primarykey_column],
119
row[table1.c.this_is_the_data_column])
120
for row in testing.db.execute(s)
127
@testing.requires.offset
128
def test_result_limit_offset(self):
129
table1 = self.tables.table1
130
s = table1.select(use_labels=True,
131
order_by=[table1.c.this_is_the_primarykey_column]).\
135
(row[table1.c.this_is_the_primarykey_column],
136
row[table1.c.this_is_the_data_column])
137
for row in testing.db.execute(s)
144
def test_table_alias_1(self):
145
table2 = self.tables.table2
146
if testing.against('oracle'):
148
table2.alias().select(),
149
"SELECT table_with_exactly_29_c_1."
150
"this_is_the_primarykey_column, "
151
"table_with_exactly_29_c_1.this_is_the_data_column "
152
"FROM table_with_exactly_29_characs "
153
"table_with_exactly_29_c_1"
157
table2.alias().select(),
158
"SELECT table_with_exactly_29_c_1."
159
"this_is_the_primarykey_column, "
160
"table_with_exactly_29_c_1.this_is_the_data_column "
161
"FROM table_with_exactly_29_characs AS "
162
"table_with_exactly_29_c_1"
165
def test_table_alias_2(self):
166
table1 = self.tables.table1
167
table2 = self.tables.table2
169
dialect = default.DefaultDialect()
170
dialect.max_identifier_length = IDENT_LENGTH
172
select([table1, ta]).select_from(
174
table1.c.this_is_the_data_column==
175
ta.c.this_is_the_data_column)).\
176
where(ta.c.this_is_the_data_column=='data3'),
178
"SELECT some_large_named_table.this_is_the_primarykey_column, "
179
"some_large_named_table.this_is_the_data_column, "
180
"table_with_exactly_29_c_1.this_is_the_primarykey_column, "
181
"table_with_exactly_29_c_1.this_is_the_data_column FROM "
182
"some_large_named_table JOIN table_with_exactly_29_characs "
183
"AS table_with_exactly_29_c_1 ON "
184
"some_large_named_table.this_is_the_data_column = "
185
"table_with_exactly_29_c_1.this_is_the_data_column "
186
"WHERE table_with_exactly_29_c_1.this_is_the_data_column = "
187
":this_is_the_data_column_1",
191
def test_table_alias_3(self):
192
table2 = self.tables.table2
194
testing.db.execute(table2.alias().select()).first(),
198
def test_colbinds(self):
199
table1 = self.tables.table1
200
r = table1.select(table1.c.this_is_the_primarykey_column == 4).\
202
assert r.fetchall() == [(4, "data4")]
204
r = table1.select(or_(
125
self._assert_labeled_table1_select(s)
127
def test_result_map_subquery(self):
130
table1.c.this_is_the_primarykey_column == 4).\
133
compiled = s2.compile(dialect=self._length_fixture())
135
set(compiled.result_map['this_is_the_data_column'][1]).\
136
issuperset(['this_is_the_data_column',
137
s.c.this_is_the_data_column])
139
set(compiled.result_map['this_is_the_primarykey_column'][1]).\
140
issuperset(['this_is_the_primarykey_column',
141
s.c.this_is_the_primarykey_column])
143
def test_result_map_anon_alias(self):
145
dialect = self._length_fixture()
147
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias()
148
s = select([q]).apply_labels()
150
self.assert_compile(s,
152
'anon_1.this_is_the_primarykey_column '
153
'AS anon_1_this_is_the_prim_1, '
154
'anon_1.this_is_the_data_column '
155
'AS anon_1_this_is_the_data_2 '
158
'some_large_named_table.'
159
'this_is_the_primarykey_column '
160
'AS this_is_the_primarykey_column, '
161
'some_large_named_table.this_is_the_data_column '
162
'AS this_is_the_data_column '
164
'some_large_named_table '
166
'some_large_named_table.this_is_the_primarykey_column '
167
'= :this_is_the_primarykey__1'
171
compiled = s.compile(dialect=dialect)
172
assert set(compiled.result_map['anon_1_this_is_the_data_2'][1]).\
174
'anon_1_this_is_the_data_2',
175
q.corresponding_column(
176
table1.c.this_is_the_data_column)
179
assert set(compiled.result_map['anon_1_this_is_the_prim_1'][1]).\
181
'anon_1_this_is_the_prim_1',
182
q.corresponding_column(
183
table1.c.this_is_the_primarykey_column)
186
def test_column_bind_labels_1(self):
189
s = table1.select(table1.c.this_is_the_primarykey_column == 4)
192
"SELECT some_large_named_table.this_is_the_primarykey_column, "
193
"some_large_named_table.this_is_the_data_column "
194
"FROM some_large_named_table WHERE "
195
"some_large_named_table.this_is_the_primarykey_column = "
196
":this_is_the_primarykey__1",
197
checkparams={'this_is_the_primarykey__1': 4},
198
dialect=self._length_fixture()
203
"SELECT some_large_named_table.this_is_the_primarykey_column, "
204
"some_large_named_table.this_is_the_data_column "
205
"FROM some_large_named_table WHERE "
206
"some_large_named_table.this_is_the_primarykey_column = "
208
checkpositional=(4, ),
209
checkparams={'this_is_the_primarykey__1': 4},
210
dialect=self._length_fixture(positional=True)
213
def test_column_bind_labels_2(self):
216
s = table1.select(or_(
205
217
table1.c.this_is_the_primarykey_column == 4,
206
218
table1.c.this_is_the_primarykey_column == 2
208
assert r.fetchall() == [(2, "data2"), (4, "data4")]
210
@testing.provide_metadata
211
def test_insert_no_pk(self):
212
t = Table("some_other_large_named_table", self.metadata,
213
Column("this_is_the_primarykey_column", Integer,
214
Sequence("this_is_some_large_seq"),
216
Column("this_is_the_data_column", String(30))
218
t.create(testing.db, checkfirst=True)
219
testing.db.execute(t.insert(),
220
**{"this_is_the_data_column":"data1"})
222
@testing.requires.subqueries
223
def test_subquery(self):
224
table1 = self.tables.table1
225
q = table1.select(table1.c.this_is_the_primarykey_column == 4).\
228
list(testing.db.execute(select([q]))),
232
@testing.requires.subqueries
233
def test_anon_alias(self):
234
table1 = self.tables.table1
235
compile_dialect = default.DefaultDialect()
236
compile_dialect.max_identifier_length = IDENT_LENGTH
238
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias()
239
x = select([q], use_labels=True)
241
self.assert_compile(x,
242
"SELECT anon_1.this_is_the_primarykey_column AS "
243
"anon_1_this_is_the_prim_1, anon_1.this_is_the_data_column "
244
"AS anon_1_this_is_the_data_2 "
245
"FROM (SELECT some_large_named_table."
246
"this_is_the_primarykey_column AS "
247
"this_is_the_primarykey_column, "
248
"some_large_named_table.this_is_the_data_column "
249
"AS this_is_the_data_column "
250
"FROM some_large_named_table "
251
"WHERE some_large_named_table.this_is_the_primarykey_column "
252
"= :this_is_the_primarykey__1) AS anon_1",
253
dialect=compile_dialect)
256
list(testing.db.execute(x)),
260
def test_adjustable(self):
261
table1 = self.tables.table1
263
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
266
compile_dialect = default.DefaultDialect(label_length=10)
267
self.assert_compile(x,
268
"SELECT foo.this_1, foo.this_2 FROM "
269
"(SELECT some_large_named_table."
270
"this_is_the_primarykey_column AS this_1, "
271
"some_large_named_table.this_is_the_data_column AS this_2 "
272
"FROM some_large_named_table WHERE "
273
"some_large_named_table.this_is_the_primarykey_column = :this_1) AS foo",
274
dialect=compile_dialect)
222
"SELECT some_large_named_table.this_is_the_primarykey_column, "
223
"some_large_named_table.this_is_the_data_column "
224
"FROM some_large_named_table WHERE "
225
"some_large_named_table.this_is_the_primarykey_column = "
226
":this_is_the_primarykey__1 OR "
227
"some_large_named_table.this_is_the_primarykey_column = "
228
":this_is_the_primarykey__2",
230
'this_is_the_primarykey__1': 4,
231
'this_is_the_primarykey__2': 2
233
dialect=self._length_fixture()
237
"SELECT some_large_named_table.this_is_the_primarykey_column, "
238
"some_large_named_table.this_is_the_data_column "
239
"FROM some_large_named_table WHERE "
240
"some_large_named_table.this_is_the_primarykey_column = "
242
"some_large_named_table.this_is_the_primarykey_column = "
245
'this_is_the_primarykey__1': 4,
246
'this_is_the_primarykey__2': 2
248
checkpositional=(4, 2),
249
dialect=self._length_fixture(positional=True)
253
class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL):
254
__dialect__ = 'DefaultDialect'
256
table1 = table('some_large_named_table',
257
column('this_is_the_primarykey_column'),
258
column('this_is_the_data_column')
261
table2 = table('table_with_exactly_29_characs',
262
column('this_is_the_primarykey_column'),
263
column('this_is_the_data_column')
266
def test_adjustable_1(self):
269
table1.c.this_is_the_primarykey_column == 4).alias('foo')
271
compile_dialect = default.DefaultDialect(label_length=10)
272
self.assert_compile(x,
274
'foo.this_1, foo.this_2 '
277
'some_large_named_table.this_is_the_primarykey_column '
279
'some_large_named_table.this_is_the_data_column '
282
'some_large_named_table '
284
'some_large_named_table.this_is_the_primarykey_column '
288
dialect=compile_dialect)
290
def test_adjustable_2(self):
294
table1.c.this_is_the_primarykey_column == 4).alias('foo')
297
compile_dialect = default.DefaultDialect(label_length=10)
298
self.assert_compile(x,
300
'foo.this_1, foo.this_2 '
303
'some_large_named_table.this_is_the_primarykey_column '
305
'some_large_named_table.this_is_the_data_column '
308
'some_large_named_table '
310
'some_large_named_table.this_is_the_primarykey_column '
314
dialect=compile_dialect)
316
def test_adjustable_3(self):
276
319
compile_dialect = default.DefaultDialect(label_length=4)
277
self.assert_compile(x, "SELECT foo._1, foo._2 FROM "
278
"(SELECT some_large_named_table.this_is_the_primarykey_column "
279
"AS _1, some_large_named_table.this_is_the_data_column AS _2 "
280
"FROM some_large_named_table WHERE "
281
"some_large_named_table.this_is_the_primarykey_column = :_1) AS foo",
321
table1.c.this_is_the_primarykey_column == 4).alias('foo')
324
self.assert_compile(x,
329
'some_large_named_table.this_is_the_primarykey_column '
331
'some_large_named_table.this_is_the_data_column '
334
'some_large_named_table '
336
'some_large_named_table.this_is_the_primarykey_column '
282
340
dialect=compile_dialect)
342
def test_adjustable_4(self):
284
345
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias()
285
346
x = select([q], use_labels=True)
287
348
compile_dialect = default.DefaultDialect(label_length=10)
288
349
self.assert_compile(x,
289
"SELECT anon_1.this_2 AS anon_1, anon_1.this_4 AS anon_3 FROM "
290
"(SELECT some_large_named_table.this_is_the_primarykey_column "
291
"AS this_2, some_large_named_table.this_is_the_data_column AS this_4 "
292
"FROM some_large_named_table WHERE "
293
"some_large_named_table.this_is_the_primarykey_column = :this_1) AS anon_1",
351
'anon_1.this_2 AS anon_1, '
352
'anon_1.this_4 AS anon_3 '
355
'some_large_named_table.this_is_the_primarykey_column '
357
'some_large_named_table.this_is_the_data_column '
360
'some_large_named_table '
362
'some_large_named_table.this_is_the_primarykey_column '
294
366
dialect=compile_dialect)
368
def test_adjustable_5(self):
370
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias()
371
x = select([q], use_labels=True)
296
373
compile_dialect = default.DefaultDialect(label_length=4)
297
self.assert_compile(x, "SELECT _1._2 AS _1, _1._4 AS _3 FROM "
298
"(SELECT some_large_named_table.this_is_the_primarykey_column "
299
"AS _2, some_large_named_table.this_is_the_data_column AS _4 "
300
"FROM some_large_named_table WHERE "
301
"some_large_named_table.this_is_the_primarykey_column = :_1) AS _1",
374
self.assert_compile(x,
380
'some_large_named_table.this_is_the_primarykey_column '
382
'some_large_named_table.this_is_the_data_column '
385
'some_large_named_table '
387
'some_large_named_table.this_is_the_primarykey_column '
302
391
dialect=compile_dialect)
304
def test_adjustable_result_schema_column(self):
305
table1 = self.tables.table1
307
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
310
e = testing_engine(options={"label_length":10})
311
e.pool = testing.db.pool
312
row = e.execute(x).first()
313
eq_(row.this_is_the_primarykey_column, 4)
315
eq_(row['this_1'], 4)
317
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
318
row = e.execute(x).first()
319
eq_(row.this_is_the_primarykey_column, 4)
322
def test_adjustable_result_lightweight_column(self):
324
table1 = table("some_large_named_table",
325
column("this_is_the_primarykey_column"),
326
column("this_is_the_data_column")
329
q = table1.select(table1.c.this_is_the_primarykey_column == 4).alias('foo')
332
e = testing_engine(options={"label_length":10})
333
e.pool = testing.db.pool
334
row = e.execute(x).first()
335
eq_(row.this_is_the_primarykey_column, 4)
393
def test_adjustable_result_schema_column_1(self):
397
table1.c.this_is_the_primarykey_column == 4).apply_labels().\
400
dialect = default.DefaultDialect(label_length=10)
401
compiled = q.compile(dialect=dialect)
403
assert set(compiled.result_map['some_2'][1]).issuperset([
404
table1.c.this_is_the_data_column,
405
'some_large_named_table_this_is_the_data_column',
409
assert set(compiled.result_map['some_1'][1]).issuperset([
410
table1.c.this_is_the_primarykey_column,
411
'some_large_named_table_this_is_the_primarykey_column',
415
def test_adjustable_result_schema_column_2(self):
419
table1.c.this_is_the_primarykey_column == 4).alias('foo')
422
dialect = default.DefaultDialect(label_length=10)
423
compiled = x.compile(dialect=dialect)
425
assert set(compiled.result_map['this_2'][1]).issuperset([
426
q.corresponding_column(table1.c.this_is_the_data_column),
427
'this_is_the_data_column',
430
assert set(compiled.result_map['this_1'][1]).issuperset([
431
q.corresponding_column(table1.c.this_is_the_primarykey_column),
432
'this_is_the_primarykey_column',
338
435
def test_table_plus_column_exceeds_length(self):
339
"""test that the truncation occurs if tablename / colname are only
340
greater than the max when concatenated."""
436
"""test that the truncation only occurs when tablename + colname are
437
concatenated, if they are individually under the label length.
342
441
compile_dialect = default.DefaultDialect(label_length=30)
345
443
'thirty_characters_table_xxxxxx',
347
Column('id', Integer, primary_key=True)
351
448
'other_thirty_characters_table_',
353
Column('id', Integer, primary_key=True),
354
Column('thirty_characters_table_id',
356
ForeignKey('thirty_characters_table_xxxxxx.id'),
450
column('thirty_characters_table_id')
361
453
anon = a_table.alias()
455
j1 = other_table.outerjoin(anon,
456
anon.c.id == other_table.c.thirty_characters_table_id)
362
458
self.assert_compile(
363
select([other_table,anon]).
365
other_table.outerjoin(anon)
367
"SELECT other_thirty_characters_table_.id AS "
368
"other_thirty_characters__1, "
369
"other_thirty_characters_table_.thirty_characters_table_id "
370
"AS other_thirty_characters__2, thirty_characters_table__1.id "
371
"AS thirty_characters_table__3 "
372
"FROM other_thirty_characters_table_ "
373
"LEFT OUTER JOIN thirty_characters_table_xxxxxx "
374
"AS thirty_characters_table__1 ON "
375
"thirty_characters_table__1.id = "
376
"other_thirty_characters_table_.thirty_characters_table_id",
459
select([other_table, anon]).
460
select_from(j1).apply_labels(),
462
'other_thirty_characters_table_.id '
463
'AS other_thirty_characters__1, '
464
'other_thirty_characters_table_.thirty_characters_table_id '
465
'AS other_thirty_characters__2, '
466
'thirty_characters_table__1.id '
467
'AS thirty_characters_table__3 '
469
'other_thirty_characters_table_ '
471
'thirty_characters_table_xxxxxx AS thirty_characters_table__1 '
472
'ON thirty_characters_table__1.id = '
473
'other_thirty_characters_table_.thirty_characters_table_id',
377
474
dialect=compile_dialect)
380
select([other_table, anon]).
382
other_table.outerjoin(anon)
384
"SELECT other_thirty_characters_table_.id AS "
385
"other_thirty_characters__1, "
386
"other_thirty_characters_table_.thirty_characters_table_id "
387
"AS other_thirty_characters__2, "
388
"thirty_characters_table__1.id AS thirty_characters_table__3 "
389
"FROM other_thirty_characters_table_ "
390
"LEFT OUTER JOIN thirty_characters_table_xxxxxx "
391
"AS thirty_characters_table__1 ON "
392
"thirty_characters_table__1.id = "
393
"other_thirty_characters_table_.thirty_characters_table_id",
394
dialect=compile_dialect
476
def test_colnames_longer_than_labels_lowercase(self):
477
t1 = table('a', column('abcde'))
478
self._test_colnames_longer_than_labels(t1)
480
def test_colnames_longer_than_labels_uppercase(self):
482
t1 = Table('a', m, Column('abcde', Integer))
483
self._test_colnames_longer_than_labels(t1)
485
def _test_colnames_longer_than_labels(self, t1):
486
dialect = default.DefaultDialect(label_length=4)
487
a1 = t1.alias(name='asdf')
489
# 'abcde' is longer than 4, but rendered as itself
490
# needs to have all characters
492
self.assert_compile(select([a1]),
493
'SELECT asdf.abcde FROM a AS asdf',
495
compiled = s.compile(dialect=dialect)
496
assert set(compiled.result_map['abcde'][1]).issuperset([
497
'abcde', a1.c.abcde, 'abcde'])
499
# column still there, but short label
500
s = select([a1]).apply_labels()
501
self.assert_compile(s,
502
'SELECT asdf.abcde AS _1 FROM a AS asdf',
504
compiled = s.compile(dialect=dialect)
505
assert set(compiled.result_map['_1'][1]).issuperset([
506
'asdf_abcde', a1.c.abcde, '_1'])