def main(sqlite_file, server_person_id): (db_mysql, cur_mysql) = dbs.connect_mysql() (db_sqlite, cur_sqlite) = dbs.connect_sqlite(sqlite_file) sqlite_tables = dbs.get_name_of_tables_sqlite(cur_sqlite) for table in sqlite_tables: results = cur_sqlite.execute("SELECT * FROM " + table) for row in results.fetchall(): insert = "INSERT INTO " + table + " VALUES( " + server_person_id + ", " str_row = [] for r in row: # TODO: fix, handle unicode characters if type(r) == unicode: r = r.encode('ascii', 'ignore') r = str(r).replace("'", '') str_row.append("'" + r + "'") insert += ",".join(str_row) insert += ")" cur_mysql.execute(insert) db_mysql.commit()
def main(): (db_mysql, cur_mysql) = dbs.connect_mysql() (db_sqlite, cur_sqlite) = dbs.connect_sqlite() drop_chronojump_table(db_mysql, cur_mysql) (db_mysql, cur_mysql) = dbs.connect_mysql() # Creates tables table_names = dbs.get_name_of_tables_sqlite(cur_sqlite) for table_name in table_names: sql_table = dbs.get_create_table(cur_sqlite, table_name) sql_table = add_person_id(sql_table) sql_table = fix_unique_id_primary_key(sql_table) cur_mysql.execute(sql_table)
def populates_sqlite_file(file_name, person_id): (db_mysql, cur_mysql) = dbs.connect_mysql() (db_sqlite, cur_sqlite) = dbs.connect_sqlite() name_of_tables = dbs.get_name_of_tables_mysql(cur_mysql) new_sqlite = sqlite3.connect(file_name) for name_of_table in name_of_tables: copy_data(cur_mysql, new_sqlite, person_id, name_of_table)
def create_sqlite_file(file_name): (conn, cursor) = dbs.connect_mysql() new_sqlite_cursor = sqlite3.connect(file_name) table_names = dbs.get_name_of_tables_mysql(cursor) for table_name in table_names: sql = dbs.get_create_table_mysql(cursor, table_name) new_sqlite_cursor.execute(sql)