summaryrefslogtreecommitdiff
path: root/test/sql/quote.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-08-12 17:28:15 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-08-12 17:28:15 +0000
commit9e8fad2abcce364253352f042836bf58ce8f4f81 (patch)
tree5058c15280a2e56d454670deeb7a53dd8b6b1f67 /test/sql/quote.py
parentfb88b031d916ea91ce9af760a67ea27e00113c14 (diff)
downloadsqlalchemy-9e8fad2abcce364253352f042836bf58ce8f4f81.tar.gz
quoting facilities set up so that database-specific quoting can be
turned on for individual table, schema, and column identifiers when used in all queries/creates/drops. Enabled via "quote=True" in Table or Column, as well as "quote_schema=True" in Table. Thanks to Aaron Spike for his excellent efforts. [ticket:155]
Diffstat (limited to 'test/sql/quote.py')
-rw-r--r--test/sql/quote.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/sql/quote.py b/test/sql/quote.py
new file mode 100644
index 000000000..af279ffdb
--- /dev/null
+++ b/test/sql/quote.py
@@ -0,0 +1,72 @@
+from testbase import PersistTest
+import testbase
+from sqlalchemy import *
+
+class QuoteTest(PersistTest):
+ def setUpAll(self):
+ # TODO: figure out which databases/which identifiers allow special characters to be used,
+ # such as: spaces, quote characters, punctuation characters, set up tests for those as
+ # well.
+ global table1, table2, table3
+ metadata = BoundMetaData(testbase.db)
+ table1 = Table('WorstCase1', metadata,
+ Column('lowercase', Integer, primary_key=True),
+ Column('UPPERCASE', Integer),
+ Column('MixedCase', Integer, quote=True),
+ Column('ASC', Integer, quote=True),
+ quote=True)
+ table2 = Table('WorstCase2', metadata,
+ Column('desc', Integer, quote=True, primary_key=True),
+ Column('Union', Integer, quote=True),
+ Column('MixedCase', Integer, quote=True),
+ quote=True)
+ table1.create()
+ table2.create()
+
+ def tearDown(self):
+ table1.delete().execute()
+ table2.delete().execute()
+
+ def tearDownAll(self):
+ table1.drop()
+ table2.drop()
+
+ def testbasic(self):
+ table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'ASC':4},
+ {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'ASC':4},
+ {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'ASC':1})
+ table2.insert().execute({'desc':1,'Union':2,'MixedCase':3},
+ {'desc':2,'Union':2,'MixedCase':3},
+ {'desc':4,'Union':3,'MixedCase':2})
+
+ res1 = select([table1.c.lowercase, table1.c.UPPERCASE, table1.c.MixedCase, table1.c.ASC]).execute().fetchall()
+ print res1
+ assert(res1==[(1,2,3,4),(2,2,3,4),(4,3,2,1)])
+
+ res2 = select([table2.c.desc, table2.c.Union, table2.c.MixedCase]).execute().fetchall()
+ print res2
+ assert(res2==[(1,2,3),(2,2,3),(4,3,2)])
+
+ def testreflect(self):
+ meta2 = BoundMetaData(testbase.db)
+ t2 = Table('WorstCase2', meta2, autoload=True, quote=True)
+ assert t2.c.has_key('MixedCase')
+
+ def testlabels(self):
+ table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'ASC':4},
+ {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'ASC':4},
+ {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'ASC':1})
+ table2.insert().execute({'desc':1,'Union':2,'MixedCase':3},
+ {'desc':2,'Union':2,'MixedCase':3},
+ {'desc':4,'Union':3,'MixedCase':2})
+
+ res1 = select([table1.c.lowercase, table1.c.UPPERCASE, table1.c.MixedCase, table1.c.ASC], use_labels=True).execute().fetchall()
+ print res1
+ assert(res1==[(1,2,3,4),(2,2,3,4),(4,3,2,1)])
+
+ res2 = select([table2.c.desc, table2.c.Union, table2.c.MixedCase], use_labels=True).execute().fetchall()
+ print res2
+ assert(res2==[(1,2,3),(2,2,3),(4,3,2)])
+
+if __name__ == "__main__":
+ testbase.main()