@@ -653,6 +653,20 @@ def visit_drop_schema(self, drop, **kw):
653653 def visit_check_constraint (self , constraint , ** kw ):
654654 pass
655655
656+ def create_table_constraints (self , table , ** kw ):
657+ description = ""
658+ comment = table .comment
659+ if comment :
660+ # hack to keep \r, kind of
661+ comment = comment .replace ('\r ' , '\n \t ' )
662+ literal = self .sql_compiler .render_literal_value (comment , sqltypes .String ())
663+ description = "%DESCRIPTION " + literal
664+
665+ constraints = super ().create_table_constraints (table , ** kw )
666+ if constraints and description :
667+ description = ", \n \t " + description
668+ return constraints + description
669+
656670 def visit_add_constraint (self , create , ** kw ):
657671 if isinstance (create .element , schema .CheckConstraint ):
658672 raise exc .CompileError ("Can't add CHECK constraint" )
@@ -701,6 +715,7 @@ def get_column_specification(self, column, **kwargs):
701715
702716 comment = column .comment
703717 if comment is not None :
718+ comment = comment .replace ('\r ' , '\n \t ' )
704719 literal = self .sql_compiler .render_literal_value (comment , sqltypes .String ())
705720 colspec .append ("%DESCRIPTION " + literal )
706721
@@ -883,6 +898,12 @@ class IRISDialect(default.DefaultDialect):
883898 type_compiler = IRISTypeCompiler
884899 execution_ctx_cls = IRISExecutionContext
885900
901+ insert_returning = True
902+ insert_executemany_returning = True
903+ insert_executemany_returning_sort_by_parameter_order = True
904+ update_executemany_returning = False
905+ delete_executemany_returning = False
906+
886907 construct_arguments = [
887908 (schema .Index , {"include" : None }),
888909 ]
@@ -1105,6 +1126,38 @@ def get_schema(self, schema=None):
11051126 return "SQLUser"
11061127 return schema
11071128
1129+ @reflection .cache
1130+ def get_table_options (self , connection , table_name , schema = None , ** kw ):
1131+ if not self .has_table (connection = connection , table_name = table_name , schema = schema ):
1132+ raise exc .NoSuchTableError (
1133+ f"{ schema } .{ table_name } " if schema else table_name
1134+ ) from None
1135+ return {}
1136+
1137+ @reflection .cache
1138+ def get_table_comment (self , connection , table_name , schema = None , ** kw ):
1139+ if not self .has_table (connection = connection , table_name = table_name , schema = schema ):
1140+ raise exc .NoSuchTableError (
1141+ f"{ schema } .{ table_name } " if schema else table_name
1142+ ) from None
1143+
1144+ tables = ischema .tables
1145+ schema_name = self .get_schema (schema )
1146+
1147+ s = sql .select (tables .c .description ).where (
1148+ sql .and_ (
1149+ tables .c .table_schema == str (schema_name ),
1150+ tables .c .table_name == str (table_name ),
1151+ )
1152+ )
1153+ comment = connection .execute (s ).scalar ()
1154+ if comment :
1155+ # make it as \r
1156+ comment = comment .replace (' \t \t \t \t ' , '\r ' )
1157+ # restore \n
1158+ comment = comment .replace (' \t \t \t ' , '\n ' )
1159+ return {"text" : comment }
1160+
11081161 @reflection .cache
11091162 def get_schema_names (self , connection , ** kw ):
11101163 s = sql .select (ischema .schemata .c .schema_name ).order_by (
@@ -1131,7 +1184,7 @@ def get_table_names(self, connection, schema=None, **kw):
11311184 return table_names
11321185
11331186 @reflection .cache
1134- def get_temp_table_names (self , connection , dblink = None , ** kw ):
1187+ def get_temp_table_names (self , connection , ** kw ):
11351188 tables = ischema .tables
11361189 s = (
11371190 sql .select (tables .c .table_name )
@@ -1598,6 +1651,7 @@ def get_multi_columns(
15981651 columns .c .column_default ,
15991652 columns .c .collation_name ,
16001653 columns .c .auto_increment ,
1654+ columns .c .description ,
16011655 )
16021656 .select_from (columns )
16031657 .where (
@@ -1650,7 +1704,12 @@ def get_multi_columns(
16501704 sqlComputeCode = row [property .c .SqlComputeCode ]
16511705 calculated = row [property .c .Calculated ]
16521706 transient = row [property .c .Transient ]
1653- # description = row[columns.c.description]
1707+ comment = row [columns .c .description ]
1708+ if comment :
1709+ # make it as \r
1710+ comment = comment .replace (' \t \t \t \t ' , '\r ' )
1711+ # restore \n
1712+ comment = comment .replace (' \t \t \t ' , '\n ' )
16541713
16551714 coltype = self .ischema_names .get (type_ , None )
16561715
@@ -1696,7 +1755,7 @@ def get_multi_columns(
16961755 "nullable" : nullable ,
16971756 "default" : default ,
16981757 "autoincrement" : autoincrement ,
1699- # "comment": description ,
1758+ "comment" : comment ,
17001759 }
17011760 if sqlComputeCode and "set {*} = " in sqlComputeCode .lower ():
17021761 sqltext = sqlComputeCode
0 commit comments