def do_insert_table(self, txn, table):
        """
        Insert table into the backend.  Use multi-row insert
        statements (supported in sqlite 3.7.11) for speed.
        """
        
        self.stats['inserts_received'] = self.stats.get('inserts_received', 0) + 1

        rowcount = 0

        base_query = "INSERT INTO %s (%s) VALUES " % (table.get_tablename(), ",".join( table.get_column_names() ) )

        nr_columns = len(table.get_column_names())
        max_nr_values = 400  # supposedly the max is 500..

        nr_values = 0
        bind_values = []

        one_row = '({})'.format(','.join(['?'] * nr_columns))

        sql = base_query

        for row_index, row in enumerate(table.get_rows()):

            if nr_values + nr_columns > max_nr_values:

                # execute this batch and start again.

                sql += ','.join([ one_row ] * (nr_values / nr_columns))

                #logging.info("DEBUG: hit limit: executing (values %d, rows %d): %s", nr_values, rowcount, sql)

                txn.execute(sql, bind_values)
                bind_values = []
                nr_values = 0
                sql = base_query

            nr_values += nr_columns

            # add this row to our bind values

            for value in row:
                bind_values.append(value)

            rowcount += 1

        # handle last batch
        if rowcount > 0:
            sql += ','.join([ one_row ] * (nr_values / nr_columns))

            #logging.info("DEBUG: final: executing (values %d, rows %d): %s", nr_values, rowcount, sql)

            txn.execute(sql, bind_values)

        self.stats['inserts_completed'] = self.stats.get('inserts_completed', 0) + 1

        return rowcount
dataset/ETHPy150Open MediaMath/qasino/lib/sqlite_backend.py/SqlConnections.do_insert_table/original