Skip to content

Commit

Permalink
Release 038 (#109)
Browse files Browse the repository at this point in the history
* code fix for issue #106

Signed-off-by: amukherjee <[email protected]>

* Code changes for issue #24

Signed-off-by: amukherjee <[email protected]>

* PR changes #74

Signed-off-by: amukherjee <[email protected]>

* Fix for issue #20 and PR #56

Signed-off-by: amukherjee <[email protected]>
  • Loading branch information
amukherjee28 authored Apr 27, 2022
1 parent 1e79716 commit 1a811a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ibm_db_sa/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ def visit_select(self, select, **kwargs):
return sql_ori

def visit_sequence(self, sequence, **kw):
if sequence.schema:
return "NEXT VALUE FOR %s.%s" % (sequence.schema, sequence.name)
return "NEXT VALUE FOR %s" % sequence.name

def default_from(self):
Expand Down Expand Up @@ -675,6 +677,7 @@ class DB2Dialect(default.DefaultDialect):
supports_sane_multi_rowcount = True
supports_native_decimal = False
supports_native_boolean = False
supports_statement_cache = False
preexecute_sequences = False
supports_alter = True
supports_sequences = True
Expand Down
1 change: 1 addition & 0 deletions ibm_db_sa/ibm_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def get_result_proxy(self):
class DB2Dialect_ibm_db(DB2Dialect):
driver = 'ibm_db_sa'
supports_unicode_statements = True
supports_statement_cache = False
supports_sane_rowcount = True
supports_sane_multi_rowcount = False
supports_native_decimal = False
Expand Down
32 changes: 21 additions & 11 deletions ibm_db_sa/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# +--------------------------------------------------------------------------+
import sys
from sqlalchemy import types as sa_types
from sqlalchemy import sql, util
from sqlalchemy import sql, util, join
from sqlalchemy import Table, MetaData, Column
from sqlalchemy.engine import reflection
import re
Expand Down Expand Up @@ -156,6 +156,7 @@ class DB2Reflector(BaseReflector):
Column("NULLS", CoerceUnicode, key="nullable"),
Column("IDENTITY", CoerceUnicode, key="identity"),
Column("GENERATED", CoerceUnicode, key="generated"),
Column("REMARKS", CoerceUnicode, key="remarks"),
schema="SYSCAT")

sys_views = Table("VIEWS", ischema,
Expand Down Expand Up @@ -264,7 +265,8 @@ def get_columns(self, connection, table_name, schema=None, **kw):
query = sql.select([syscols.c.colname, syscols.c.typename,
syscols.c.defaultval, syscols.c.nullable,
syscols.c.length, syscols.c.scale,
syscols.c.identity, syscols.c.generated],
syscols.c.identity, syscols.c.generated,
syscols.c.remarks],
sql.and_(
syscols.c.tabschema == current_schema,
syscols.c.tabname == table_name
Expand Down Expand Up @@ -293,6 +295,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
'nullable': r[3] == 'Y',
'default': r[2] or None,
'autoincrement': (r[6] == 'Y') and (r[7] != ' '),
'comment': r[8] or None,
})
return sa_columns

Expand Down Expand Up @@ -346,16 +349,18 @@ def get_foreign_keys(self, connection, table_name, schema=None, **kw):
default_schema = self.normalize_name(default_schema)
table_name = self.denormalize_name(table_name)
sysfkeys = self.sys_foreignkeys
systbl = self.sys_tables
query = sql.select([sysfkeys.c.fkname, sysfkeys.c.fktabschema, \
sysfkeys.c.fktabname, sysfkeys.c.fkcolname, \
sysfkeys.c.pkname, sysfkeys.c.pktabschema, \
sysfkeys.c.pktabname, sysfkeys.c.pkcolname],
sql.and_(
sysfkeys.c.fktabschema == current_schema,
sysfkeys.c.fktabname == table_name
),
order_by=[sysfkeys.c.colno]
)
sysfkeys.c.pktabname, sysfkeys.c.pkcolname]) \
.select_from(
join(systbl,sysfkeys, systbl.c.tabname == sysfkeys.c.pktabname)
) \
.where(systbl.c.type == 'T') \
.where(systbl.c.tabschema == current_schema) \
.where(sysfkeys.c.fktabname == table_name) \
.order_by(systbl.c.tabname)

fschema = {}
for r in connection.execute(query):
Expand Down Expand Up @@ -518,6 +523,7 @@ class AS400Reflector(BaseReflector):
Column("HAS_DEFAULT", CoerceUnicode, key="hasdef"),
Column("IS_IDENTITY", CoerceUnicode, key="isid"),
Column("IDENTITY_GENERATION", CoerceUnicode, key="idgenerate"),
Column("LONG_COMMENT", CoerceUnicode, key="remark"),
schema="QSYS2")

sys_indexes = Table("SYSINDEXES", ischema,
Expand Down Expand Up @@ -653,7 +659,8 @@ def get_columns(self, connection, table_name, schema=None, **kw):
syscols.c.typename,
syscols.c.defaultval, syscols.c.nullable,
syscols.c.length, syscols.c.scale,
syscols.c.isid, syscols.c.idgenerate],
syscols.c.isid, syscols.c.idgenerate,
syscols.c.remark],
sql.and_(
syscols.c.tabschema == current_schema,
syscols.c.tabname == table_name
Expand Down Expand Up @@ -682,6 +689,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
'nullable': r[3] == 'Y',
'default': r[2],
'autoincrement': (r[6] == 'YES') and (r[7] != None),
'comment': r[8] or None,
})
return sa_columns

Expand Down Expand Up @@ -874,6 +882,7 @@ class OS390Reflector(BaseReflector):
Column("NULLS", CoerceUnicode, key="nullable"),
Column("GENERATED_ATTR", CoerceUnicode, key="generated"),
Column("KEYSEQ", sa_types.Integer, key="keyseq"),
Column("REMARKS", sa_types.Integer, key="remark"),
schema="SYSIBM")

sys_views = Table("SYSVIEWS", ischema,
Expand Down Expand Up @@ -972,7 +981,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
query = sql.select([syscols.c.colname, syscols.c.typename,
syscols.c.defaultval, syscols.c.nullable,
syscols.c.length, syscols.c.scale,
syscols.c.generated],
syscols.c.generated, syscols.c.remark],
sql.and_(
syscols.c.tabschema == current_schema,
syscols.c.tabname == table_name
Expand Down Expand Up @@ -1001,6 +1010,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
'nullable': r[3] == 'Y',
'default': r[2] or None,
'autoincrement': (r[2] == 'J') and (r[2] != ' ') ,
'comment': r[7] or None,
})
return sa_columns

Expand Down

0 comments on commit 1a811a8

Please sign in to comment.