diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-31 18:58:22 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-31 18:58:22 +0000 |
commit | 0c7250a4740b26875d94fc9a1cb714fc970ea700 (patch) | |
tree | 79f3661459b4aab78681ae8c42f51944858ef0e9 /test | |
parent | 2e077dc627bfbc9f81cdb363a1ea1acf32f4cfe9 (diff) | |
download | sqlalchemy-0c7250a4740b26875d94fc9a1cb714fc970ea700.tar.gz |
- added case_sensitive argument to MetaData, Table, Column, determines
itself automatically based on if a parent schemaitem has a non-None
setting for the flag, or if not, then whether the identifier name is all lower
case or not. when set to True, quoting is applied to identifiers with mixed or
uppercase identifiers. quoting is also applied automatically in all cases to
identifiers that are known to be reserved words or contain other non-standard
characters. various database dialects can override all of this behavior, but
currently they are all using the default behavior. tested with postgres, mysql,
sqlite. needs more testing with firebird, oracle, ms-sql. part of the ongoing
work with [ticket:155]
Diffstat (limited to 'test')
-rw-r--r-- | test/orm/cycles.py | 40 | ||||
-rw-r--r-- | test/sql/quote.py | 25 | ||||
-rw-r--r-- | test/sql/select.py | 14 |
3 files changed, 45 insertions, 34 deletions
diff --git a/test/orm/cycles.py b/test/orm/cycles.py index 9d494020b..dbc234d85 100644 --- a/test/orm/cycles.py +++ b/test/orm/cycles.py @@ -217,13 +217,13 @@ class OneToManyManyToOneTest(AssertMixin): ) person = Table('person', metadata, Column('id', Integer, Sequence('person_id_seq', optional=True), primary_key=True), - Column('favoriteBall_id', Integer, ForeignKey('ball.id')), -# Column('favoriteBall_id', Integer), + Column('favorite_ball_id', Integer, ForeignKey('ball.id')), +# Column('favorite_ball_id', Integer), ) ball.create() person.create() -# person.c.favoriteBall_id.append_item(ForeignKey('ball.id')) +# person.c.favorite_ball_id.append_item(ForeignKey('ball.id')) ball.c.person_id.append_item(ForeignKey('person.id')) # make the test more complete for postgres @@ -250,7 +250,7 @@ class OneToManyManyToOneTest(AssertMixin): Ball.mapper = mapper(Ball, ball) Person.mapper = mapper(Person, person, properties= dict( balls = relation(Ball.mapper, primaryjoin=ball.c.person_id==person.c.id, foreignkey=ball.c.person_id), - favorateBall = relation(Ball.mapper, primaryjoin=person.c.favoriteBall_id==ball.c.id, foreignkey=person.c.favoriteBall_id), + favorateBall = relation(Ball.mapper, primaryjoin=person.c.favorite_ball_id==ball.c.id, foreignkey=person.c.favorite_ball_id), ) ) @@ -275,7 +275,7 @@ class OneToManyManyToOneTest(AssertMixin): Ball.mapper = mapper(Ball, ball) Person.mapper = mapper(Person, person, properties= dict( balls = relation(Ball.mapper, primaryjoin=ball.c.person_id==person.c.id, foreignkey=ball.c.person_id, post_update=False, private=True), - favorateBall = relation(Ball.mapper, primaryjoin=person.c.favoriteBall_id==ball.c.id, foreignkey=person.c.favoriteBall_id, post_update=True), + favorateBall = relation(Ball.mapper, primaryjoin=person.c.favorite_ball_id==ball.c.id, foreignkey=person.c.favorite_ball_id, post_update=True), ) ) @@ -294,8 +294,8 @@ class OneToManyManyToOneTest(AssertMixin): self.assert_sql(db, lambda: sess.flush(), [ ( - "INSERT INTO person (favoriteBall_id) VALUES (:favoriteBall_id)", - {'favoriteBall_id': None} + "INSERT INTO person (favorite_ball_id) VALUES (:favorite_ball_id)", + {'favorite_ball_id': None} ), ( "INSERT INTO ball (person_id) VALUES (:person_id)", @@ -314,14 +314,14 @@ class OneToManyManyToOneTest(AssertMixin): lambda ctx:{'person_id':p.id} ), ( - "UPDATE person SET favoriteBall_id=:favoriteBall_id WHERE person.id = :person_id", - lambda ctx:{'favoriteBall_id':p.favorateBall.id,'person_id':p.id} + "UPDATE person SET favorite_ball_id=:favorite_ball_id WHERE person.id = :person_id", + lambda ctx:{'favorite_ball_id':p.favorateBall.id,'person_id':p.id} ) ], with_sequences= [ ( - "INSERT INTO person (id, favoriteBall_id) VALUES (:id, :favoriteBall_id)", - lambda ctx:{'id':ctx.last_inserted_ids()[0], 'favoriteBall_id': None} + "INSERT INTO person (id, favorite_ball_id) VALUES (:id, :favorite_ball_id)", + lambda ctx:{'id':ctx.last_inserted_ids()[0], 'favorite_ball_id': None} ), ( "INSERT INTO ball (id, person_id) VALUES (:id, :person_id)", @@ -341,16 +341,16 @@ class OneToManyManyToOneTest(AssertMixin): ), # heres the post update ( - "UPDATE person SET favoriteBall_id=:favoriteBall_id WHERE person.id = :person_id", - lambda ctx:{'favoriteBall_id':p.favorateBall.id,'person_id':p.id} + "UPDATE person SET favorite_ball_id=:favorite_ball_id WHERE person.id = :person_id", + lambda ctx:{'favorite_ball_id':p.favorateBall.id,'person_id':p.id} ) ]) sess.delete(p) self.assert_sql(db, lambda: sess.flush(), [ # heres the post update (which is a pre-update with deletes) ( - "UPDATE person SET favoriteBall_id=:favoriteBall_id WHERE person.id = :person_id", - lambda ctx:{'person_id': p.id, 'favoriteBall_id': None} + "UPDATE person SET favorite_ball_id=:favorite_ball_id WHERE person.id = :person_id", + lambda ctx:{'person_id': p.id, 'favorite_ball_id': None} ), ( "DELETE FROM ball WHERE ball.id = :id", @@ -377,7 +377,7 @@ class OneToManyManyToOneTest(AssertMixin): Ball.mapper = mapper(Ball, ball) Person.mapper = mapper(Person, person, properties= dict( balls = relation(Ball.mapper, primaryjoin=ball.c.person_id==person.c.id, foreignkey=ball.c.person_id, private=True, post_update=True), - favorateBall = relation(Ball.mapper, primaryjoin=person.c.favoriteBall_id==ball.c.id, foreignkey=person.c.favoriteBall_id), + favorateBall = relation(Ball.mapper, primaryjoin=person.c.favorite_ball_id==ball.c.id, foreignkey=person.c.favorite_ball_id), ) ) @@ -414,8 +414,8 @@ class OneToManyManyToOneTest(AssertMixin): {'person_id':None} ), ( - "INSERT INTO person (favoriteBall_id) VALUES (:favoriteBall_id)", - lambda ctx:{'favoriteBall_id':b.id} + "INSERT INTO person (favorite_ball_id) VALUES (:favorite_ball_id)", + lambda ctx:{'favorite_ball_id':b.id} ), # heres the post update on each one-to-many item ( @@ -453,8 +453,8 @@ class OneToManyManyToOneTest(AssertMixin): lambda ctx:{'id':ctx.last_inserted_ids()[0], 'person_id':None} ), ( - "INSERT INTO person (id, favoriteBall_id) VALUES (:id, :favoriteBall_id)", - lambda ctx:{'id':ctx.last_inserted_ids()[0], 'favoriteBall_id':b.id} + "INSERT INTO person (id, favorite_ball_id) VALUES (:id, :favorite_ball_id)", + lambda ctx:{'id':ctx.last_inserted_ids()[0], 'favorite_ball_id':b.id} ), ( "UPDATE ball SET person_id=:person_id WHERE ball.id = :ball_id", diff --git a/test/sql/quote.py b/test/sql/quote.py index af279ffdb..02a501003 100644 --- a/test/sql/quote.py +++ b/test/sql/quote.py @@ -12,14 +12,12 @@ class QuoteTest(PersistTest): 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) + Column('MixedCase', Integer), + Column('ASC', Integer)) table2 = Table('WorstCase2', metadata, - Column('desc', Integer, quote=True, primary_key=True), - Column('Union', Integer, quote=True), - Column('MixedCase', Integer, quote=True), - quote=True) + Column('desc', Integer, primary_key=True), + Column('Union', Integer), + Column('MixedCase', Integer)) table1.create() table2.create() @@ -67,6 +65,19 @@ class QuoteTest(PersistTest): 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)]) + + def testcascade(self): + lcmetadata = MetaData(case_sensitive=False) + t1 = Table('SomeTable', lcmetadata, + Column('UcCol', Integer), + Column('normalcol', String)) + t2 = Table('othertable', lcmetadata, + Column('UcCol', Integer), + Column('normalcol', String, ForeignKey('SomeTable.normalcol'))) + assert lcmetadata.case_sensitive is False + assert t1.c.UcCol.case_sensitive is False + assert t2.c.normalcol.case_sensitive is False + if __name__ == "__main__": testbase.main() diff --git a/test/sql/select.py b/test/sql/select.py index e43d30c54..7711e2908 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -344,9 +344,9 @@ FROM mytable, myothertable WHERE foo.id = foofoo(lala) AND datetime(foo) = Today def testcalculatedcolumns(self): value_tbl = table('values', - Column('id', Integer), - Column('val1', Float), - Column('val2', Float), + column('id', Integer), + column('val1', Float), + column('val2', Float), ) self.runtest( @@ -549,10 +549,10 @@ FROM mytable, myothertable WHERE mytable.myid = myothertable.otherid AND mytable def testcast(self): tbl = table('casttest', - Column('id', Integer), - Column('v1', Float), - Column('v2', Float), - Column('ts', TIMESTAMP), + column('id', Integer), + column('v1', Float), + column('v2', Float), + column('ts', TIMESTAMP), ) def check_results(dialect, expected_results, literal): |