Skip to content

Commit

Permalink
Added recovery functions to SQL cache
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcarreras committed Aug 27, 2021
1 parent f5b657a commit 7ee2c76
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions pyqchem/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,57 @@ def integrity_check(self):

pass

def export(self, file):
def fix_database(self, file):

import subprocess, os

dump_file = self._calculation_data_filename + '.dump'
# dump_file = '_recovery.test'
print(dump_file)
schema = subprocess.run(
['sqlite3',
self._calculation_data_filename,
'.output {}'.format(dump_file),
'.dump',
],
capture_output=True
)

with open(dump_file, 'r') as f:
data = f.read().replace("ROLLBACK", "COMMIT")

with open(dump_file, 'w') as f:
f.write(data)

try:
os.remove(file)
except FileNotFoundError:
pass

schema = subprocess.run(
['sqlite3',
file,
'.read {}'.format(dump_file)
],
capture_output=True
)

os.remove(dump_file)

def _recovery_kill(self, file):

# cursor = self._conn.execute(".save ?", (file,))

import subprocess
schema = subprocess.run(
['sqlite3',
self._calculation_data_filename,
'.backup {}'.format(file)
'.recover'.format(file)
],
capture_output=True
)

# print(schema.stdout.decode('utf-8'))
print(schema.stdout)

def get_all_data(self):

Expand Down

0 comments on commit 7ee2c76

Please sign in to comment.