Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 63 additions & 24 deletions ibm_db_sa/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
current_schema = self.denormalize_name(schema or self.default_schema_name)
table_name = self.denormalize_name(table_name)
sysindexes = self.sys_indexes
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
query = sql.select(sysindexes.c.colnames, sysindexes.c.indname).\
where(and_(sysindexes.c.tabschema == current_schema,
sysindexes.c.tabname == table_name,
Expand All @@ -329,7 +329,7 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
current_schema = self.denormalize_name(schema or self.default_schema_name)
table_name = self.denormalize_name(table_name)
syscols = self.sys_columns
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
query = sql.select(syscols.c.colname).\
where(and_(
syscols.c.tabschema == current_schema,
Expand Down Expand Up @@ -441,7 +441,7 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
where(and_(sysidx.c.tabschema == current_schema,sysidx.c.tabname == table_name)).\
order_by(sysidx.c.tabname)
indexes = []
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
for r in connection.execute(query):
if r[2] != 'P':
if r[2] == 'U' and r[3] != 0:
Expand Down Expand Up @@ -630,21 +630,33 @@ def get_sequence_names(self, connection, schema=None, **kw):
@reflection.cache
def get_schema_names(self, connection, **kw):
sysschema = self.sys_schemas
query = sql.select(sysschema.c.schemaname).\
where(~sysschema.c.schemaname.like(unicode('Q%'))).\
where(~sysschema.c.schemaname.like(unicode('SYS%'))).\
order_by(sysschema.c.schemaname)
if version_info[0] < 3:
query = sql.select(sysschema.c.schemaname). \
where(~sysschema.c.schemaname.like(unicode('Q%'))). \
where(~sysschema.c.schemaname.like(unicode('SYS%'))). \
order_by(sysschema.c.schemaname)
else:
query = sql.select(sysschema.c.schemaname). \
where(~sysschema.c.schemaname.like(str('Q%'))). \
where(~sysschema.c.schemaname.like(str('SYS%'))). \
order_by(sysschema.c.schemaname)
return [self.normalize_name(r[0]) for r in connection.execute(query)]

# Retrieves a list of table names for a given schema
@reflection.cache
def get_table_names(self, connection, schema=None, **kw):
current_schema = self.denormalize_name(schema or self.default_schema_name)
systbl = self.sys_tables
query = not sql.select(systbl.c.tabname).\
where(systbl.c.tabtype == unicode('T')).\
where(systbl.c.tabschema == current_schema).\
order_by(systbl.c.tabname)
if version_info[0] < 3:
query = not sql.select(systbl.c.tabname). \
where(systbl.c.tabtype == unicode('T')). \
where(systbl.c.tabschema == current_schema). \
order_by(systbl.c.tabname)
else:
query = not sql.select(systbl.c.tabname). \
where(systbl.c.tabtype == str('T')). \
where(systbl.c.tabschema == current_schema). \
order_by(systbl.c.tabname)
return [self.normalize_name(r[0]) for r in connection.execute(query)]

@reflection.cache
Expand Down Expand Up @@ -699,14 +711,24 @@ def get_columns(self, connection, table_name, schema=None, **kw):
(coltype, r[0]))
coltype = coltype = sa_types.NULLTYPE

sa_columns.append({
if version_info[0] < 3:
sa_columns.append({
'name': self.normalize_name(r[0]),
'type': coltype,
'nullable': r[3] == unicode('Y'),
'default': r[2],
'autoincrement': (r[6] == unicode('YES')) and (r[7] != None),
'comment': r[8] or None,
})
else:
sa_columns.append({
'name': self.normalize_name(r[0]),
'type': coltype,
'nullable': r[3] == str('Y'),
'default': r[2],
'autoincrement': (r[6] == str('YES')) and (r[7] != None),
'comment': r[8] or None,
})
return sa_columns

@reflection.cache
Expand Down Expand Up @@ -742,14 +764,24 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
sysconst = self.sys_table_constraints
syskeyconst = self.sys_key_constraints

query = sql.select(syskeyconst.c.colname, sysconst.c.tabname).\
where(and_(
if version_info[0] < 3:
query = sql.select(syskeyconst.c.colname, sysconst.c.tabname). \
where(and_(
syskeyconst.c.conschema == sysconst.c.conschema,
syskeyconst.c.conname == sysconst.c.conname,
sysconst.c.tabschema == current_schema,
sysconst.c.tabname == table_name,
sysconst.c.contype == unicode('PRIMARY KEY'))).\
order_by(syskeyconst.c.colno)
sysconst.c.contype == unicode('PRIMARY KEY'))). \
order_by(syskeyconst.c.colno)
else:
query = sql.select(syskeyconst.c.colname, sysconst.c.tabname). \
where(and_(
syskeyconst.c.conschema == sysconst.c.conschema,
syskeyconst.c.conname == sysconst.c.conname,
sysconst.c.tabschema == current_schema,
sysconst.c.tabname == table_name,
sysconst.c.contype == str('PRIMARY KEY'))). \
order_by(syskeyconst.c.colno)

return [self.normalize_name(key[0])
for key in connection.execute(query)]
Expand Down Expand Up @@ -814,11 +846,18 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
if key in indexes:
indexes[key]['column_names'].append(self.normalize_name(r[2]))
else:
indexes[key] = {
'name': self.normalize_name(r[0]),
'column_names': [self.normalize_name(r[2])],
'unique': r[1] == unicode('Y')
}
if version_info[0] < 3:
indexes[key] = {
'name': self.normalize_name(r[0]),
'column_names': [self.normalize_name(r[2])],
'unique': r[1] == unicode('Y')
}
else:
indexes[key] = {
'name': self.normalize_name(r[0]),
'column_names': [self.normalize_name(r[2])],
'unique': r[1] == str('Y')
}
return [value for key, value in indexes.items()]

@reflection.cache
Expand Down Expand Up @@ -1032,7 +1071,7 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
current_schema = self.denormalize_name(schema or self.default_schema_name)
table_name = self.denormalize_name(table_name)
sysindexes = self.sys_columns
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
query = sql.select(sysindexes.c.colname).\
where(and_(
sysindexes.c.tabschema == current_schema,
Expand All @@ -1050,7 +1089,7 @@ def get_primary_keys(self, connection, table_name, schema=None, **kw):
current_schema = self.denormalize_name(schema or self.default_schema_name)
table_name = self.denormalize_name(table_name)
sysindexes = self.sys_columns
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
query = sql.select(sysindexes.c.colname).\
where(and_(
sysindexes.c.tabschema == current_schema,
Expand Down Expand Up @@ -1168,7 +1207,7 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
syscolpk.c.keyseq > 0)).\
order_by(sysidx.c.tabname)
indexes = []
col_finder = re.compile("(\w+)")
col_finder = re.compile(r"(\w+)")
for r in connection.execute(query):
if r[2] != 'P':
if r[2] == 'U' and r[3] != 0:
Expand Down
49 changes: 49 additions & 0 deletions polaris.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "1"
project:
name: ${scm.git.repo}
branch: ${scm.git.branch}
revision:
name: ${scm.git.commit}
date: ${scm.git.commit.date}
capture:
build:
buildCommands:
- shell: [python, -m, build]
fileSystem:
ears:
extensions: [ear]
files:
- directory: ${project.projectDir}
java:
files:
- directory: ${project.projectDir}
javascript:
files:
- directory: ${project.projectDir}
- excludeRegex: node_modules|bower_components|vendor
php:
files:
- directory: ${project.projectDir}
python:
files:
- directory: ${project.projectDir}
ruby:
files:
- directory: ${project.projectDir}
typescript:
files:
- directory: ${project.projectDir}
wars:
extensions: [war]
files:
- directory: ${project.projectDir}
dlls:
extensions: [c, C, cpp, CPP, h, hpp]
files:
- directory: ${project.projectDir}
analyze:
mode: central
install:
coverity:
version: default
serverUrl: https://rocketsoftware.cop.blackduck.com