~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to test/sql/test_compiler.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from sqlalchemy.dialects import mysql, mssql, postgresql, oracle, \
29
29
            sqlite, sybase
30
30
from sqlalchemy.ext.compiler import compiles
 
31
from sqlalchemy.sql import compiler
31
32
 
32
33
table1 = table('mytable',
33
34
    column('myid', Integer),
181
182
                checkparams=params
182
183
            )
183
184
 
 
185
    def test_select_precol_compile_ordering(self):
 
186
        s1 = select([column('x')]).select_from('a').limit(5).as_scalar()
 
187
        s2 = select([s1]).limit(10)
 
188
 
 
189
        class MyCompiler(compiler.SQLCompiler):
 
190
            def get_select_precolumns(self, select):
 
191
                result = ""
 
192
                if select._limit:
 
193
                    result += "FIRST %s " % self.process(literal(select._limit))
 
194
                if select._offset:
 
195
                    result += "SKIP %s " % self.process(literal(select._offset))
 
196
                return result
 
197
 
 
198
            def limit_clause(self, select):
 
199
                return ""
 
200
 
 
201
        dialect = default.DefaultDialect()
 
202
        dialect.statement_compiler = MyCompiler
 
203
        dialect.paramstyle = 'qmark'
 
204
        dialect.positional = True
 
205
        self.assert_compile(
 
206
            s2,
 
207
            "SELECT FIRST ? (SELECT FIRST ? x FROM a) AS anon_1",
 
208
            checkpositional=(10, 5),
 
209
            dialect=dialect
 
210
        )
 
211
 
 
212
 
184
213
    def test_from_subquery(self):
185
214
        """tests placing select statements in the column clause of
186
215
        another select, for the
933
962
        )
934
963
 
935
964
 
 
965
    def test_where_empty(self):
 
966
        self.assert_compile(
 
967
            select([table1.c.myid]).where(and_()),
 
968
            "SELECT mytable.myid FROM mytable"
 
969
        )
 
970
        self.assert_compile(
 
971
            select([table1.c.myid]).where(or_()),
 
972
            "SELECT mytable.myid FROM mytable"
 
973
        )
936
974
 
937
975
    def test_multiple_col_binds(self):
938
976
        self.assert_compile(
1701
1739
                        expected_test_params_list
1702
1740
                )
1703
1741
 
1704
 
        # check that params() doesnt modify original statement
 
1742
        # check that params() doesn't modify original statement
1705
1743
        s = select([table1], or_(table1.c.myid == bindparam('myid'),
1706
1744
                                    table2.c.otherid ==
1707
1745
                                        bindparam('myotherid')))