diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-28 07:19:14 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-28 07:19:14 +0000 |
commit | e0b638a704f7f0abf88d1a80a95cf052954e048c (patch) | |
tree | 6b8717e491820322c48b5b271ec6b192fa8a86cd /test/sql/labels.py | |
parent | ccbcbda43e74a1d09d50aa2f8212b3cb9adafd23 (diff) | |
download | sqlalchemy-e0b638a704f7f0abf88d1a80a95cf052954e048c.tar.gz |
- column label and bind param "truncation" also generate
deterministic names now, based on their ordering within the
full statement being compiled. this means the same statement
will produce the same string across application restarts and
allowing DB query plan caching to work better.
- cleanup to sql.ClauseParameters since it was just falling
apart, API made more explicit
- many unit test tweaks to adjust for bind params not being
"pre" truncated, changes to ClauseParameters
Diffstat (limited to 'test/sql/labels.py')
-rw-r--r-- | test/sql/labels.py | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/test/sql/labels.py b/test/sql/labels.py index 0302fee78..a2e899ed6 100644 --- a/test/sql/labels.py +++ b/test/sql/labels.py @@ -2,27 +2,34 @@ import testbase from sqlalchemy import * +# 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 + class LongLabelsTest(testbase.PersistTest): def setUpAll(self): global metadata, table1 metadata = MetaData(engine=testbase.db) table1 = Table("some_large_named_table", metadata, - Column("this_is_the_primary_key_column", Integer, primary_key=True), + Column("this_is_the_primarykey_column", Integer, primary_key=True), Column("this_is_the_data_column", String(30)) ) metadata.create_all() - table1.insert().execute(**{"this_is_the_primary_key_column":1, "this_is_the_data_column":"data1"}) - table1.insert().execute(**{"this_is_the_primary_key_column":2, "this_is_the_data_column":"data2"}) - table1.insert().execute(**{"this_is_the_primary_key_column":3, "this_is_the_data_column":"data3"}) - table1.insert().execute(**{"this_is_the_primary_key_column":4, "this_is_the_data_column":"data4"}) + def tearDown(self): + table1.delete().execute() + def tearDownAll(self): metadata.drop_all() def test_result(self): + table1.insert().execute(**{"this_is_the_primarykey_column":1, "this_is_the_data_column":"data1"}) + table1.insert().execute(**{"this_is_the_primarykey_column":2, "this_is_the_data_column":"data2"}) + table1.insert().execute(**{"this_is_the_primarykey_column":3, "this_is_the_data_column":"data3"}) + table1.insert().execute(**{"this_is_the_primarykey_column":4, "this_is_the_data_column":"data4"}) + r = table1.select(use_labels=True).execute() result = [] for row in r: - result.append((row[table1.c.this_is_the_primary_key_column], row[table1.c.this_is_the_data_column])) + result.append((row[table1.c.this_is_the_primarykey_column], row[table1.c.this_is_the_data_column])) assert result == [ (1, "data1"), (2, "data2"), @@ -31,14 +38,30 @@ class LongLabelsTest(testbase.PersistTest): ] def test_colbinds(self): - r = table1.select(table1.c.this_is_the_primary_key_column == 4).execute() + table1.insert().execute(**{"this_is_the_primarykey_column":1, "this_is_the_data_column":"data1"}) + table1.insert().execute(**{"this_is_the_primarykey_column":2, "this_is_the_data_column":"data2"}) + table1.insert().execute(**{"this_is_the_primarykey_column":3, "this_is_the_data_column":"data3"}) + table1.insert().execute(**{"this_is_the_primarykey_column":4, "this_is_the_data_column":"data4"}) + + r = table1.select(table1.c.this_is_the_primarykey_column == 4).execute() assert r.fetchall() == [(4, "data4")] r = table1.select(or_( - table1.c.this_is_the_primary_key_column == 4, - table1.c.this_is_the_primary_key_column == 2 + table1.c.this_is_the_primarykey_column == 4, + table1.c.this_is_the_primarykey_column == 2 )).execute() assert r.fetchall() == [(2, "data2"), (4, "data4")] + + def test_insert_no_pk(self): + table1.insert().execute(**{"this_is_the_data_column":"data1"}) + table1.insert().execute(**{"this_is_the_data_column":"data2"}) + table1.insert().execute(**{"this_is_the_data_column":"data3"}) + table1.insert().execute(**{"this_is_the_data_column":"data4"}) + + def test_subquery(self): + q = table1.select(table1.c.this_is_the_primarykey_column == 4, use_labels=True) + x = select([q]) + print str(x) if __name__ == '__main__': testbase.main()
\ No newline at end of file |