@@ -307,7 +307,7 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
307307 current_schema = self .denormalize_name (schema or self .default_schema_name )
308308 table_name = self .denormalize_name (table_name )
309309 sysindexes = self .sys_indexes
310- col_finder = re .compile ("(\w+)" )
310+ col_finder = re .compile (r "(\w+)" )
311311 query = sql .select (sysindexes .c .colnames , sysindexes .c .indname ).\
312312 where (and_ (sysindexes .c .tabschema == current_schema ,
313313 sysindexes .c .tabname == table_name ,
@@ -329,7 +329,7 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
329329 current_schema = self .denormalize_name (schema or self .default_schema_name )
330330 table_name = self .denormalize_name (table_name )
331331 syscols = self .sys_columns
332- col_finder = re .compile ("(\w+)" )
332+ col_finder = re .compile (r "(\w+)" )
333333 query = sql .select (syscols .c .colname ).\
334334 where (and_ (
335335 syscols .c .tabschema == current_schema ,
@@ -441,7 +441,7 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
441441 where (and_ (sysidx .c .tabschema == current_schema ,sysidx .c .tabname == table_name )).\
442442 order_by (sysidx .c .tabname )
443443 indexes = []
444- col_finder = re .compile ("(\w+)" )
444+ col_finder = re .compile (r "(\w+)" )
445445 for r in connection .execute (query ):
446446 if r [2 ] != 'P' :
447447 if r [2 ] == 'U' and r [3 ] != 0 :
@@ -630,21 +630,33 @@ def get_sequence_names(self, connection, schema=None, **kw):
630630 @reflection .cache
631631 def get_schema_names (self , connection , ** kw ):
632632 sysschema = self .sys_schemas
633- query = sql .select (sysschema .c .schemaname ).\
634- where (~ sysschema .c .schemaname .like (unicode ('Q%' ))).\
635- where (~ sysschema .c .schemaname .like (unicode ('SYS%' ))).\
636- order_by (sysschema .c .schemaname )
633+ if version_info [0 ] < 3 :
634+ query = sql .select (sysschema .c .schemaname ). \
635+ where (~ sysschema .c .schemaname .like (unicode ('Q%' ))). \
636+ where (~ sysschema .c .schemaname .like (unicode ('SYS%' ))). \
637+ order_by (sysschema .c .schemaname )
638+ else :
639+ query = sql .select (sysschema .c .schemaname ). \
640+ where (~ sysschema .c .schemaname .like (str ('Q%' ))). \
641+ where (~ sysschema .c .schemaname .like (str ('SYS%' ))). \
642+ order_by (sysschema .c .schemaname )
637643 return [self .normalize_name (r [0 ]) for r in connection .execute (query )]
638644
639645 # Retrieves a list of table names for a given schema
640646 @reflection .cache
641647 def get_table_names (self , connection , schema = None , ** kw ):
642648 current_schema = self .denormalize_name (schema or self .default_schema_name )
643649 systbl = self .sys_tables
644- query = not sql .select (systbl .c .tabname ).\
645- where (systbl .c .tabtype == unicode ('T' )).\
646- where (systbl .c .tabschema == current_schema ).\
647- order_by (systbl .c .tabname )
650+ if version_info [0 ] < 3 :
651+ query = not sql .select (systbl .c .tabname ). \
652+ where (systbl .c .tabtype == unicode ('T' )). \
653+ where (systbl .c .tabschema == current_schema ). \
654+ order_by (systbl .c .tabname )
655+ else :
656+ query = not sql .select (systbl .c .tabname ). \
657+ where (systbl .c .tabtype == str ('T' )). \
658+ where (systbl .c .tabschema == current_schema ). \
659+ order_by (systbl .c .tabname )
648660 return [self .normalize_name (r [0 ]) for r in connection .execute (query )]
649661
650662 @reflection .cache
@@ -699,14 +711,24 @@ def get_columns(self, connection, table_name, schema=None, **kw):
699711 (coltype , r [0 ]))
700712 coltype = coltype = sa_types .NULLTYPE
701713
702- sa_columns .append ({
714+ if version_info [0 ] < 3 :
715+ sa_columns .append ({
703716 'name' : self .normalize_name (r [0 ]),
704717 'type' : coltype ,
705718 'nullable' : r [3 ] == unicode ('Y' ),
706719 'default' : r [2 ],
707720 'autoincrement' : (r [6 ] == unicode ('YES' )) and (r [7 ] != None ),
708721 'comment' : r [8 ] or None ,
709722 })
723+ else :
724+ sa_columns .append ({
725+ 'name' : self .normalize_name (r [0 ]),
726+ 'type' : coltype ,
727+ 'nullable' : r [3 ] == str ('Y' ),
728+ 'default' : r [2 ],
729+ 'autoincrement' : (r [6 ] == str ('YES' )) and (r [7 ] != None ),
730+ 'comment' : r [8 ] or None ,
731+ })
710732 return sa_columns
711733
712734 @reflection .cache
@@ -742,14 +764,24 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
742764 sysconst = self .sys_table_constraints
743765 syskeyconst = self .sys_key_constraints
744766
745- query = sql .select (syskeyconst .c .colname , sysconst .c .tabname ).\
746- where (and_ (
767+ if version_info [0 ] < 3 :
768+ query = sql .select (syskeyconst .c .colname , sysconst .c .tabname ). \
769+ where (and_ (
747770 syskeyconst .c .conschema == sysconst .c .conschema ,
748771 syskeyconst .c .conname == sysconst .c .conname ,
749772 sysconst .c .tabschema == current_schema ,
750773 sysconst .c .tabname == table_name ,
751- sysconst .c .contype == unicode ('PRIMARY KEY' ))).\
752- order_by (syskeyconst .c .colno )
774+ sysconst .c .contype == unicode ('PRIMARY KEY' ))). \
775+ order_by (syskeyconst .c .colno )
776+ else :
777+ query = sql .select (syskeyconst .c .colname , sysconst .c .tabname ). \
778+ where (and_ (
779+ syskeyconst .c .conschema == sysconst .c .conschema ,
780+ syskeyconst .c .conname == sysconst .c .conname ,
781+ sysconst .c .tabschema == current_schema ,
782+ sysconst .c .tabname == table_name ,
783+ sysconst .c .contype == str ('PRIMARY KEY' ))). \
784+ order_by (syskeyconst .c .colno )
753785
754786 return [self .normalize_name (key [0 ])
755787 for key in connection .execute (query )]
@@ -814,11 +846,18 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
814846 if key in indexes :
815847 indexes [key ]['column_names' ].append (self .normalize_name (r [2 ]))
816848 else :
817- indexes [key ] = {
818- 'name' : self .normalize_name (r [0 ]),
819- 'column_names' : [self .normalize_name (r [2 ])],
820- 'unique' : r [1 ] == unicode ('Y' )
821- }
849+ if version_info [0 ] < 3 :
850+ indexes [key ] = {
851+ 'name' : self .normalize_name (r [0 ]),
852+ 'column_names' : [self .normalize_name (r [2 ])],
853+ 'unique' : r [1 ] == unicode ('Y' )
854+ }
855+ else :
856+ indexes [key ] = {
857+ 'name' : self .normalize_name (r [0 ]),
858+ 'column_names' : [self .normalize_name (r [2 ])],
859+ 'unique' : r [1 ] == str ('Y' )
860+ }
822861 return [value for key , value in indexes .items ()]
823862
824863 @reflection .cache
@@ -1032,7 +1071,7 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
10321071 current_schema = self .denormalize_name (schema or self .default_schema_name )
10331072 table_name = self .denormalize_name (table_name )
10341073 sysindexes = self .sys_columns
1035- col_finder = re .compile ("(\w+)" )
1074+ col_finder = re .compile (r "(\w+)" )
10361075 query = sql .select (sysindexes .c .colname ).\
10371076 where (and_ (
10381077 sysindexes .c .tabschema == current_schema ,
@@ -1050,7 +1089,7 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
10501089 current_schema = self .denormalize_name (schema or self .default_schema_name )
10511090 table_name = self .denormalize_name (table_name )
10521091 sysindexes = self .sys_columns
1053- col_finder = re .compile ("(\w+)" )
1092+ col_finder = re .compile (r "(\w+)" )
10541093 query = sql .select (sysindexes .c .colname ).\
10551094 where (and_ (
10561095 sysindexes .c .tabschema == current_schema ,
@@ -1168,7 +1207,7 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
11681207 syscolpk .c .keyseq > 0 )).\
11691208 order_by (sysidx .c .tabname )
11701209 indexes = []
1171- col_finder = re .compile ("(\w+)" )
1210+ col_finder = re .compile (r "(\w+)" )
11721211 for r in connection .execute (query ):
11731212 if r [2 ] != 'P' :
11741213 if r [2 ] == 'U' and r [3 ] != 0 :
0 commit comments