Python pyodbc.ProgrammingError() Examples

The following are 17 code examples of pyodbc.ProgrammingError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyodbc , or try the search function .
Example #1
Source File: udf_sdk.py    From python-exasol with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUp(self):
        if sys.version_info[0:2] != expected_version:
            self.skipTest('createScript expects Python %s' % '.'.join(map(str, expected_version)))
        self.odbc_kwargs = {
                #'DSN':'EXtest_start_external_service_get_dataAODBC_TEST',
                'Driver': 'EXAODBC',
                'EXAHOST': os.environ['ODBC_HOST'],
                'EXAUID': os.environ['EXAUSER'],
                'EXAPWD': os.environ['EXAPW']
                }
        if 'ODBC_LOG' in os.environ:
            self.odbc_kwargs['LOGFILE'] = os.environ['ODBC_LOG']

        with pyodbc.connect(**self.odbc_kwargs) as con:
            try:
                con.cursor().execute('CREATE SCHEMA foo')
            except pyodbc.ProgrammingError:
                # schema FOO exists
                pass 
Example #2
Source File: exasol.py    From python-exasol with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _startOutputService(self):
        """Start service for EXASolution UDF scripts' output

        After the service is running, the createScript function
        produces additional code in scripts, which redirects the
        stdout and stderr of a stript to this service.

        The output of this service is the local stdout.

        """
        if not self._connected:
            raise pyodbc.ProgrammingError("Not connected")
        self._stopOutputService()
        self._outputService = ScriptOutputThread()
        self._outputService.fileObject = self.outputFileObject
        self._outputService.finished = False
        self._outputService.serverAddress = self.clientAddress
        self._outputService.init()
        self.clientAddress = self._outputService.serverAddress
        self._outputService.start() 
Example #3
Source File: connector.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
Example #4
Source File: connector.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
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" % getSafeExString(msg)) 
Example #5
Source File: connector.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
            return None 
Example #6
Source File: exasol.py    From python-exasol with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def close(self):
        """Closes the underlying pyodbc.Connection object and stops
        any implicitly started output service."""
        if not self._connected:
            raise pyodbc.ProgrammingError("Not connected")
        self._connected = False
        try:
            self.odbc.close()
        finally:
            self._stopOutputService() 
Example #7
Source File: exasol.py    From python-exasol with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __enter__(self):
        """Allows to use E.connect in "with" statements"""
        if not self._connected:
            raise pyodbc.ProgrammingError("Not connected")
        return self 
Example #8
Source File: connector.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
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]) 
Example #9
Source File: odbc.py    From script-languages with MIT License 5 votes vote down vote up
def query(self, qtext, *args):
        if self.cursor is None:
            raise ClientError('query() requires connect() first')
        q = self.cursor.execute(qtext, *args)
        try:
            return q.fetchall()
        except pyodbc.ProgrammingError as e:
            if 'No results.  Previous SQL was not a query.' in str(e):
                return None
            else:
                raise 
Example #10
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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]) 
Example #11
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
Example #12
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
Example #13
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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]) 
Example #14
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
Example #15
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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]) 
Example #16
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def fetchall(self):
        try:
            return self.cursor.fetchall()
        except pyodbc.ProgrammingError, msg:
            logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
            return None 
Example #17
Source File: exasol.py    From python-exasol with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def readData(self, sqlCommand, readCallback=None, **kw):
        """Execute a DQL statement and returns the result

        This is a optimized version of pyodbc.Connection.execute
        function. ReadData returns per default a pandas data frame
        or any other data, if a different readCallback was specified.

          readCallback
            A function, which is called with the file object contained
            the query result as CSV and all keyword arguments given to
            readData. The returned data will be returned from
            readData function.

        """
        if not self._connected:
            raise pyodbc.ProgrammingError("Not connected")
        if readCallback is None:
            if self.csvIsDefault:
                readCallback = csvReadCallback
            else:
                readCallback = pandasReadCallback
        odbc = self.odbc
        self.odbc = None  # during command execution is odbc not usable
        try:
            srv = TunneledTCPServer(self.serverAddress, HTTPIOHandler)
            srv.pipeInFd, srv.pipeOutFd = os.pipe()
            srv.outputMode = True
            srv.error, srv.pipeIn, srv.pipeOut = None, os.fdopen(srv.pipeInFd), os.fdopen(srv.pipeOutFd, 'w')
            s = HTTPIOServerThread()
            s.srv = srv
            srv.serverThread = s
            q = HTTPExportQueryThread()
            q.srv = srv
            srv.queryThread = q
            q.sqlCommand = sqlCommand
            q.odbc = odbc
            s.start()
            q.start()

            try:
                try:
                    ret = readCallback(s.srv.pipeIn, **kw)
                except Exception as err:
                    if srv.error is not None:
                        raise srv.error
                    raise err
            finally:
                srv.server_close()
                try:
                    srv.pipeIn.close()
                    srv.pipeOut.close()
                except:
                    pass
                q.join()
                s.join()
        finally:
            self.odbc = odbc
        if srv.error is not None:
            raise srv.error
        return ret