<s> from sqlalchemy . testing import eq_ , is_ <EOL> from sqlalchemy import schema <EOL> from sqlalchemy . sql import table , column <EOL> from sqlalchemy . databases import mssql <EOL> from sqlalchemy . dialects . mssql import mxodbc <EOL> from sqlalchemy . testing import fixtures , AssertsCompiledSQL <EOL> from sqlalchemy import sql <EOL> from sqlalchemy import Integer , String , Table , Column , select , MetaData , update , delete , insert , extract , union , func , PrimaryKeyConstraint , UniqueConstraint , Index , Sequence , literal <EOL> class CompileTest ( fixtures . TestBase , AssertsCompiledSQL ) : <EOL> __dialect__ = mssql . dialect ( ) <EOL> def test_true_false ( self ) : <EOL> self . assert_compile ( <EOL> sql . false ( ) , "<STR_LIT:0>" <EOL> ) <EOL> self . assert_compile ( <EOL> sql . true ( ) , <EOL> "<STR_LIT:1>" <EOL> ) <EOL> def test_select ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( t . select ( ) , <EOL> '<STR_LIT>' ) <EOL> def test_select_with_nolock ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( <EOL> t . select ( ) . with_hint ( t , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_select_with_nolock_schema ( self ) : <EOL> m = MetaData ( ) <EOL> t = Table ( '<STR_LIT>' , m , Column ( '<STR_LIT>' , Integer ) , <EOL> schema = '<STR_LIT>' ) <EOL> self . assert_compile ( <EOL> t . select ( ) . with_hint ( t , '<STR_LIT>' ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_join_with_hint ( self ) : <EOL> t1 = table ( '<STR_LIT>' , <EOL> column ( '<STR_LIT:a>' , Integer ) , <EOL> column ( '<STR_LIT:b>' , String ) , <EOL> column ( '<STR_LIT:c>' , String ) , <EOL> ) <EOL> t2 = table ( '<STR_LIT>' , <EOL> column ( "<STR_LIT:a>" , Integer ) , <EOL> column ( "<STR_LIT:b>" , Integer ) , <EOL> column ( "<STR_LIT:c>" , Integer ) , <EOL> ) <EOL> join = t1 . join ( t2 , t1 . c . a == t2 . c . a ) . select ( ) . with_hint ( t1 , '<STR_LIT>' ) <EOL> self . assert_compile ( <EOL> join , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_insert ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( t . insert ( ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_update ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( t . update ( t . c . somecolumn == <NUM_LIT:7> ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , dict ( somecolumn = <NUM_LIT:10> ) ) <EOL> def test_insert_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> for targ in ( None , t ) : <EOL> for darg in ( "<STR_LIT:*>" , "<STR_LIT>" ) : <EOL> self . assert_compile ( <EOL> t . insert ( ) . <EOL> values ( somecolumn = "<STR_LIT:x>" ) . <EOL> with_hint ( "<STR_LIT>" , <EOL> selectable = targ , <EOL> dialect_name = darg ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_update_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> for targ in ( None , t ) : <EOL> for darg in ( "<STR_LIT:*>" , "<STR_LIT>" ) : <EOL> self . assert_compile ( <EOL> t . update ( ) . where ( t . c . somecolumn == "<STR_LIT:q>" ) . <EOL> values ( somecolumn = "<STR_LIT:x>" ) . <EOL> with_hint ( "<STR_LIT>" , <EOL> selectable = targ , <EOL> dialect_name = darg ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_update_exclude_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( <EOL> t . update ( ) . where ( t . c . somecolumn == "<STR_LIT:q>" ) . <EOL> values ( somecolumn = "<STR_LIT:x>" ) . <EOL> with_hint ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_delete_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> for targ in ( None , t ) : <EOL> for darg in ( "<STR_LIT:*>" , "<STR_LIT>" ) : <EOL> self . assert_compile ( <EOL> t . delete ( ) . where ( t . c . somecolumn == "<STR_LIT:q>" ) . <EOL> with_hint ( "<STR_LIT>" , <EOL> selectable = targ , <EOL> dialect_name = darg ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_delete_exclude_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( <EOL> t . delete ( ) . <EOL> where ( t . c . somecolumn == "<STR_LIT:q>" ) . <EOL> with_hint ( "<STR_LIT>" , dialect_name = "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_update_from_hint ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> t2 = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> for darg in ( "<STR_LIT:*>" , "<STR_LIT>" ) : <EOL> self . assert_compile ( <EOL> t . update ( ) . where ( t . c . somecolumn == t2 . c . somecolumn ) . <EOL> values ( somecolumn = "<STR_LIT:x>" ) . <EOL> with_hint ( "<STR_LIT>" , <EOL> selectable = t2 , <EOL> dialect_name = darg ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_update_to_select_schema ( self ) : <EOL> meta = MetaData ( ) <EOL> table = Table ( <EOL> "<STR_LIT>" , meta , <EOL> Column ( "<STR_LIT>" , String ) , <EOL> Column ( "<STR_LIT>" , Integer ) , <EOL> schema = "<STR_LIT>" <EOL> ) <EOL> other = Table ( <EOL> "<STR_LIT>" , meta , <EOL> Column ( "<STR_LIT>" , String ) , <EOL> Column ( "<STR_LIT>" , Integer ) <EOL> ) <EOL> stmt = table . update ( ) . values ( <EOL> val = select ( [ other . c . newval ] ) . <EOL> where ( table . c . sym == other . c . sym ) . as_scalar ( ) ) <EOL> self . assert_compile ( <EOL> stmt , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) <EOL> stmt = table . update ( ) . values ( val = other . c . newval ) . where ( table . c . sym == other . c . sym ) <EOL> self . assert_compile ( <EOL> stmt , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) <EOL> def test_strict_binds ( self ) : <EOL> """<STR_LIT>""" <EOL> from sqlalchemy . dialects . mssql . base import MSSQLStrictCompiler <EOL> mxodbc_dialect = mxodbc . dialect ( ) <EOL> mxodbc_dialect . statement_compiler = MSSQLStrictCompiler <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT:foo>' ) ) <EOL> for expr , compile in [ <EOL> ( <EOL> select ( [ literal ( "<STR_LIT:x>" ) , literal ( "<STR_LIT:y>" ) ] ) , <EOL> "<STR_LIT>" , <EOL> ) , <EOL> ( <EOL> select ( [ t ] ) . where ( t . c . foo . in_ ( [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) , <EOL> ( <EOL> t . c . foo . in_ ( [ None ] ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> ] : <EOL> self . assert_compile ( expr , compile , dialect = mxodbc_dialect ) <EOL> def test_in_with_subqueries ( self ) : <EOL> """<STR_LIT>""" <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( t . select ( ) . where ( t . c . somecolumn <EOL> == t . select ( ) ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assert_compile ( t . select ( ) . where ( t . c . somecolumn <EOL> != t . select ( ) ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_count ( self ) : <EOL> t = table ( '<STR_LIT>' , column ( '<STR_LIT>' ) ) <EOL> self . assert_compile ( t . count ( ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_noorderby_insubquery ( self ) : <EOL> """<STR_LIT>""" <EOL> table1 = table ( '<STR_LIT>' , <EOL> column ( '<STR_LIT>' , Integer ) , <EOL> column ( '<STR_LIT:name>' , String ) , <EOL> column ( '<STR_LIT:description>' , String ) , <EOL> ) <EOL> q = select ( [ table1 . c . myid ] , <EOL> order_by = [ table1 . c . myid ] ) . alias ( '<STR_LIT:foo>' ) <EOL> crit = q . c . myid == table1 . c . myid <EOL> self . assert_compile ( select ( [ '<STR_LIT:*>' ] , crit ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_delete_schema ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , Column ( '<STR_LIT:id>' , Integer , <EOL> primary_key = True ) , schema = '<STR_LIT>' ) <EOL> self . assert_compile ( tbl . delete ( tbl . c . id == <NUM_LIT:1> ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> s = select ( [ tbl . c . id ] ) . where ( tbl . c . id == <NUM_LIT:1> ) <EOL> self . assert_compile ( tbl . delete ( ) . where ( tbl . c . id . in_ ( s ) ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_delete_schema_multipart ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( <EOL> '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , <EOL> primary_key = True ) , <EOL> schema = '<STR_LIT>' ) <EOL> self . assert_compile ( tbl . delete ( tbl . c . id == <NUM_LIT:1> ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> s = select ( [ tbl . c . id ] ) . where ( tbl . c . id == <NUM_LIT:1> ) <EOL> self . assert_compile ( tbl . delete ( ) . where ( tbl . c . id . in_ ( s ) ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_delete_schema_multipart_needs_quoting ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( <EOL> '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> schema = '<STR_LIT>' ) <EOL> self . assert_compile ( tbl . delete ( tbl . c . id == <NUM_LIT:1> ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> s = select ( [ tbl . c . id ] ) . where ( tbl . c . id == <NUM_LIT:1> ) <EOL> self . assert_compile ( tbl . delete ( ) . where ( tbl . c . id . in_ ( s ) ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_delete_schema_multipart_both_need_quoting ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , Column ( '<STR_LIT:id>' , Integer , <EOL> primary_key = True ) , <EOL> schema = '<STR_LIT>' ) <EOL> self . assert_compile ( tbl . delete ( tbl . c . id == <NUM_LIT:1> ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> s = select ( [ tbl . c . id ] ) . where ( tbl . c . id == <NUM_LIT:1> ) <EOL> self . assert_compile ( <EOL> tbl . delete ( ) . where ( tbl . c . id . in_ ( s ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_union ( self ) : <EOL> t1 = table ( <EOL> '<STR_LIT>' , column ( '<STR_LIT>' ) , column ( '<STR_LIT>' ) , <EOL> column ( '<STR_LIT>' ) , column ( '<STR_LIT>' ) ) <EOL> t2 = table ( <EOL> '<STR_LIT>' , column ( '<STR_LIT>' ) , column ( '<STR_LIT>' ) , <EOL> column ( '<STR_LIT>' ) , column ( '<STR_LIT>' ) ) <EOL> s1 , s2 = select ( <EOL> [ t1 . c . col3 . label ( '<STR_LIT>' ) , t1 . c . col4 . label ( '<STR_LIT>' ) ] , <EOL> t1 . c . col2 . in_ ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) , select ( [ t2 . c . col3 . label ( '<STR_LIT>' ) , t2 . c . col4 . label ( '<STR_LIT>' ) ] , <EOL> t2 . c . col2 . in_ ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> u = union ( s1 , s2 , order_by = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assert_compile ( u , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assert_compile ( u . alias ( '<STR_LIT:bar>' ) . select ( ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_function ( self ) : <EOL> self . assert_compile ( func . foo ( <NUM_LIT:1> , <NUM_LIT:2> ) , '<STR_LIT>' ) <EOL> self . assert_compile ( func . current_time ( ) , '<STR_LIT>' ) <EOL> self . assert_compile ( func . foo ( ) , '<STR_LIT>' ) <EOL> m = MetaData ( ) <EOL> t = Table ( <EOL> '<STR_LIT>' , m , Column ( '<STR_LIT>' , Integer ) , Column ( '<STR_LIT>' , Integer ) ) <EOL> self . assert_compile ( select ( [ func . max ( t . c . col1 ) ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_function_overrides ( self ) : <EOL> self . assert_compile ( func . current_date ( ) , "<STR_LIT>" ) <EOL> self . assert_compile ( func . length ( <NUM_LIT:3> ) , "<STR_LIT>" ) <EOL> def test_extract ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT>' ) ) <EOL> for field in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> self . assert_compile ( <EOL> select ( [ extract ( field , t . c . col1 ) ] ) , <EOL> '<STR_LIT>' % field ) <EOL> def test_update_returning ( self ) : <EOL> table1 = table ( <EOL> '<STR_LIT>' , <EOL> column ( '<STR_LIT>' , Integer ) , <EOL> column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) ) , <EOL> column ( '<STR_LIT:description>' , String ( <NUM_LIT> ) ) ) <EOL> u = update ( <EOL> table1 , <EOL> values = dict ( name = '<STR_LIT:foo>' ) ) . returning ( table1 . c . myid , table1 . c . name ) <EOL> self . assert_compile ( u , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> u = update ( table1 , values = dict ( name = '<STR_LIT:foo>' ) ) . returning ( table1 ) <EOL> self . assert_compile ( u , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> u = update ( <EOL> table1 , <EOL> values = dict ( <EOL> name = '<STR_LIT:foo>' ) ) . returning ( table1 ) . where ( table1 . c . name == '<STR_LIT:bar>' ) <EOL> self . assert_compile ( u , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> u = update ( table1 , values = dict ( name = '<STR_LIT:foo>' <EOL> ) ) . returning ( func . length ( table1 . c . name ) ) <EOL> self . assert_compile ( u , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_delete_returning ( self ) : <EOL> table1 = table ( <EOL> '<STR_LIT>' , column ( '<STR_LIT>' , Integer ) , <EOL> column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) ) , column ( '<STR_LIT:description>' , String ( <NUM_LIT> ) ) ) <EOL> d = delete ( table1 ) . returning ( table1 . c . myid , table1 . c . name ) <EOL> self . assert_compile ( d , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> d = delete ( table1 ) . where ( table1 . c . name == '<STR_LIT:bar>' <EOL> ) . returning ( table1 . c . myid , <EOL> table1 . c . name ) <EOL> self . assert_compile ( d , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_insert_returning ( self ) : <EOL> table1 = table ( <EOL> '<STR_LIT>' , column ( '<STR_LIT>' , Integer ) , <EOL> column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) ) , column ( '<STR_LIT:description>' , String ( <NUM_LIT> ) ) ) <EOL> i = insert ( <EOL> table1 , <EOL> values = dict ( name = '<STR_LIT:foo>' ) ) . returning ( table1 . c . myid , table1 . c . name ) <EOL> self . assert_compile ( i , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> i = insert ( table1 , values = dict ( name = '<STR_LIT:foo>' ) ) . returning ( table1 ) <EOL> self . assert_compile ( i , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> i = insert ( table1 , values = dict ( name = '<STR_LIT:foo>' <EOL> ) ) . returning ( func . length ( table1 . c . name ) ) <EOL> self . assert_compile ( i , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_limit_using_top ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> s = select ( [ t ] ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . limit ( <NUM_LIT:10> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> def test_limit_zero_using_top ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> s = select ( [ t ] ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . limit ( <NUM_LIT:0> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> c = s . compile ( dialect = mssql . MSDialect ( ) ) <EOL> eq_ ( len ( c . _result_columns ) , <NUM_LIT:2> ) <EOL> assert t . c . x in set ( c . _create_result_map ( ) [ '<STR_LIT:x>' ] [ <NUM_LIT:1> ] ) <EOL> def test_offset_using_window ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> s = select ( [ t ] ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . offset ( <NUM_LIT:20> ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:20> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> c = s . compile ( dialect = mssql . MSDialect ( ) ) <EOL> eq_ ( len ( c . _result_columns ) , <NUM_LIT:2> ) <EOL> assert t . c . x in set ( c . _create_result_map ( ) [ '<STR_LIT:x>' ] [ <NUM_LIT:1> ] ) <EOL> def test_limit_offset_using_window ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> s = select ( [ t ] ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . limit ( <NUM_LIT:10> ) . offset ( <NUM_LIT:20> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:20> , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> c = s . compile ( dialect = mssql . MSDialect ( ) ) <EOL> eq_ ( len ( c . _result_columns ) , <NUM_LIT:2> ) <EOL> assert t . c . x in set ( c . _create_result_map ( ) [ '<STR_LIT:x>' ] [ <NUM_LIT:1> ] ) <EOL> assert t . c . y in set ( c . _create_result_map ( ) [ '<STR_LIT:y>' ] [ <NUM_LIT:1> ] ) <EOL> def test_limit_offset_w_ambiguous_cols ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> cols = [ t . c . x , t . c . x . label ( '<STR_LIT:q>' ) , t . c . x . label ( '<STR_LIT:p>' ) , t . c . y ] <EOL> s = select ( cols ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . limit ( <NUM_LIT:10> ) . offset ( <NUM_LIT:20> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:20> , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> c = s . compile ( dialect = mssql . MSDialect ( ) ) <EOL> eq_ ( len ( c . _result_columns ) , <NUM_LIT:4> ) <EOL> result_map = c . _create_result_map ( ) <EOL> for col in cols : <EOL> is_ ( result_map [ col . key ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , col ) <EOL> def test_limit_offset_with_correlated_order_by ( self ) : <EOL> t1 = table ( '<STR_LIT>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> t2 = table ( '<STR_LIT>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> order_by = select ( [ t2 . c . y ] ) . where ( t1 . c . x == t2 . c . x ) . as_scalar ( ) <EOL> s = select ( [ t1 ] ) . where ( t1 . c . x == <NUM_LIT:5> ) . order_by ( order_by ) . limit ( <NUM_LIT:10> ) . offset ( <NUM_LIT:20> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:20> , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> c = s . compile ( dialect = mssql . MSDialect ( ) ) <EOL> eq_ ( len ( c . _result_columns ) , <NUM_LIT:2> ) <EOL> assert t1 . c . x in set ( c . _create_result_map ( ) [ '<STR_LIT:x>' ] [ <NUM_LIT:1> ] ) <EOL> assert t1 . c . y in set ( c . _create_result_map ( ) [ '<STR_LIT:y>' ] [ <NUM_LIT:1> ] ) <EOL> def test_limit_zero_offset_using_window ( self ) : <EOL> t = table ( '<STR_LIT:t>' , column ( '<STR_LIT:x>' , Integer ) , column ( '<STR_LIT:y>' , Integer ) ) <EOL> s = select ( [ t ] ) . where ( t . c . x == <NUM_LIT:5> ) . order_by ( t . c . y ) . limit ( <NUM_LIT:0> ) . offset ( <NUM_LIT:0> ) <EOL> self . assert_compile ( <EOL> s , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> checkparams = { '<STR_LIT>' : <NUM_LIT:5> } <EOL> ) <EOL> def test_sequence_start_0 ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , Sequence ( '<STR_LIT>' , <NUM_LIT:0> ) , primary_key = True ) ) <EOL> self . assert_compile ( <EOL> schema . CreateTable ( tbl ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_sequence_non_primary_key ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , Sequence ( '<STR_LIT>' ) , primary_key = False ) ) <EOL> self . assert_compile ( <EOL> schema . CreateTable ( tbl ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_sequence_ignore_nullability ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , Sequence ( '<STR_LIT>' ) , nullable = True ) ) <EOL> self . assert_compile ( <EOL> schema . CreateTable ( tbl ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_table_pkc_clustering ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:x>' , Integer , autoincrement = False ) , <EOL> Column ( '<STR_LIT:y>' , Integer , autoincrement = False ) , <EOL> PrimaryKeyConstraint ( "<STR_LIT:x>" , "<STR_LIT:y>" , mssql_clustered = True ) ) <EOL> self . assert_compile ( <EOL> schema . CreateTable ( tbl ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_table_uc_clustering ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:x>' , Integer , autoincrement = False ) , <EOL> Column ( '<STR_LIT:y>' , Integer , autoincrement = False ) , <EOL> PrimaryKeyConstraint ( "<STR_LIT:x>" ) , <EOL> UniqueConstraint ( "<STR_LIT:y>" , mssql_clustered = True ) ) <EOL> self . assert_compile ( <EOL> schema . CreateTable ( tbl ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_index_clustering ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer ) ) <EOL> idx = Index ( "<STR_LIT:foo>" , tbl . c . id , mssql_clustered = True ) <EOL> self . assert_compile ( schema . CreateIndex ( idx ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_index_ordering ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( <EOL> '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:x>' , Integer ) , Column ( '<STR_LIT:y>' , Integer ) , Column ( '<STR_LIT:z>' , Integer ) ) <EOL> idx = Index ( "<STR_LIT:foo>" , tbl . c . x . desc ( ) , "<STR_LIT:y>" ) <EOL> self . assert_compile ( schema . CreateIndex ( idx ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_create_index_expr ( self ) : <EOL> m = MetaData ( ) <EOL> t1 = Table ( '<STR_LIT:foo>' , m , <EOL> Column ( '<STR_LIT:x>' , Integer ) <EOL> ) <EOL> self . assert_compile ( <EOL> schema . CreateIndex ( Index ( "<STR_LIT:bar>" , t1 . c . x > <NUM_LIT:5> ) ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_drop_index_w_schema ( self ) : <EOL> m = MetaData ( ) <EOL> t1 = Table ( '<STR_LIT:foo>' , m , <EOL> Column ( '<STR_LIT:x>' , Integer ) , <EOL> schema = '<STR_LIT:bar>' <EOL> ) <EOL> self . assert_compile ( <EOL> schema . DropIndex ( Index ( "<STR_LIT>" , t1 . c . x ) ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_index_extra_include_1 ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( <EOL> '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:x>' , Integer ) , Column ( '<STR_LIT:y>' , Integer ) , Column ( '<STR_LIT:z>' , Integer ) ) <EOL> idx = Index ( "<STR_LIT:foo>" , tbl . c . x , mssql_include = [ '<STR_LIT:y>' ] ) <EOL> self . assert_compile ( schema . CreateIndex ( idx ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_index_extra_include_2 ( self ) : <EOL> metadata = MetaData ( ) <EOL> tbl = Table ( <EOL> '<STR_LIT:test>' , metadata , <EOL> Column ( '<STR_LIT:x>' , Integer ) , Column ( '<STR_LIT:y>' , Integer ) , Column ( '<STR_LIT:z>' , Integer ) ) <EOL> idx = Index ( "<STR_LIT:foo>" , tbl . c . x , mssql_include = [ tbl . c . y ] ) <EOL> self . assert_compile ( schema . CreateIndex ( idx ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> class SchemaTest ( fixtures . TestBase ) : <EOL> def setup ( self ) : <EOL> t = Table ( '<STR_LIT>' , MetaData ( ) , <EOL> Column ( '<STR_LIT>' , Integer ) , <EOL> Column ( '<STR_LIT>' , String ) <EOL> ) <EOL> self . column = t . c . test_column <EOL> dialect = mssql . dialect ( ) <EOL> self . ddl_compiler = dialect . ddl_compiler ( dialect , <EOL> schema . CreateTable ( t ) ) <EOL> def _column_spec ( self ) : <EOL> return self . ddl_compiler . get_column_specification ( self . column ) <EOL> def test_that_mssql_default_nullability_emits_null ( self ) : <EOL> eq_ ( "<STR_LIT>" , self . _column_spec ( ) ) <EOL> def test_that_mssql_none_nullability_does_not_emit_nullability ( self ) : <EOL> self . column . nullable = None <EOL> eq_ ( "<STR_LIT>" , self . _column_spec ( ) ) <EOL> def test_that_mssql_specified_nullable_emits_null ( self ) : <EOL> self . column . nullable = True <EOL> eq_ ( "<STR_LIT>" , self . _column_spec ( ) ) <EOL> def test_that_mssql_specified_not_nullable_emits_not_null ( self ) : <EOL> self . column . nullable = False <EOL> eq_ ( "<STR_LIT>" , self . _column_spec ( ) ) </s>
