def dump_sqlite_memdb(self, con, db_name): temp_file = utilities.stringio() for line in con.iterdump(): temp_file.write(line+'\n') temp_file.seek(0) # Create a database in a file and import from tempfile mem_db = utilities.sqlite.connect(db_name) mem_db.cursor().executescript(temp_file.read()) mem_db.commit() mem_db.close() return con
def init_sqlite_db(db_name): # Read database to tempfile con = sqlite3.connect(db_name) temp_file = utilities.stringio() for line in con.iterdump(): temp_file.write('%s\n' % line) con.close() temp_file.seek(0) # Create a database in memory and import from tempfile mem_db = sqlite3.connect(":memory:") mem_db.cursor().executescript(temp_file.read()) mem_db.commit() return mem_db
def load_sqlite_memdb(self, db_name): # Read database to tempfile con = utilities.sqlite.connect(db_name) temp_file = utilities.stringio() for line in con.iterdump(): temp_file.write(line+'\n') temp_file.seek(0) con.close() # Create a database in memory and import from tempfile mem_db = utilities.sqlite.connect(":memory:") mem_db.cursor().executescript(temp_file.read()) mem_db.commit() mem_db_cursor = mem_db.cursor() return mem_db, mem_db_cursor