How to use the apsw.ExecutionCompleteError function in apsw

To help you get started, we’ve selected a few apsw 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 openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / mterm.py View on Github external
readline.add_history(histstatement.encode('utf-8'))
        except:
            pass

        before = datetime.datetime.now()
        try:
            if queryplan:
                cexec = connection.queryplan(statement)
                desc = cexec.next()
            else:
                cursor = connection.cursor()
                cexec = cursor.execute(statement)
                try:
                    desc = cursor.getdescriptionsafe()
                    lastcols[0:len(desc)] = [x for x, y in desc]
                except apsw.ExecutionCompleteError, e:
                    desc = []

            newcols=[x for x,y in desc]

            colorama.init()
            rownum=0

            if not pipedinput:
                for row in cexec:
                    printrow(row)
                    rownum+=1
            else:
                print(json.dumps({"schema":desc}, separators=(',',':'), ensure_ascii=False).encode('utf_8', 'replace'))
                for row in cexec:
                    print(json.dumps(row, separators=(',',':'), ensure_ascii=False).encode('utf_8', 'replace'))
                    if nobuf:
github dbilid / PARJ / exareme-tools / madis / src / functions / vtable / wcache.py View on Github external
def getnewcursor(self):
        if self.keepcursor:
            self.keepcursor = False
            return self.q
        try:
            return self.envarsdb.cursor().execute(self.query)
        except apsw.ExecutionCompleteError:
            raise functions.DynamicSchemaWithEmptyResultError(__name__.rsplit('.')[-1])
github Cog-Creators / Red-DiscordBot / redbot / cogs / audio / databases.py View on Github external
from .utils import PlaylistScope

log = logging.getLogger("red.audio.database")

if TYPE_CHECKING:
    database_connection: apsw.Connection
    _bot: Red
    _config: Config
else:
    _config = None
    _bot = None
    database_connection = None


SCHEMA_VERSION = 3
SQLError = apsw.ExecutionCompleteError


_PARSER: Mapping = {
    "youtube": {
        "insert": YOUTUBE_UPSERT,
        "youtube_url": {"query": YOUTUBE_QUERY},
        "update": YOUTUBE_UPDATE,
    },
    "spotify": {
        "insert": SPOTIFY_UPSERT,
        "track_info": {"query": SPOTIFY_QUERY},
        "update": SPOTIFY_UPDATE,
    },
    "lavalink": {
        "insert": LAVALINK_UPSERT,
        "data": {"query": LAVALINK_QUERY, "played": LAVALINK_QUERY_LAST_FETCHED_RANDOM},
github probcomp / bayeslite / src / bql.py View on Github external
def __init__(self, bdb, cursor):
        self._bdb = bdb
        self._cursor = cursor
        # XXX Must save the description early because apsw discards it
        # after we have iterated over all rows -- or if there are no
        # rows, discards it immediately!
        try:
            self._description = cursor.description
        except apsw.ExecutionCompleteError:
            self._description = []
        else:
            assert self._description is not None
            if self._description is None:
                self._description = []
    def __iter__(self):
github MediaMath / qasino / lib / sqlite_backend.py View on Github external
max_widths = {}

        # Get the column names.

        column_names = []

        try:
            for column_index, column_name in enumerate(txn.getdescription()):

                if not max_widths.has_key(str(column_index)) or max_widths[str(column_index)] < len(column_name[0]):
                    max_widths[str(column_index)] = len(column_name[0])
            
                column_names.append(column_name[0])

        except apsw.ExecutionCompleteError as e:
            # Ugh, getdescription fails if the query succeeds but returns no rows!  This is the message:
            #    "Can't get description for statements that have completed execution"

            # For now return a zero row empty table:

            data = { "column_names" : [ "query returned zero rows" ], "rows" : [ ] }

            return { "retval" : 0, "error_message" : '', "data" : data, "max_widths" : { "0" : 24 } }

        # Save the data here:

        saved_rows = []
        nr_rows = 0

        # For each row.
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / functions / __init__.py View on Github external
functions = {'row': {}, 'aggregate': {}, 'vtable': {}}
multiset_functions = {}
iterheader = 'ITER'+chr(30)

variables = lambda _: _
variables.flowname = ''
variables.execdb = None
variables.filename = ''

privatevars=lambda _: _

rowfuncs=lambda _: _

oldexecdb=-1

ExecutionCompleteError = apsw.ExecutionCompleteError

def getvar(name):
    return variables.__dict__[name]

def setvar(name, value):
    variables.__dict__[name] = value

def mstr(s):
    if s==None:
        return None

    try:
        return unicode(s, 'utf-8', errors='replace')
    except KeyboardInterrupt:
        raise
    except:
github probcomp / bayeslite / src / sessions.py View on Github external
SELECT version FROM bayesdb_session
                WHERE id = ?
        ''', (session_id,)))
        cursor = self._sql('''
            SELECT * FROM bayesdb_session_entries
                WHERE session_id = ?
                ORDER BY start_time DESC
        ''', (session_id,))
        # XXX Get the description first because apsw cursors, for
        # whatever reason, don't let you get the description after
        # you've gotten all the results.
        # (see also bql.py BayesDBCursor.__init__)
        fields = []
        try:
            fields = [d[0] for d in cursor.description]
        except apsw.ExecutionCompleteError:
            pass # Probably no rows.
        entries = cursor.fetchall()
        session = {
            'entries': entries,
            'fields': fields,
            'version': version,
        }
        return json.dumps(session, sort_keys=True)
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / functions / __init__.py View on Github external
import locale
    from lib import pptable
    global test_connection
    
    language, output_encoding = locale.getdefaultlocale()

    if output_encoding==None:
        output_encoding="UTF8"

    test_cursor=test_connection.cursor()
        
    e=test_cursor.execute(sqlquery.decode(output_encoding))
    try:
        desc=test_cursor.getdescription()
        print pptable.indent([[x[0] for x in desc]]+[x for x in e], hasHeader=True),
    except apsw.ExecutionCompleteError:
        print '',
    test_cursor.close()
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / functions / __init__.py View on Github external
def getdescriptionsafe(self):
        try:
            # Try to get the schema the normal way
            schema = self.__wrapped.getdescription()
        except apsw.ExecutionCompleteError:
            # Else create a tempview and query the view
            if not self.__query.strip().lower().startswith('select'):
                raise apsw.ExecutionCompleteError
            try:
                list(self.executetrace('create temp view temp.___schemaview as '+ self.__query + ';'))
                schema = [(x[1], x[2]) for x in list(self.executetrace('pragma table_info(___schemaview);'))]
                list(self.executetrace('drop view temp.___schemaview;'))
            except Exception, e:
                raise apsw.ExecutionCompleteError
            
        return schema