summaryrefslogtreecommitdiff
path: root/backends/sqlcipher.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-01-24 14:23:40 -0200
committerdrebs <drebs@leap.se>2013-01-24 14:23:40 -0200
commit517ec48dee4e743a9f68622e14a7b56be6685881 (patch)
treed8014cf0dce168b8c758c3213dec4ddb3bec05f2 /backends/sqlcipher.py
parente07024c40a9cf74a2df2ba671b0fc677f3cbcc85 (diff)
Add syncable flag for LeapDocument.
Diffstat (limited to 'backends/sqlcipher.py')
-rw-r--r--backends/sqlcipher.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/backends/sqlcipher.py b/backends/sqlcipher.py
index 08b4df43..6cebcf7d 100644
--- a/backends/sqlcipher.py
+++ b/backends/sqlcipher.py
@@ -25,10 +25,11 @@ from u1db.backends.sqlite_backend import (
SQLitePartialExpandDatabase,
)
from u1db import (
- Document,
errors,
)
+from leap.soledad.backends.leap_backend import LeapDocument
+
def open(path, password, create=True, document_factory=None):
"""Open a database at the given location.
@@ -70,7 +71,7 @@ class SQLCipherDatabase(SQLitePartialExpandDatabase):
SQLCipherDatabase.set_pragma_key(self._db_handle, password)
self._real_replica_uid = None
self._ensure_schema()
- self._factory = document_factory or Document
+ self._factory = document_factory or LeapDocument
def _check_if_db_is_encrypted(self, sqlite_file):
if not os.path.exists(sqlite_file):
@@ -133,5 +134,26 @@ class SQLCipherDatabase(SQLitePartialExpandDatabase):
return Synchronizer(self, LeapSyncTarget(url, creds=creds),
soledad=self._soledad).sync(autocreate=autocreate)
+ def _extra_schema_init(self, c):
+ c.execute(
+ 'ALTER TABLE document '
+ 'ADD COLUMN syncable BOOL NOT NULL DEFAULT TRUE')
+
+ def _put_and_update_indexes(self, old_doc, doc):
+ super(SQLCipherDatabase, self)._put_and_update_indexes(old_doc, doc)
+ c = self._db_handle.cursor()
+ c.execute('UPDATE document SET syncable=? WHERE doc_id=?',
+ (doc.syncable, doc.doc_id))
+
+ def _get_doc(self, doc_id, check_for_conflicts=False):
+ doc = super(SQLCipherDatabase, self)._get_doc(doc_id,
+ check_for_conflicts)
+ if doc:
+ c = self._db_handle.cursor()
+ c.execute('SELECT syncable FROM document WHERE doc_id=?',
+ (doc.doc_id,))
+ doc.syncable = bool(c.fetchone()[0])
+ return doc
+
SQLiteDatabase.register_implementation(SQLCipherDatabase)