Exemple #1
0
    def execute(self,
                statements,
                bindings=None,
                parse=True,
                localbindings=None):  # overload execute statement
        if localbindings != None:
            bindings = localbindings
        else:
            if bindings == None:
                bindings = variables.__dict__
            else:
                if type(bindings) is dict:
                    bindings.update(variables.__dict__)

        if not parse:
            self.__query = statements
            return self.executetrace(statements, bindings)

        svts = sqltransform.transform(statements,
                                      multiset_functions.keys(),
                                      functions['vtable'],
                                      functions['row'].keys(),
                                      substitute=functions['row']['subst'])
        s = svts[0]
        try:
            if self.__vtables != []:
                self.executetrace(''.join([
                    'drop table ' + 'temp.' + x + ';'
                    for x in reversed(self.__vtables)
                ]))
                self.__vtables = []
            for i in svts[1]:
                createvirtualsql = None
                if re.match(r'\s*$', i[2]) is None:
                    sep = ','
                else:
                    sep = ''
                createvirtualsql = VTCREATE + i[0] + ' using ' + i[
                    1] + "(" + i[2] + sep + "'automatic_vtable:1'" + ")"
                try:
                    self.executetrace(createvirtualsql)
                except Exception, e:
                    strex = mstr(e)
                    if SQLITEAFTER3711 or type(
                            e) != apsw.SQLError or strex.find(
                                'already exists') == -1 or strex.find(
                                    i[0]) == -1:
                        raise e, None, sys.exc_info()[2]
                    else:
                        self.__permanentvtables[i[0]] = createvirtualsql

                if len(i) == 4:
                    self.__permanentvtables[i[0]] = createvirtualsql
                else:
                    self.__vtables.append(i[0])
            self.__query = s
            return self.executetrace(s, bindings)
Exemple #2
0
    def execute(self, statements, bindings=None, parse=True, localbindings=None):  # overload execute statement
        if localbindings != None:
            bindings = localbindings
        else:
            if bindings == None:
                bindings = variables.__dict__
            else:
                if type(bindings) is dict:
                    bindings.update(variables.__dict__)

        if not parse:
            self.__query = statements
            return self.executetrace(statements, bindings)

        svts = sqltransform.transform(statements, multiset_functions.keys(), functions['vtable'],
                                      functions['row'].keys(), substitute=functions['row']['subst'])
        s = svts[0]
        try:
            if self.__vtables != []:
                self.executetrace(''.join(['drop table ' + 'temp.' + x + ';' for x in reversed(self.__vtables)]))
                self.__vtables = []
            for i in svts[1]:
                createvirtualsql = None
                if re.match(r'\s*$', i[2]) is None:
                    sep = ','
                else:
                    sep = ''
                createvirtualsql = VTCREATE + i[0] + ' using ' + i[1] + "(" + i[2] + sep + "'automatic_vtable:1'" + ")"
                try:
                    self.executetrace(createvirtualsql)
                except Exception, e:
                    strex = mstr(e)
                    if SQLITEAFTER3711 or type(e) != apsw.SQLError or strex.find('already exists') == -1 or strex.find(
                            i[0]) == -1:
                        raise e, None, sys.exc_info()[2]
                    else:
                        self.__permanentvtables[i[0]] = createvirtualsql

                if len(i) == 4:
                    self.__permanentvtables[i[0]] = createvirtualsql
                else:
                    self.__vtables.append(i[0])
            self.__query = s
            return self.executetrace(s, bindings)
Exemple #3
0
    def execute(self,
                statements,
                bindings=None,
                parse=True,
                localbindings=None):  # overload execute statement
        if localbindings != None:
            bindings = localbindings
        else:
            if bindings == None:
                bindings = variables.__dict__
            else:
                if type(bindings) is dict:
                    bindings.update(variables.__dict__)

        if not parse:
            self.__query = statements
            return self.executetrace(statements, bindings)

        # simple hack to run .schema command from here - just for hbp
        if ".schema" in statements:
            arg = statements.split()[1]
            argument = arg.rstrip('; ')

            db = 'main'
            if '.' in arg:
                sa = argument.split('.')
                db = sa[0]
                argument = ''.join(sa[1:])
            q = "select sql from (select * from " + db + ".sqlite_master union all select * from sqlite_temp_master) where tbl_name like '%s' and sql is not null;" % argument
            return self.executetrace(q)
        # end of hbp update

        svts = sqltransform.transform(statements,
                                      multiset_functions.keys(),
                                      functions['vtable'],
                                      functions['row'].keys(),
                                      substitute=functions['row']['subst'])
        s = svts[0]
        try:
            if self.__vtables != []:
                self.executetrace(''.join([
                    'drop table ' + 'temp.' + x + ';'
                    for x in reversed(self.__vtables)
                ]))
                self.__vtables = []
            for i in svts[1]:
                createvirtualsql = None
                if re.match(r'\s*$', i[2]) is None:
                    sep = ','
                else:
                    sep = ''
                createvirtualsql = VTCREATE + i[0] + ' using ' + i[
                    1] + "(" + i[2] + sep + "'automatic_vtable:1'" + ")"
                try:
                    self.executetrace(createvirtualsql)
                except Exception, e:
                    strex = mstr(e)
                    if SQLITEAFTER3711 or type(
                            e) != apsw.SQLError or strex.find(
                                'already exists') == -1 or strex.find(
                                    i[0]) == -1:
                        raise e, None, sys.exc_info()[2]
                    else:
                        self.__permanentvtables[i[0]] = createvirtualsql

                if len(i) == 4:
                    self.__permanentvtables[i[0]] = createvirtualsql
                else:
                    self.__vtables.append(i[0])
            self.__query = s
            return self.executetrace(s, bindings)