How to use the pymssql.ProgrammingError function in pymssql

To help you get started, we’ve selected a few pymssql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pymssql / pymssql / tests / test_pymssql.py View on Github external
def test_rollback_after_create_error(self):
        """
            test_rollback_after_create_error

            For some reason, SQL server will issue a batch-abort
            if the statement is a CREATE statement and it fails.  This means
            the transaction is implicitly rolled back and a subsequent call to
            rollback() without special handling would result in an error.
        """
        cur = self.conn.cursor()
        cur.execute('insert into users values (%s)', 'foobar')
        eq_(self.row_count(), 1)
        try:
            cur.execute("CREATE TABLE badschema.t1 ( test1 CHAR(5) NOT NULL)")
        except pym.ProgrammingError as e:
            if 'badschema' not in str(e):
                raise
            # encountered an error, so we want to rollback
            self.conn.rollback()
        # rollback should have resulted in user's insert getting rolled back
        # too
        eq_(self.row_count(), 0)
github sqlmapproject / sqlmap / plugins / dbms / mssqlserver / connector.py View on Github external
def execute(self, query):
        retVal = False

        try:
            self.cursor.execute(getText(query))
            retVal = True
        except (pymssql.OperationalError, pymssql.ProgrammingError) as ex:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
        except pymssql.InternalError as ex:
            raise SqlmapConnectionException(getSafeExString(ex))

        return retVal
github Azure / azure-cli-extensions / src / db-up / azext_db_up / custom.py View on Github external
def _run_sql_commands(host, user, password, database):
    # Connect to sql and get cursor to run sql commands
    _ensure_pymssql()
    import pymssql
    with pymssql.connect(host, user, password, database, tds_version='7.0') as connection:
        logger.warning('Successfully Connected to PostgreSQL.')
        with connection.cursor() as cursor:
            try:
                db_password = _create_db_password(database)
                cursor.execute("CREATE USER root WITH PASSWORD = '{}'".format(db_password))
                logger.warning("Ran Database Query: `CREATE USER root WITH PASSWORD = '%s'`", db_password)
            except pymssql.ProgrammingError:
                pass
            cursor.execute("Use {};".format(database))
            cursor.execute("GRANT ALL to root")
            logger.warning("Ran Database Query: `GRANT ALL TO root`")
github insightfinder / InsightAgent / mssql / getmessages_mssql.py View on Github external
def query_messages_mssql(cursor, sql_str):
    try:
        logger.info('Starting execute SQL')
        logger.info(sql_str)

        # execute sql string
        cursor.execute(sql_str)

        parse_messages_mssql(cursor)
    except ProgrammingError as e:
        logger.error(e)
        logger.error('SQL execute error: '.format(sql_str))
github sqlmapproject / sqlmap / plugins / dbms / sybase / connector.py View on Github external
def execute(self, query):
        retVal = False

        try:
            self.cursor.execute(getText(query))
            retVal = True
        except (pymssql.OperationalError, pymssql.ProgrammingError) as ex:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
        except pymssql.InternalError as ex:
            raise SqlmapConnectionException(getSafeExString(ex))

        return retVal
github cr0hn / golismero-legacy / tools / sqlmap / plugins / dbms / sybase / connector.py View on Github external
def execute(self, query):
        retVal = False

        try:
            self.cursor.execute(utf8encode(query))
            retVal = True
        except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
        except pymssql.InternalError, msg:
            raise SqlmapConnectionException(msg)

        return retVal
github WhitewidowScanner / whitewidow / lib / modules / core / tools / thirdparty / sqlmap / plugins / dbms / sybase / connector.py View on Github external
def execute(self, query):
        retVal = False

        try:
            self.cursor.execute(utf8encode(query))
            retVal = True
        except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
        except pymssql.InternalError, msg:
            raise SqlmapConnectionException(msg)

        return retVal
github cr0hn / golismero-legacy / tools / sqlmap / plugins / dbms / mssqlserver / connector.py View on Github external
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except (pymssql.ProgrammingError, pymssql.OperationalError, _mssql.MssqlDatabaseException), msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
            return None