1
+ import re
1
2
import intersystems_iris .dbapi ._DBAPI as dbapi
2
3
from . import information_schema as ischema
3
4
from . import types
@@ -461,6 +462,19 @@ def visit_drop_schema(self, drop, **kw):
461
462
def visit_check_constraint (self , constraint , ** kw ):
462
463
raise exc .CompileError ("Check CONSTRAINT not supported" )
463
464
465
+ def visit_computed_column (self , generated , ** kwargs ):
466
+ text = self .sql_compiler .process (
467
+ generated .sqltext , include_table = True , literal_binds = True
468
+ )
469
+ text = re .sub (r"(?<!')(\b[^\d]\w+\b)" , r'{\g<1>}' , text )
470
+ # text = text.replace("'", '"')
471
+ text = 'COMPUTECODE {Set {*} = %s}' % (text ,)
472
+ if generated .persisted is False :
473
+ text += ' CALCULATED'
474
+ else :
475
+ text += ' COMPUTEONCHANGE ("%%UPDATE")'
476
+ return text
477
+
464
478
def get_column_specification (self , column , ** kwargs ):
465
479
466
480
colspec = [
@@ -487,6 +501,9 @@ def get_column_specification(self, column, **kwargs):
487
501
if default is not None :
488
502
colspec .append ("DEFAULT " + default )
489
503
504
+ if column .computed is not None :
505
+ colspec .append (self .process (column .computed ))
506
+
490
507
if not column .nullable :
491
508
colspec .append ("NOT NULL" )
492
509
@@ -583,7 +600,6 @@ class IRISDialect(default.DefaultDialect):
583
600
584
601
def __init__ (self , ** kwargs ):
585
602
default .DefaultDialect .__init__ (self , ** kwargs )
586
- self ._auto_parallel = 1
587
603
588
604
_isolation_lookup = set (
589
605
[
@@ -920,7 +936,9 @@ def fkey_rec():
920
936
921
937
def get_columns (self , connection , table_name , schema = None , ** kw ):
922
938
schema_name = self .get_schema (schema )
939
+ tables = ischema .tables
923
940
columns = ischema .columns
941
+ property = ischema .property
924
942
925
943
whereclause = sql .and_ (
926
944
columns .c .table_name == str (table_name ),
@@ -938,9 +956,24 @@ def get_columns(self, connection, table_name, schema=None, **kw):
938
956
columns .c .column_default ,
939
957
columns .c .collation_name ,
940
958
columns .c .auto_increment ,
959
+ property .c .SqlComputeCode ,
960
+ property .c .Calculated ,
961
+ property .c .Transient ,
941
962
# columns.c.description,
942
963
)
943
964
.select_from (columns )
965
+ .outerjoin (
966
+ property ,
967
+ sql .and_ (
968
+ property .c .SqlFieldName == columns .c .column_name ,
969
+ property .c .parent ==
970
+ sql .select (tables .c .classname )
971
+ .where (
972
+ columns .c .table_name == tables .c .table_name ,
973
+ columns .c .table_schema == tables .c .table_schema ,
974
+ ).scalar_subquery ()
975
+ ),
976
+ )
944
977
.where (whereclause )
945
978
.order_by (columns .c .ordinal_position )
946
979
)
@@ -958,6 +991,9 @@ def get_columns(self, connection, table_name, schema=None, **kw):
958
991
default = row [columns .c .column_default ]
959
992
collation = row [columns .c .collation_name ]
960
993
autoincrement = row [columns .c .auto_increment ]
994
+ sqlComputeCode = row [property .c .SqlComputeCode ]
995
+ calculated = row [property .c .Calculated ]
996
+ transient = row [property .c .Transient ]
961
997
# description = row[columns.c.description]
962
998
963
999
coltype = self .ischema_names .get (type_ , None )
@@ -997,6 +1033,15 @@ def get_columns(self, connection, table_name, schema=None, **kw):
997
1033
"autoincrement" : autoincrement ,
998
1034
# "comment": description,
999
1035
}
1036
+ if sqlComputeCode and 'set {*} = ' in sqlComputeCode .lower ():
1037
+ sqltext = sqlComputeCode
1038
+ sqltext = sqltext .split (' = ' )[1 ]
1039
+ sqltext = re .sub (r"{(\b\w+\b)}" , r"\g<1>" , sqltext )
1040
+ persisted = not calculated and not transient
1041
+ cdict ['computed' ] = {
1042
+ "sqltext" : sqltext ,
1043
+ "persisted" : persisted ,
1044
+ }
1000
1045
cols .append (cdict )
1001
1046
1002
1047
if cols :
0 commit comments