(self, sql, bindings=None, internal=False, summary=None)
Processes SQL text consisting of one or more statements

        :param sql: SQL to execute

        :param bindings: bindings for the *sql*

        :param internal: If True then this is an internal execution
          (eg the .tables or .database command).  When executing
          internal sql timings are not shown nor is the SQL echoed.

        :param summary: If not None then should be a tuple of two
          items.  If the ``sql`` returns any data then the first item
          is printed before the first row, and the second item is
          printed after the last row.  An example usage is the .find
          command which shows table names.
Processes SQL text consisting of one or more statements
Processes SQL text consisting of one or more statements
def process_sql(self, sql, bindings=None, internal=False, summary=None):
        """Processes SQL text consisting of one or more statements

        :param sql: SQL to execute

        :param bindings: bindings for the *sql*

        :param internal: If True then this is an internal execution
          (eg the .tables or .database command).  When executing
          internal sql timings are not shown nor is the SQL echoed.

        :param summary: If not None then should be a tuple of two
          items.  If the ``sql`` returns any data then the first item
          is printed before the first row, and the second item is
          printed after the last row.  An example usage is the .find
          command which shows table names.
        """
        cur = self.db.cursor()
        # we need to know when each new statement is executed
        state = {'newsql': True, 'timing': None}

        def et(cur, sql, bindings):
            state['newsql'] = True
            # if time reporting, do so now
            if not internal and self.timer:
                if state['timing']:
                    self.display_timing(state['timing'], self.get_resource_usage())
            # print statement if echo is on
            if not internal and self.echo:
                # ? should we strip leading and trailing whitespace? backslash quote stuff?
                if bindings:
                    self.write(self.stderr, "%s [%s]\n" % (sql, bindings))
                else:
                    self.write(self.stderr, sql + "\n")
            # save resource from beginning of command (ie don't include echo time above)
            if not internal and self.timer:
                state['timing'] = self.get_resource_usage()
            return True

        cur.setexectrace(et)
        # processing loop
        try:
            for row in cur.execute(sql, bindings):
                if state['newsql']:
                    # summary line?
                    if summary:
                        self._output_summary(summary[0])
                    # output a header always
                    cols = [h for h, d in cur.getdescription()]
                    self.output(True, cols)
                    state['newsql'] = False
                self.output(False, row)
            if not state['newsql'] and summary:
                self._output_summary(summary[1])
        except:
            # If echo is on and the sql to execute is a syntax error
            # then the exec tracer won't have seen it so it won't be
            # printed and the user will be wondering exactly what sql
            # had the error.  We look in the traceback and deduce if
            # the error was happening in a prepare or not.  Also we
            # need to ignore the case where SQLITE_SCHEMA happened and
            # a reprepare is being done since the exec tracer will
            # have been called in that situation.
            if not internal and self.echo:
                tb = sys.exc_info()[2]
                last = None
                while tb:
                    last = tb.tb_frame
                    tb = tb.tb_next

                if last and last.f_code.co_name=="sqlite3_prepare" \
                   and last.f_code.co_filename.endswith("statementcache.c") \
                   and "sql" in last.f_locals:
                    self.write(self.stderr, last.f_locals["sql"] + "\n")
            raise

        if not internal and self.timer:
            self.display_timing(state['timing'], self.get_resource_usage())
def process_sql ( self , sql , bindings = None , internal = False , summary = None ) : cur = self . db . cursor ( ) # we need to know when each new statement is executed state = { 'newsql' : True , 'timing' : None } def et ( cur , sql , bindings ) : state [ 'newsql' ] = True # if time reporting, do so now if not internal and self . timer : if state [ 'timing' ] : self . display_timing ( state [ 'timing' ] , self . get_resource_usage ( ) ) # print statement if echo is on if not internal and self . echo : # ? should we strip leading and trailing whitespace? backslash quote stuff? if bindings : self . write ( self . stderr , "%s [%s]\n" % ( sql , bindings ) ) else : self . write ( self . stderr , sql + "\n" ) # save resource from beginning of command (ie don't include echo time above) if not internal and self . timer : state [ 'timing' ] = self . get_resource_usage ( ) return True cur . setexectrace ( et ) # processing loop try : for row in cur . execute ( sql , bindings ) : if state [ 'newsql' ] : # summary line? if summary : self . _output_summary ( summary [ 0 ] ) # output a header always cols = [ h for h , d in cur . getdescription ( ) ] self . output ( True , cols ) state [ 'newsql' ] = False self . output ( False , row ) if not state [ 'newsql' ] and summary : self . _output_summary ( summary [ 1 ] ) except : # If echo is on and the sql to execute is a syntax error # then the exec tracer won't have seen it so it won't be # printed and the user will be wondering exactly what sql # had the error.  We look in the traceback and deduce if # the error was happening in a prepare or not.  Also we # need to ignore the case where SQLITE_SCHEMA happened and # a reprepare is being done since the exec tracer will # have been called in that situation. if not internal and self . echo : tb = sys . exc_info ( ) [ 2 ] last = None while tb : last = tb . tb_frame tb = tb . tb_next if last and last . f_code . co_name == "sqlite3_prepare" and last . f_code . co_filename . endswith ( "statementcache.c" ) and "sql" in last . f_locals : self . write ( self . stderr , last . f_locals [ "sql" ] + "\n" ) raise if not internal and self . timer : self . display_timing ( state [ 'timing' ] , self . get_resource_usage ( ) )