11
11
from sqlalchemy .testing import config
12
12
from sqlalchemy .orm import Session
13
13
from sqlalchemy import testing
14
- from sqlalchemy import Table , Column , select , func
14
+ from sqlalchemy import Table , Column , select , func , text
15
15
from sqlalchemy .types import Integer
16
16
from sqlalchemy .types import String
17
17
from sqlalchemy .types import VARBINARY
@@ -516,6 +516,7 @@ def test_add_table_comment(self, connection):
516
516
def test_drop_table_comment (self , connection ):
517
517
pass
518
518
519
+
519
520
class IRISPaginationTest (fixtures .TablesTest ):
520
521
521
522
@classmethod
@@ -538,14 +539,16 @@ def define_tables(cls, metadata):
538
539
def insert_data (cls , connection ):
539
540
connection .execute (
540
541
cls .tables .data .insert (),
541
- [
542
- {"id" : i , "value" : f"value_{ i } " } for i in range (1 , 21 )
543
- ],
542
+ [{"id" : i , "value" : f"value_{ i } " } for i in range (1 , 21 )],
544
543
)
545
544
connection .execute (
546
545
cls .tables .users .insert (),
547
546
[
548
- {"user_id" : i , "username" : f"user_{ i } " , "email" : f"user_{ i } @example.com" }
547
+ {
548
+ "user_id" : i ,
549
+ "username" : f"user_{ i } " ,
550
+ "email" : f"user_{ i } @example.com" ,
551
+ }
549
552
for i in range (1 , 31 )
550
553
],
551
554
)
@@ -605,12 +608,12 @@ def test_pagination_two_tables_join(self):
605
608
select (
606
609
self .tables .data .c .value ,
607
610
self .tables .users .c .username ,
608
- self .tables .users .c .email
611
+ self .tables .users .c .email ,
609
612
)
610
613
.select_from (
611
614
self .tables .data .join (
612
615
self .tables .users ,
613
- self .tables .data .c .id == self .tables .users .c .user_id
616
+ self .tables .data .c .id == self .tables .users .c .user_id ,
614
617
)
615
618
)
616
619
.order_by (self .tables .data .c .id )
@@ -675,4 +678,49 @@ def test_pagination_count_total(self):
675
678
.limit (page_size )
676
679
.offset ((total_pages_data - 1 ) * page_size )
677
680
).fetchall ()
678
- assert len (result ) == 6 # Last page has 6 records (20 - 14)
681
+ assert len (result ) == 6 # Last page has 6 records (20 - 14)
682
+
683
+
684
+ class Issue20Test (fixtures .TablesTest ):
685
+
686
+ def test_with (self ):
687
+ sql = """
688
+ WITH cte AS (
689
+ SELECT 123 as n, :param as message
690
+ ),
691
+ cte1 AS (
692
+ SELECT 345 as n, :param1 as message
693
+ ),
694
+ cte2 AS (
695
+ SELECT *, :param2 as message2
696
+ FROM cte
697
+ )
698
+ SELECT *, :global as test FROM %s;
699
+ """
700
+
701
+ params = {
702
+ "param" : "hello" ,
703
+ "param2" : "hello2" ,
704
+ "param1" : "hello1" ,
705
+ "global" : "global_value" ,
706
+ }
707
+ with config .db .connect () as conn :
708
+ result = conn .execute (
709
+ text (sql % "cte" ),
710
+ params ,
711
+ ).fetchall ()
712
+ assert result == [(123 , "hello" , "global_value" )]
713
+
714
+ with config .db .connect () as conn :
715
+ result = conn .execute (
716
+ text (sql % "cte1" ),
717
+ params ,
718
+ ).fetchall ()
719
+ assert result == [(345 , "hello1" , "global_value" )]
720
+
721
+ with config .db .connect () as conn :
722
+ result = conn .execute (
723
+ text (sql % "cte2" ),
724
+ params ,
725
+ ).fetchall ()
726
+ assert result == [(123 , "hello" , "hello2" , "global_value" )]
0 commit comments