@@ -388,6 +388,19 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
388388
389389 conf .db = safeSQLIdentificatorNaming (conf .db )
390390
391+ if conf .col :
392+ if Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
393+ conf .col = conf .col .upper ()
394+
395+ colList = conf .col .split ("," )
396+ else :
397+ colList = []
398+
399+ for col in colList :
400+ colList [colList .index (col )] = safeSQLIdentificatorNaming (col )
401+
402+ colList = filter (None , colList )
403+
391404 if conf .tbl :
392405 if Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
393406 conf .tbl = conf .tbl .upper ()
@@ -427,19 +440,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
427440 logger .error (errMsg )
428441 bruteForce = True
429442
430- if bruteForce :
431- if conf .col :
432- if Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
433- conf .col = conf .col .upper ()
434-
435- colList = conf .col .split ("," )
436- else :
437- colList = []
438-
439- for col in colList :
440- colList [colList .index (col )] = safeSQLIdentificatorNaming (col )
441-
442- colList = filter (None , colList )
443+ if bruteForce or colList :
443444 resumeAvailable = False
444445
445446 for tbl in tblList :
@@ -490,17 +491,37 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
490491
491492 return {conf .db : kb .data .cachedColumns [conf .db ]}
492493
493- infoMsg = "fetching columns for table '%s' " % unsafeSQLIdentificatorNaming (tbl )
494+ infoMsg = "fetching columns "
495+
496+ if len (colList ) > 0 :
497+ if colTuple is None :
498+ colConsider , colCondParam = self .likeOrExact ("column" )
499+ else :
500+ colConsider , colCondParam = colTuple
501+ condQueryStr = "%%s%s" % colCondParam
502+ condQuery = " AND (%s)" % " OR " .join (condQueryStr % (condition , unsafeSQLIdentificatorNaming (col )) for col in sorted (colList ))
503+
504+ if colConsider == "1" :
505+ infoMsg += "like '%s' " % ", " .join (unsafeSQLIdentificatorNaming (col ) for col in sorted (colList ))
506+ else :
507+ infoMsg += "'%s' " % ", " .join (unsafeSQLIdentificatorNaming (col ) for col in sorted (colList ))
508+ else :
509+ condQuery = ""
510+
511+ infoMsg += "for table '%s' " % unsafeSQLIdentificatorNaming (tbl )
494512 infoMsg += "in database '%s'" % unsafeSQLIdentificatorNaming (conf .db )
495513 logger .info (infoMsg )
496514
497515 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .PGSQL ):
498516 query = rootQuery .inband .query % (unsafeSQLIdentificatorNaming (tbl ), unsafeSQLIdentificatorNaming (conf .db ))
517+ query += condQuery
499518 elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
500519 query = rootQuery .inband .query % unsafeSQLIdentificatorNaming (tbl .upper ())
520+ query += condQuery
501521 elif Backend .isDbms (DBMS .MSSQL ):
502522 query = rootQuery .inband .query % (conf .db , conf .db , conf .db , conf .db ,
503523 conf .db , conf .db , conf .db , unsafeSQLIdentificatorNaming (tbl ).split ("." )[- 1 ])
524+ query += condQuery .replace ("[DB]" , conf .db )
504525 elif Backend .isDbms (DBMS .SQLITE ):
505526 query = rootQuery .inband .query % tbl
506527
@@ -539,19 +560,44 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
539560
540561 return {conf .db : kb .data .cachedColumns [conf .db ]}
541562
542- infoMsg = "fetching columns for table '%s' " % unsafeSQLIdentificatorNaming (tbl )
563+ infoMsg = "fetching columns "
564+
565+ if len (colList ) > 0 :
566+ if colTuple is None :
567+ colConsider , colCondParam = self .likeOrExact ("column" )
568+ else :
569+ colConsider , colCondParam = colTuple
570+ condQueryStr = "%%s%s" % colCondParam
571+ condQuery = " AND (%s)" % " OR " .join (condQueryStr % (condition , unsafeSQLIdentificatorNaming (col )) for col in sorted (colList ))
572+
573+ if colConsider == "1" :
574+ infoMsg += "like '%s' " % ", " .join (unsafeSQLIdentificatorNaming (col ) for col in sorted (colList ))
575+ else :
576+ infoMsg += "'%s' " % ", " .join (unsafeSQLIdentificatorNaming (col ) for col in sorted (colList ))
577+ else :
578+ condQuery = ""
579+
580+ infoMsg += "for table '%s' " % unsafeSQLIdentificatorNaming (tbl )
543581 infoMsg += "in database '%s'" % unsafeSQLIdentificatorNaming (conf .db )
544582 logger .info (infoMsg )
545583
546584 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .PGSQL ):
547585 query = rootQuery .blind .count % (unsafeSQLIdentificatorNaming (tbl ), unsafeSQLIdentificatorNaming (conf .db ))
586+ query += condQuery
587+
548588 elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
549589 query = rootQuery .blind .count % unsafeSQLIdentificatorNaming (tbl .upper ())
590+ query += condQuery
591+
550592 elif Backend .isDbms (DBMS .MSSQL ):
551593 query = rootQuery .blind .count % (conf .db , conf .db , \
552594 unsafeSQLIdentificatorNaming (tbl ).split ("." )[- 1 ])
595+ query += condQuery .replace ("[DB]" , conf .db )
596+
553597 elif Backend .isDbms (DBMS .FIREBIRD ):
554598 query = rootQuery .blind .count % (tbl )
599+ query += condQuery
600+
555601 elif Backend .isDbms (DBMS .SQLITE ):
556602 query = rootQuery .blind .query % tbl
557603 value = inject .getValue (query , union = False , error = False )
@@ -574,15 +620,19 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
574620 for index in getLimitRange (count ):
575621 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .PGSQL ):
576622 query = rootQuery .blind .query % (unsafeSQLIdentificatorNaming (tbl ), unsafeSQLIdentificatorNaming (conf .db ))
623+ query += condQuery
577624 field = None
578625 elif Backend .getIdentifiedDbms () in (DBMS .ORACLE , DBMS .DB2 ):
579626 query = rootQuery .blind .query % unsafeSQLIdentificatorNaming (tbl .upper ())
627+ query += condQuery
580628 field = None
581629 elif Backend .isDbms (DBMS .MSSQL ):
582630 query = rootQuery .blind .query .replace ("'%s'" , "'%s'" % unsafeSQLIdentificatorNaming (tbl ).split ("." )[- 1 ]).replace ("%s" , conf .db ).replace ("%d" , str (index ))
631+ query += condQuery .replace ("[DB]" , conf .db )
583632 field = condition .replace ("[DB]" , conf .db )
584633 elif Backend .isDbms (DBMS .FIREBIRD ):
585634 query = rootQuery .blind .query % (tbl )
635+ query += condQuery
586636 field = None
587637
588638 query = agent .limitQuery (index , query , field , field )
0 commit comments