Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45af228

Browse files
committed
fixes #370 (the bug was introduced with commit edb977a)#
1 parent 7ee07d0 commit 45af228

1 file changed

Lines changed: 42 additions & 35 deletions

File tree

plugins/generic/search.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def searchDb(self):
5656
dbConsider, dbCondParam = self.likeOrExact("database")
5757

5858
for db in dbList:
59+
values = []
5960
db = safeSQLIdentificatorNaming(db)
6061

6162
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2):
@@ -93,7 +94,7 @@ def searchDb(self):
9394
value = safeSQLIdentificatorNaming(value)
9495
foundDbs.append(value)
9596

96-
if len(foundDbs) == 0 and isInferenceAvailable() and not conf.direct:
97+
if not values and isInferenceAvailable() and not conf.direct:
9798
infoMsg = "fetching number of database"
9899
if dbConsider == "1":
99100
infoMsg += "s like"
@@ -166,6 +167,7 @@ def searchTable(self):
166167
tblConsider, tblCondParam = self.likeOrExact("table")
167168

168169
for tbl in tblList:
170+
values = []
169171
tbl = safeSQLIdentificatorNaming(tbl, True)
170172

171173
if Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.FIREBIRD):
@@ -219,49 +221,53 @@ def searchTable(self):
219221
else:
220222
foundTbls[foundDb] = [foundTbl]
221223

222-
if len(foundTbls) == 0 and isInferenceAvailable() and not conf.direct:
224+
if not values and isInferenceAvailable() and not conf.direct:
223225
if Backend.getIdentifiedDbms() not in (DBMS.SQLITE, DBMS.FIREBIRD):
224-
infoMsg = "fetching number of databases with table"
225-
if tblConsider == "1":
226-
infoMsg += "s like"
227-
infoMsg += " '%s'" % unsafeSQLIdentificatorNaming(tbl)
228-
logger.info(infoMsg)
226+
if len(whereDbsQuery) == 0:
227+
infoMsg = "fetching number of databases with table"
228+
if tblConsider == "1":
229+
infoMsg += "s like"
230+
infoMsg += " '%s'" % unsafeSQLIdentificatorNaming(tbl)
231+
logger.info(infoMsg)
229232

230-
query = rootQuery.blind.count
231-
query += tblQuery
232-
query += whereDbsQuery
233-
count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
233+
query = rootQuery.blind.count
234+
query += tblQuery
235+
query += whereDbsQuery
236+
count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
234237

235-
if not isNumPosStrValue(count):
236-
warnMsg = "no databases have table"
237-
if tblConsider == "1":
238-
warnMsg += "s like"
239-
warnMsg += " '%s'" % unsafeSQLIdentificatorNaming(tbl)
240-
logger.warn(warnMsg)
238+
if not isNumPosStrValue(count):
239+
warnMsg = "no databases have table"
240+
if tblConsider == "1":
241+
warnMsg += "s like"
242+
warnMsg += " '%s'" % unsafeSQLIdentificatorNaming(tbl)
243+
logger.warn(warnMsg)
241244

242-
continue
245+
continue
243246

244-
indexRange = getLimitRange(count)
247+
indexRange = getLimitRange(count)
245248

246-
for index in indexRange:
247-
query = rootQuery.blind.query
248-
query += tblQuery
249-
query += whereDbsQuery
250-
if Backend.isDbms(DBMS.DB2):
251-
query += ") AS foobar"
252-
query = agent.limitQuery(index, query)
249+
for index in indexRange:
250+
query = rootQuery.blind.query
251+
query += tblQuery
252+
query += whereDbsQuery
253+
if Backend.isDbms(DBMS.DB2):
254+
query += ") AS foobar"
255+
query = agent.limitQuery(index, query)
253256

254-
foundDb = unArrayizeValue(inject.getValue(query, union=False, error=False))
255-
foundDb = safeSQLIdentificatorNaming(foundDb)
257+
foundDb = unArrayizeValue(inject.getValue(query, union=False, error=False))
258+
foundDb = safeSQLIdentificatorNaming(foundDb)
256259

257-
if foundDb not in foundTbls:
258-
foundTbls[foundDb] = []
260+
if foundDb not in foundTbls:
261+
foundTbls[foundDb] = []
259262

260-
if tblConsider == "2":
261-
foundTbls[foundDb].append(tbl)
263+
if tblConsider == "2":
264+
foundTbls[foundDb].append(tbl)
262265

263-
if tblConsider == "2":
264-
continue
266+
if tblConsider == "2":
267+
continue
268+
else:
269+
for db in conf.db.split(","):
270+
foundTbls[db] = []
265271
else:
266272
dbName = "SQLite" if Backend.isDbms(DBMS.SQLITE) else "Firebird"
267273
foundTbls["%s%s" % (dbName, METADB_SUFFIX)] = []
@@ -364,6 +370,7 @@ def searchColumn(self):
364370
colConsider, colCondParam = self.likeOrExact("column")
365371

366372
for column in colList:
373+
values = []
367374
column = safeSQLIdentificatorNaming(column)
368375
conf.db = origDb
369376
conf.tbl = origTbl
@@ -449,7 +456,7 @@ def searchColumn(self):
449456

450457
kb.data.cachedColumns = {}
451458

452-
if len(dbs) == 0 and isInferenceAvailable() and not conf.direct:
459+
if not values and isInferenceAvailable() and not conf.direct:
453460
if not conf.db:
454461
infoMsg = "fetching number of databases with tables containing column"
455462
if colConsider == "1":

0 commit comments

Comments
 (0)