Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_execute_on_closed_cursor(conn):
cur = await conn.cursor()
await cur.close()
with pytest.raises(pyodbc.OperationalError):
await cur.execute('SELECT 1;')
def execute(self, query):
try:
self.cursor.execute(query)
except (pyodbc.OperationalError, pyodbc.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
except pyodbc.Error, msg:
raise SqlmapConnectionException(msg[1])
self.connector.commit()
def __init__(self, uri, schema):
DBConnector.__init__(self, uri, schema)
try:
self.conn = pyodbc.connect(uri)
except (ProgrammingError, InterfaceError, pyodbc.Error, pyodbc.OperationalError) as e:
raise DBConnectorError(str(e), e)
self.schema = schema
self._bMetadataTable = self._metadata_exists()
self.iliCodeName = 'iliCode'
self.tid = 'T_Id'
self.dispName = 'dispName'
def connect(self):
if not IS_WIN:
errMsg = "currently, direct connection to Microsoft Access database(s) "
errMsg += "is restricted to Windows platforms"
raise SqlmapUnsupportedFeatureException(errMsg)
self.initConnection()
self.checkFileDb()
try:
self.connector = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb)};Dbq=%s;Uid=Admin;Pwd=;' % self.db)
except (pyodbc.Error, pyodbc.OperationalError) as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
async def _run_operation(self, func, *args, **kwargs):
# execute func in thread pool of attached to cursor connection
if not self._conn:
raise pyodbc.OperationalError('Cursor is closed.')
try:
result = await self._conn._execute(func, *args, **kwargs)
return result
except pyodbc.Error as e:
if self._conn and _is_conn_close_error(e):
await self._conn.close()
raise
def should_reconnect(provider, exc):
return isinstance(exc, pyodbc.OperationalError)
def connect(self):
if not IS_WIN:
errMsg = "currently, direct connection to Microsoft Access database(s) "
errMsg += "is restricted to Windows platforms"
raise SqlmapUnsupportedFeatureException(errMsg)
self.initConnection()
self.checkFileDb()
try:
self.connector = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb)};Dbq=%s;Uid=Admin;Pwd=;' % self.db)
except (pyodbc.Error, pyodbc.OperationalError), msg:
raise SqlmapConnectionException(msg[1])
self.initCursor()
self.printConnected()
oracleConnect = cx_Oracle.connect
oracleDatabaseError = cx_Oracle.DatabaseError
oracleInterfaceError = cx_Oracle.InterfaceError
oracleNCLOB = cx_Oracle.NCLOB
except ImportError:
# also requires "Oracle Instant Client"
hasOracle = False
oracleConnect = noop
oracleDatabaseError = oracleInterfaceError = NoopException
oracleCLOB = None
try:
import pyodbc
hasMSSql = True
mssqlConnect = pyodbc.connect
mssqlOperationalError = pyodbc.OperationalError
mssqlProgrammingError = pyodbc.ProgrammingError
mssqlInterfaceError = pyodbc.InterfaceError
mssqlInternalError = pyodbc.InternalError
mssqlDataError = pyodbc.DataError
mssqlIntegrityError = pyodbc.IntegrityError
except ImportError:
hasMSSql = False
mssqlConnect = noop
mssqlOperationalError = mssqlProgrammingError = mssqlInterfaceError = mssqlInternalError = \
mssqlDataError = mssqlIntegrityError = NoopException
try:
import sqlite3
hasSQLite = True
sqliteConnect = sqlite3.connect
sqliteParseDecltypes = sqlite3.PARSE_DECLTYPES