Commit bb1b3faa authored by Ajay Patel's avatar Ajay Patel

Fix linting errors

parent d8d24b06
Pipeline #36985040 failed with stages
in 22 minutes and 30 seconds
[flake8]
ignore = E261,E402,W504
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,setup.py,icu_sources.py,supersqlite/third_party,supersqlite/third_party_mock,benchmark.py,supersqlite/req_wheels
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,setup.py,icu_sources.py,supersqlite/third_party,supersqlite/third_party_mock,benchmark.py,supersqlite/req_wheels,supersqlite/idxchk.py
max-line-length = 80
\ No newline at end of file
......@@ -513,7 +513,15 @@ THIRD_PARTY = PROJ_PATH + '/' + PACKAGE_NAME + '/third_party'
BUILD_PATH = PROJ_PATH + '/build'
BUILD_THIRD_PARTY = BUILD_PATH + '/lib/' + PACKAGE_NAME + '/third_party'
INTERNAL = THIRD_PARTY + '/internal'
BINARY_EXTENSIONS = ('.so', '.pyd', '.dll', '.o', '.obj', '.lib', '.dylib', '.a')
BINARY_EXTENSIONS = (
'.so',
'.pyd',
'.dll',
'.o',
'.obj',
'.lib',
'.dylib',
'.a')
# Get the package version
__version__ = None
......
......@@ -24,10 +24,10 @@ except ImportError:
import apsw
sqlite_connect, SQLError = apsw.Connection, apsw.SQLError
debug = False # if true, displays SQL.
debug = False # if true, displays SQL.
verbose = False
dbname = ''
sql = ''
dbname = ''
sql = ''
if '-debug' in sys.argv:
debug = True
......@@ -37,7 +37,7 @@ if '-v' in sys.argv:
verbose = True
sys.argv.remove('-v')
if len(sys.argv)<=1:
if len(sys.argv) <= 1:
print 'usage: %s [-v] [-debug] dbfile [sqlcmds ...]' % sys.argv[0]
print
print ' -v verbose output: opcodes, databases, tables, cursors'
......@@ -52,7 +52,7 @@ if len(sys.argv)<=1:
dbname = sys.argv[1]
# if sql parm is missing, read from stdin
if len(sys.argv)>2:
if len(sys.argv) > 2:
sql = ' '.join(sys.argv[2:]) + ' \n;\n'
else:
sql = sys.stdin.read()
......@@ -61,11 +61,13 @@ else:
# Connect to database.
session = sqlite_connect(dbname)
def DO(sql, params={}, cur=session.cursor()):
'Run some SQL.'
if debug:
print '>>>', '\n...'.join(sql.split('\n'))
if params: print ' %s' % params
if params:
print ' %s' % params
try:
cur.execute(sql, params)
rows = []
......@@ -81,14 +83,14 @@ def DO(sql, params={}, cur=session.cursor()):
# eg, if temp tables are created and indexed, attach other db's, etc.
idxsql = ''
while len(idxsql)==0:
while len(idxsql) == 0:
sqlcmds = sql.split(';')
if sqlcmds:
presql = sqlcmds[:-1]
idxsql = sqlcmds[-1].strip()
sql = ';'.join(presql)
presql = sqlcmds[:-1]
idxsql = sqlcmds[-1].strip()
sql = ';'.join(presql)
else:
print 'no sqlcmds to explain'
print 'no sqlcmds to explain'
session.close()
sys.exit(2)
......@@ -102,20 +104,20 @@ for s in presql:
print '----------------------------------------------------------'
print s.replace('\n', ' ')[:50], '.....'
print
try:
DO(s)
except SQLError, e:
except SQLError as e:
print 'sql error while executing statement %d:' % cnt
print s + '\n\nerror message:\n' + str(e)
session.close()
sys.exit(3)
cnt += 1
try:
vcode = DO('EXPLAIN ' + idxsql)
except SQLError, e:
except SQLError as e:
print 'sql error while explaining statement %d:' % cnt
print idxsql + '\n\nerror message:\n' + str(e)
session.close()
......@@ -131,11 +133,11 @@ dbarr = {}
for dbnum, dbname, dbfile in DO('pragma database_list'):
dbarr[dbnum] = dbname
if verbose:
print '%6d %s (%s)' % (dbnum, dbname, dbfile)
print '%6d %s (%s)' % (dbnum, dbname, dbfile)
prevint = -1
idxtbl = {}
idxtbl = {}
nesting = []
cursors = []
......@@ -144,34 +146,34 @@ for addr, opcode, p1, p2, p3 in vcode:
if opcode == 'Integer':
prevint = p1
elif opcode == 'OpenRead':
if prevint == -1: # previous opcode was not Integer!
if prevint == -1: # previous opcode was not Integer!
continue
dbnum = prevint
if dbnum not in dbarr:
# explained statement is probably creating a temp table
dbarr[dbnum] = 'temp'
if dbarr[dbnum] == 'temp':
temp = 'temp_'
else:
temp = ''
if dbarr[dbnum] != 'main' and dbarr[dbnum] != 'temp':
dbname = dbarr[dbnum] + '.'
else:
dbname = ''
if p2 == 1: # opening sqlite_master itself, skip
continue
schemasql = '''SELECT type, name, tbl_name, rootpage
FROM %(dbname)ssqlite_%(temp)smaster
WHERE rootpage = %(p2)s''' % locals()
type, name, tbl_name, rootpage = DO(schemasql)[0]
cursors.append((p1, type, dbname+name, name, tbl_name))
cursors.append((p1, type, dbname + name, name, tbl_name))
else:
# reset int value, if preceeding opcode not Integer
......@@ -187,7 +189,7 @@ if verbose:
print 'opcodes'
print '----------------------------------------------------------'
for addr, opcode, p1, p2, p3 in vcode:
print '%s|%s|%s|%s|%s' % (addr, opcode, p1, p2, p3)
print '%s|%s|%s|%s|%s' % (addr, opcode, p1, p2, p3)
print
......@@ -195,56 +197,55 @@ prevint = -1 # not present in the original Tcl - bug?
for addr, opcode, p1, p2, p3 in vcode:
if opcode == 'Integer':
prevint = p1
prevint = p1
elif opcode == 'OpenRead':
if prevint == -1: # previous opcode was not Integer!
continue
dbnum = prevint
if dbnum not in dbarr:
# explained statement is probably creating a temp table
dbarr[dbnum] = 'temp'
if dbarr[dbnum] == 'temp':
temp = 'temp_'
else:
temp = ''
if dbarr[dbnum] != 'main' and dbarr[dbnum] != 'temp':
dbname = dbarr[dbnum] + '.'
else:
dbname = ''
schemasql = '''SELECT type, name, tbl_name, rootpage
FROM %(dbname)ssqlite_%(temp)smaster
WHERE rootpage = %(p2)s''' % locals()
type, name, tbl_name, rootpage = DO(schemasql)[0]
idxtab = dbname + tbl_name
#cursors.append((p1, type, dbnamename))
if type == 'index':
# get info for table, all indexes, and this index
pr_tbl_info = DO('pragma table_info(%s)' % tbl_name)
pr_idx_list = DO('pragma index_list(%s)' % tbl_name)
pr_idx_info = DO('pragma index_info(%s)' % name)
cols = []
pkcollist = []
# sort index column names and assemble index columns
ielems = []
for seq, cid, iname in pr_idx_info:
ielems.append((seq, cid, iname))
for seq, cid, iname in sorted(ielems):
cols.append(iname)
pkcollist.append(iname)
cols = '(%s)' % ','.join(cols)
# if index itself is unique
unique = ''
for iseq, iname, isuniq in pr_idx_list:
......@@ -252,10 +253,10 @@ for addr, opcode, p1, p2, p3 in vcode:
unique = ' UNIQUE'
break
cols += unique
# index is primary key if all pkcollist names are in table pk cols
i = -1
#for cid, cname, ctype, ispk in pr_tbl_info: # outdated.
# for cid, cname, ctype, ispk in pr_tbl_info: # outdated.
for cid, cname, ctype, notnull, dflt_value, ispk in pr_tbl_info:
try:
ispk = int(ispk)
......@@ -269,31 +270,31 @@ for addr, opcode, p1, p2, p3 in vcode:
break
# remove this column name from pkcollist
del pkcollist[i]
if i >= 0 and not pkcollist:
# found all of the table pk columns in the pkcollist
cols += ' PRIMARY KEY'
idxtbl[idxtab] = idxtbl.get(idxtab, [])
idxtbl[idxtab].append((name, cols))
elif type == 'table':
# if not in idxtbl array, add it with empty index info
if idxtab not in idxtbl:
idxtbl[idxtab] = []
if idxtab not in nesting:
nesting.append(idxtab)
elif opcode=='NotExists' or opcode=='MoveGe' or opcode=='MoveLt':
elif opcode == 'NotExists' or opcode == 'MoveGe' or opcode == 'MoveLt':
# check for possible primary key usage
for cp1, ctype, ctab, cname, ctbl in cursors:
if p1==cp1 and ctype=='table':
if p1 == cp1 and ctype == 'table':
idxtbl[ctab].append(('<pk>', '<integer primary key or rowid>'))
break
else:
# reset int value, if preceeding opcode not Integer
prevint = -1
......@@ -306,10 +307,10 @@ if verbose:
for tab in nesting:
print '| ' * lev + tab
lev += 1
if lev > 1:
print '| ' * lev
print '| ' * lev
print
print 'cursor type name'
print '------ ------ ----------------------------------------------'
......@@ -330,14 +331,14 @@ len2 = 10
len3 = 10
for tbl, idxlist in idxtbl.items():
if len(tbl) > len1:
len1 = len(tbl)
len1 = len(tbl)
for idx, idxdef in idxlist:
if len(idx) > len2:
len2 = len(idx)
len2 = len(idx)
if len(idxdef) > len3:
len3 = len(idxdef)
len3 = len(idxdef)
fmt = '%-{len1}.{len1}s %-{len2}.{len2}s %-{len3}.{len3}s'
......@@ -345,7 +346,7 @@ fmt = '%-{len1}.{len1}s %-{len2}.{len2}s %-{len3}.{len3}s'
fmt = fmt.replace('%', '%%').replace('{', '%(').replace('}', ')s') % locals()
print fmt % ('table', 'index(es)', 'column(s)')
print fmt % ('-'*len1, '-'*len2, '-'*len3)
print fmt % ('-' * len1, '-' * len2, '-' * len3)
# now print in order of table open nesting
for tbl in nesting:
......@@ -358,15 +359,17 @@ for tbl in nesting:
idx, idxdef = ientry
print fmt % (tbl, idx, idxdef)
#tbl = ''
try: del idxtbl[t]
except KeyError: pass
try:
del idxtbl[t]
except KeyError:
pass
# print any other indexes where index was opened, but not table
for tbl in idxtbl:
idxlist = idxtbl[tbl]
if not idxlist:
print fmt % (tbl, '(none)', '')
print fmt % (tbl, '(none)', '')
else:
for ientry in idxlist:
idx, idxdef = ientry
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment