MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / limitQuery

Method limitQuery

lib/core/agent.py:1012–1170  ·  view source on GitHub ↗

Take in input a query string and return its limited query string. Example: Input: SELECT user FROM mysql.users Output: SELECT user FROM mysql.users LIMIT , 1 @param num: limit number @type num: C{int} @param query: query to be proces

(self, num, query, field=None, uniqueField=None)

Source from the content-addressed store, hash-verified

1010 return expression, limitCond, topLimit, startLimit, stopLimit
1011
1012 def limitQuery(self, num, query, field=None, uniqueField=None):
1013 """
1014 Take in input a query string and return its limited query string.
1015
1016 Example:
1017
1018 Input: SELECT user FROM mysql.users
1019 Output: SELECT user FROM mysql.users LIMIT <num>, 1
1020
1021 @param num: limit number
1022 @type num: C{int}
1023
1024 @param query: query to be processed
1025 @type query: C{str}
1026
1027 @param field: field within the query
1028 @type field: C{list}
1029
1030 @return: limited query string
1031 @rtype: C{str}
1032 """
1033
1034 if " FROM " not in query:
1035 return query
1036
1037 limitedQuery = query
1038 limitStr = queries[Backend.getIdentifiedDbms()].limit.query
1039 fromIndex = limitedQuery.index(" FROM ")
1040 untilFrom = limitedQuery[:fromIndex]
1041 fromFrom = limitedQuery[fromIndex + 1:]
1042 orderBy = None
1043
1044 if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL, DBMS.SQLITE, DBMS.VERTICA, DBMS.PRESTO, DBMS.MIMERSQL, DBMS.CUBRID, DBMS.EXTREMEDB, DBMS.DERBY):
1045 limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num, 1)
1046 limitedQuery += " %s" % limitStr
1047
1048 elif Backend.getIdentifiedDbms() in (DBMS.H2, DBMS.CRATEDB, DBMS.CLICKHOUSE):
1049 limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (1, num)
1050 limitedQuery += " %s" % limitStr
1051
1052 elif Backend.getIdentifiedDbms() in (DBMS.ALTIBASE,):
1053 limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num + 1, 1)
1054 limitedQuery += " %s" % limitStr
1055
1056 elif Backend.getIdentifiedDbms() in (DBMS.FRONTBASE, DBMS.VIRTUOSO):
1057 limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num, 1)
1058 if query.startswith("SELECT "):
1059 limitedQuery = query.replace("SELECT ", "SELECT %s " % limitStr, 1)
1060
1061 elif Backend.getIdentifiedDbms() in (DBMS.MONETDB,):
1062 if query.startswith("SELECT ") and field is not None and field in query:
1063 original = query.split("SELECT ", 1)[1].split(" FROM", 1)[0]
1064 for part in original.split(','):
1065 if re.search(r"\b%s\b" % re.escape(field), part):
1066 _ = re.sub(r"SELECT.+?FROM", "SELECT %s AS z,row_number() over() AS y FROM" % part, query, 1)
1067 replacement = "SELECT x.z FROM (%s)x WHERE x.y-1=%d" % (_, num)
1068 limitedQuery = replacement
1069 break

Callers 10

_goInferenceFieldsFunction · 0.80
xpCmdshellEvalCmdMethod · 0.80
unionThreadFunction · 0.80
_errorFieldsFunction · 0.80
getColumnsMethod · 0.80
searchDbMethod · 0.80
searchTableMethod · 0.80
searchColumnMethod · 0.80
searchTableMethod · 0.80
searchColumnMethod · 0.80

Calls 8

nullAndCastFieldMethod · 0.95
safeStringFormatFunction · 0.90
getIdentifiedDbmsMethod · 0.80
isDbmsMethod · 0.80
indexMethod · 0.45
replaceMethod · 0.45
searchMethod · 0.45
escapeMethod · 0.45

Tested by

no test coverage detected