More code refactoring of Backend class methods used

This commit is contained in:
Bernardo Damele
2011-04-30 14:54:29 +00:00
parent 2f2758b033
commit 9a4ae7d9e2
16 changed files with 146 additions and 146 deletions

View File

@@ -282,14 +282,14 @@ class Agent:
# SQLite version 2 does not support neither CAST() nor IFNULL(),
# introduced only in SQLite version 3
if Backend.getIdentifiedDbms() == DBMS.SQLITE:
if Backend.isDbms(DBMS.SQLITE):
return field
if field.startswith("(CASE"):
nulledCastedField = field
else:
nulledCastedField = queries[Backend.getIdentifiedDbms()].cast.query % field
if Backend.getIdentifiedDbms() == DBMS.ACCESS:
if Backend.isDbms(DBMS.ACCESS):
nulledCastedField = queries[Backend.getIdentifiedDbms()].isnull.query % (nulledCastedField, nulledCastedField)
else:
nulledCastedField = queries[Backend.getIdentifiedDbms()].isnull.query % nulledCastedField
@@ -401,7 +401,7 @@ class Agent:
def simpleConcatQuery(self, query1, query2):
concatenatedQuery = ""
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
concatenatedQuery = "CONCAT(%s,%s)" % (query1, query2)
elif Backend.getIdentifiedDbms() in (DBMS.PGSQL, DBMS.ORACLE, DBMS.SQLITE):
@@ -447,7 +447,7 @@ class Agent:
else:
return query
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
if fieldsExists:
concatenatedQuery = concatenatedQuery.replace("SELECT ", "CONCAT('%s'," % kb.misc.start, 1)
concatenatedQuery += ",'%s')" % kb.misc.stop
@@ -540,7 +540,7 @@ class Agent:
if query.startswith("TOP"):
# TOP enumeration on DBMS.MSSQL is too specific and it has to go into it's own brackets
# because those NULLs cause problems with ORDER BY clause
if Backend.getIdentifiedDbms() == DBMS.MSSQL:
if Backend.isDbms(DBMS.MSSQL):
inbandQuery += ",".join(map(lambda x: char if x != position else '(SELECT %s)' % query, range(0, count)))
inbandQuery = self.suffixQuery(inbandQuery, comment, suffix)
return inbandQuery
@@ -633,11 +633,11 @@ class Agent:
limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num, 1)
limitedQuery += " %s" % limitStr
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num+1, num+1)
limitedQuery += " %s" % limitStr
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
if " ORDER BY " in limitedQuery and "(SELECT " in limitedQuery:
orderBy = limitedQuery[limitedQuery.index(" ORDER BY "):]
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
@@ -650,7 +650,7 @@ class Agent:
limitedQuery = limitedQuery % fromFrom
limitedQuery += "=%d" % (num + 1)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
forgeNotIn = True
if " ORDER BY " in limitedQuery:

View File

@@ -869,7 +869,7 @@ def parsePasswordHash(password):
if not password or password == " ":
password = "NULL"
if Backend.getIdentifiedDbms() == DBMS.MSSQL and password != "NULL" and isHexEncodedString(password):
if Backend.isDbms(DBMS.MSSQL) and password != "NULL" and isHexEncodedString(password):
hexPassword = password
password = "%s\n" % hexPassword
password += "%sheader: %s\n" % (blank, hexPassword[:6])
@@ -1194,11 +1194,11 @@ def getDelayQuery(andCond=False):
banVer = kb.bannerFp["dbmsVersion"] if 'dbmsVersion' in kb.bannerFp else None
if banVer is None or (Backend.getIdentifiedDbms() == DBMS.MYSQL and banVer >= "5.0.12") or (Backend.getIdentifiedDbms() == DBMS.PGSQL and banVer >= "8.2"):
if banVer is None or (Backend.isDbms(DBMS.MYSQL) and banVer >= "5.0.12") or (Backend.isDbms(DBMS.PGSQL) and banVer >= "8.2"):
query = queries[Backend.getIdentifiedDbms()].timedelay.query % conf.timeSec
else:
query = queries[Backend.getIdentifiedDbms()].timedelay.query2 % conf.timeSec
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
query = queries[Backend.getIdentifiedDbms()].timedelay.query
else:
query = queries[Backend.getIdentifiedDbms()].timedelay.query % conf.timeSec
@@ -1206,7 +1206,7 @@ def getDelayQuery(andCond=False):
if andCond:
if Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.SQLITE ):
query = query.replace("SELECT ", "")
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
query = "(%s)>0" % query
return query

View File

@@ -104,9 +104,9 @@ class Dump:
self.string("current user", data)
def currentDb(self,data):
if Backend.getIdentifiedDbms() == DBMS.MAXDB:
if Backend.isDbms(DBMS.MAXDB):
self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data)
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data)
else:
self.string("current database", data)