def do_update_table(self, txn, table, identity):

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

        key_cols_str = table.get_property('keycols')

        column_names = table.get_column_names()

        if key_cols_str == None:
            key_column_names = column_names
        else:
            key_column_names = string.split(key_cols_str, ';')

        tablename = table.get_tablename()
        index_name = tablename + "_unique_index_" + '_'.join(key_column_names)

        create_index_sql = "CREATE UNIQUE INDEX IF NOT EXISTS %s ON %s (%s)" % (index_name, tablename, ', '.join(key_column_names))
        #logging.info("DEBUG: would execute: %s", create_index_sql)

        try:
            txn.execute(create_index_sql)

        except Exception as e:
            logging.info("ERROR: Failed to create unique index for table update: '%s': ( %s )", str(e), create_index_sql)

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

        sql = "INSERT OR REPLACE INTO %s (%s) VALUES (%s)" % (tablename, ', '.join(column_names), ', '.join([ '?' for x in column_names ]) )

        rowcount = 0

        for row in table.get_rows():

            #logging.info("DEBUG: would execute: %s with %s", sql, row)
            txn.execute(sql, row)

            rowcount += txn.getconnection().changes()

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

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