~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: use cipher_* vs cipher_default_* pragmas for open vs create
LearningCircuit5e7e82fc4505
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.pyindex aded55ecbe..0173902883 100644--- a/src/local_deep_research/database/encrypted_db.py+++ b/src/local_deep_research/database/encrypted_db.py@@ -91,7 +91,8 @@ class DatabaseManager:# Use cursor for consistent behavior (same as create_sqlcipher_connection)cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key- apply_cipher_settings_before_key(cursor)+ # Use creation_mode=True since we're creating a new test database+ apply_cipher_settings_before_key(cursor, creation_mode=True)# Use centralized key settingset_sqlcipher_key(cursor, "testpass")cursor.close()@@ -225,7 +226,8 @@ class DatabaseManager:cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key- apply_cipher_settings_before_key(cursor)+ # Use creation_mode=True since we're creating a new database+ apply_cipher_settings_before_key(cursor, creation_mode=True)# Use centralized SQLCipher setupset_sqlcipher_key(cursor, password)apply_sqlcipher_pragmas(cursor, creation_mode=True)@@ -278,7 +280,8 @@ class DatabaseManager:cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key- apply_cipher_settings_before_key(cursor)+ # Use creation_mode=False since we're opening an existing database+ apply_cipher_settings_before_key(cursor, creation_mode=False)# Use centralized SQLCipher setupset_sqlcipher_key(cursor, password)@@ -389,11 +392,14 @@ class DatabaseManager:cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key+ # Use creation_mode=False since we're opening an existing databaselogger.debug("[SQLCIPHER DEBUG] open_user_database: Calling apply_cipher_settings_before_key")try:- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(+ cursor, creation_mode=False+ )except Exception as e:logger.exception(f"[SQLCIPHER DEBUG] open_user_database: apply_cipher_settings_before_key failed: {e}"@@ -719,7 +725,10 @@ class DatabaseManager:cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key- apply_cipher_settings_before_key(cursor)+ # Use creation_mode=False since we're opening an existing database+ apply_cipher_settings_before_key(+ cursor, creation_mode=False+ )# Use centralized SQLCipher setupset_sqlcipher_key(cursor, password)diff --git a/src/local_deep_research/database/sqlcipher_utils.py b/src/local_deep_research/database/sqlcipher_utils.pyindex b68d5758d7..fff03a7095 100644--- a/src/local_deep_research/database/sqlcipher_utils.py+++ b/src/local_deep_research/database/sqlcipher_utils.py@@ -150,47 +150,61 @@ def get_sqlcipher_settings(username: Optional[str] = None) -> dict:def apply_cipher_settings_before_key(cursor_or_conn: Any,+ creation_mode: bool = False,username: Optional[str] = None,) -> None:"""Apply SQLCipher cipher settings that MUST be set BEFORE the key.- In SQLCipher 4.x, cipher_default_* pragmas must be set BEFORE PRAGMA key+ In SQLCipher 4.x, cipher settings must be set BEFORE PRAGMA keyis executed. This function should be called immediately after connection,before set_sqlcipher_key().- Note: In SQLCipher 4.6+ Community Edition, use cipher_default_page_size- instead of cipher_page_size for new databases.+ IMPORTANT: For SQLCipher 4.x:+ - When CREATING a new database: use cipher_default_* pragmas+ - When OPENING an existing database: use cipher_* pragmas (without _default_)Args:cursor_or_conn: SQLCipher cursor or connection object+ creation_mode: If True, use cipher_default_* for new databases.+ If False, use cipher_* for opening existing databases.username: Username to get settings for (if available)"""settings = get_sqlcipher_settings(username)logger.debug(- f"[SQLCIPHER DEBUG] apply_cipher_settings (pre-pragma): settings={settings}"+ f"[SQLCIPHER DEBUG] apply_cipher_settings (pre-pragma): "+ f"creation_mode={creation_mode}, settings={settings}")# These MUST be set BEFORE the key for SQLCipher 4.x compatibility- # Use cipher_default_* pragmas for SQLCipher 4.6+ Community Edition+ # Use cipher_default_* for new databases, cipher_* for existing databases+ if creation_mode:+ # For new databases: cipher_default_* sets the defaults that apply+ # when the key is set on a new database+ pragma_prefix = "cipher_default_"+ else:+ # For existing databases: cipher_* sets the cipher settings needed+ # to decrypt the database+ pragma_prefix = "cipher_"+logger.debug(- f"[SQLCIPHER DEBUG] Setting cipher_default_page_size = {settings['page_size']}"+ f"[SQLCIPHER DEBUG] Setting {pragma_prefix}page_size = {settings['page_size']}")cursor_or_conn.execute(- f"PRAGMA cipher_default_page_size = {settings['page_size']}"+ f"PRAGMA {pragma_prefix}page_size = {settings['page_size']}")logger.debug(- f"[SQLCIPHER DEBUG] Setting cipher_default_hmac_algorithm = {settings['hmac_algorithm']}"+ f"[SQLCIPHER DEBUG] Setting {pragma_prefix}hmac_algorithm = {settings['hmac_algorithm']}")cursor_or_conn.execute(- f"PRAGMA cipher_default_hmac_algorithm = {settings['hmac_algorithm']}"+ f"PRAGMA {pragma_prefix}hmac_algorithm = {settings['hmac_algorithm']}")logger.debug(- f"[SQLCIPHER DEBUG] Setting cipher_default_kdf_algorithm = {settings['kdf_algorithm']}"+ f"[SQLCIPHER DEBUG] Setting {pragma_prefix}kdf_algorithm = {settings['kdf_algorithm']}")cursor_or_conn.execute(- f"PRAGMA cipher_default_kdf_algorithm = {settings['kdf_algorithm']}"+ f"PRAGMA {pragma_prefix}kdf_algorithm = {settings['kdf_algorithm']}")logger.debug("[SQLCIPHER DEBUG] apply_cipher_settings (pre-pragma): completed successfully"@@ -326,7 +340,8 @@ def create_sqlcipher_connection(db_path: str, password: str) -> Any:cursor = conn.cursor()# IMPORTANT: For SQLCipher 4.x, cipher settings MUST be set BEFORE the key- apply_cipher_settings_before_key(cursor)+ # Use creation_mode=False since this opens an existing database+ apply_cipher_settings_before_key(cursor, creation_mode=False)# Set encryption keyset_sqlcipher_key(cursor, password)diff --git a/tests/auth_tests/test_encrypted_db.py b/tests/auth_tests/test_encrypted_db.pyindex 65cc6639d1..661528c5e7 100644--- a/tests/auth_tests/test_encrypted_db.py+++ b/tests/auth_tests/test_encrypted_db.py@@ -259,7 +259,8 @@ class TestConnectionVerification:sqlcipher = get_sqlcipher_module()conn = sqlcipher.connect(str(db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor, creation_mode=False)set_sqlcipher_key(cursor, "testpassword123")assert verify_sqlcipher_connection(cursor) is True@@ -285,7 +286,8 @@ class TestConnectionVerification:sqlcipher = get_sqlcipher_module()conn = sqlcipher.connect(str(db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor, creation_mode=False)set_sqlcipher_key(cursor, "wrongpassword")cursor.close()diff --git a/tests/auth_tests/test_sqlcipher_backwards_compat.py b/tests/auth_tests/test_sqlcipher_backwards_compat.pyindex 092ddbb02b..5213aa0fd5 100644--- a/tests/auth_tests/test_sqlcipher_backwards_compat.py+++ b/tests/auth_tests/test_sqlcipher_backwards_compat.py@@ -40,11 +40,13 @@ def sqlcipher_module():def create_configured_connection(sqlcipher_module, db_path, password):"""Helper to create a properly configured connection."""+ # Detect if we're creating a new database or opening an existing one+ creation_mode = not db_path.exists()conn = sqlcipher_module.connect(str(db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=creation_mode)set_sqlcipher_key(cursor, password)- apply_sqlcipher_pragmas(cursor)+ apply_sqlcipher_pragmas(cursor, creation_mode=creation_mode)apply_performance_pragmas(cursor)cursor.close()return conndiff --git a/tests/auth_tests/test_sqlcipher_compatibility.py b/tests/auth_tests/test_sqlcipher_compatibility.pyindex 826b1e29cf..00a3d143f6 100644--- a/tests/auth_tests/test_sqlcipher_compatibility.py+++ b/tests/auth_tests/test_sqlcipher_compatibility.py@@ -87,7 +87,7 @@ class TestSQLCipher46Compatibility:cursor = conn.cursor()# Apply cipher settings BEFORE key (SQLCipher 4.6+ requirement)- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")cursor.close()@@ -110,7 +110,7 @@ class TestSQLCipher46Compatibility:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")cursor.close()@@ -132,7 +132,7 @@ class TestSQLCipher46Compatibility:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")cursor.close()@@ -154,7 +154,7 @@ class TestSQLCipher46Compatibility:cursor = conn.cursor()# Correct order: cipher settings BEFORE key- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")# Should be able to create tables and query@@ -183,7 +183,7 @@ class TestSQLCipher46Compatibility:cursor = conn.cursor()# Correct order- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_sqlcipher_pragmas(cursor, creation_mode=True)cursor.close()diff --git a/tests/auth_tests/test_sqlcipher_key_derivation.py b/tests/auth_tests/test_sqlcipher_key_derivation.pyindex d7434cae64..af2e6a2a82 100644--- a/tests/auth_tests/test_sqlcipher_key_derivation.py+++ b/tests/auth_tests/test_sqlcipher_key_derivation.py@@ -184,7 +184,8 @@ class TestKeyDerivationWithDatabase:# Create databaseconn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, password)cursor.close()@@ -196,7 +197,8 @@ class TestKeyDerivationWithDatabase:# Reopen with same passwordconn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, password)cursor2.close()@@ -213,7 +215,8 @@ class TestKeyDerivationWithDatabase:# Create database with password1conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "password1")cursor.close()@@ -224,7 +227,8 @@ class TestKeyDerivationWithDatabase:# Try to open with password2conn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, "password2")cursor2.close()@@ -243,7 +247,8 @@ class TestKeyDerivationWithDatabase:# Create databaseconn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "original_password")cursor.close()@@ -258,7 +263,8 @@ class TestKeyDerivationWithDatabase:# Open with new password using set_sqlcipher_keyconn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, "new_password")cursor2.close()@@ -270,7 +276,8 @@ class TestKeyDerivationWithDatabase:# Original password should no longer workconn3 = sqlcipher_module.connect(str(temp_db_path))cursor3 = conn3.cursor()- apply_cipher_settings_before_key(cursor3)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor3, creation_mode=False)set_sqlcipher_key(cursor3, "original_password")cursor3.close()diff --git a/tests/auth_tests/test_sqlcipher_performance.py b/tests/auth_tests/test_sqlcipher_performance.pyindex c883cdf7e3..6197fa1fce 100644--- a/tests/auth_tests/test_sqlcipher_performance.py+++ b/tests/auth_tests/test_sqlcipher_performance.py@@ -41,7 +41,8 @@ def configured_connection(sqlcipher_module, temp_db_path):"""Create a fully configured database connection."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -62,7 +63,8 @@ class TestWALMode:"""Verify WAL mode creates -wal and -shm files."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -84,7 +86,8 @@ class TestWALMode:# Create and populate databaseconn1 = sqlcipher_module.connect(str(temp_db_path))cursor1 = conn1.cursor()- apply_cipher_settings_before_key(cursor1)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor1, creation_mode=True)set_sqlcipher_key(cursor1, "testpassword")apply_performance_pragmas(cursor1)cursor1.close()@@ -96,7 +99,8 @@ class TestWALMode:# Open second read connection while first is openconn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, "testpassword")apply_performance_pragmas(cursor2)cursor2.close()@@ -153,7 +157,8 @@ class TestBusyTimeout:# Create databaseconn1 = sqlcipher_module.connect(str(temp_db_path))cursor1 = conn1.cursor()- apply_cipher_settings_before_key(cursor1)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor1, creation_mode=True)set_sqlcipher_key(cursor1, "testpassword")apply_performance_pragmas(cursor1)cursor1.close()@@ -212,7 +217,8 @@ class TestPerformanceIntegration:# Create database with performance pragmasconn1 = sqlcipher_module.connect(str(temp_db_path))cursor1 = conn1.cursor()- apply_cipher_settings_before_key(cursor1)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor1, creation_mode=True)set_sqlcipher_key(cursor1, "testpassword")apply_performance_pragmas(cursor1)cursor1.close()@@ -224,7 +230,8 @@ class TestPerformanceIntegration:# Reopen and verifyconn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, "testpassword")apply_performance_pragmas(cursor2)cursor2.close()diff --git a/tests/auth_tests/test_sqlcipher_rekey.py b/tests/auth_tests/test_sqlcipher_rekey.pyindex 15a6e5ac9a..db2b49c27f 100644--- a/tests/auth_tests/test_sqlcipher_rekey.py+++ b/tests/auth_tests/test_sqlcipher_rekey.py@@ -43,7 +43,8 @@ def encrypted_db(sqlcipher_module, temp_db_path):"""Create an encrypted database with test data."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "original_password")cursor.close()@@ -71,7 +72,8 @@ class TestRekeyFunctionality:# Old password should failconn_old = sqlcipher_module.connect(str(db_path))cursor_old = conn_old.cursor()- apply_cipher_settings_before_key(cursor_old)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_old, creation_mode=False)set_sqlcipher_key(cursor_old, "original_password")cursor_old.close()@@ -82,7 +84,8 @@ class TestRekeyFunctionality:# New password should workconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, "new_password")cursor_new.close()@@ -109,7 +112,8 @@ class TestRekeyFunctionality:# Read data after rekeyconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, "new_password")cursor_new.close()@@ -157,7 +161,8 @@ class TestRekeyFunctionality:for wrong_password in passwords[:-1]:conn_wrong = sqlcipher_module.connect(str(db_path))cursor_wrong = conn_wrong.cursor()- apply_cipher_settings_before_key(cursor_wrong)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_wrong, creation_mode=False)set_sqlcipher_key(cursor_wrong, wrong_password)cursor_wrong.close()@@ -168,7 +173,8 @@ class TestRekeyFunctionality:# Final password worksconn_final = sqlcipher_module.connect(str(db_path))cursor_final = conn_final.cursor()- apply_cipher_settings_before_key(cursor_final)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_final, creation_mode=False)set_sqlcipher_key(cursor_final, "final_password")cursor_final.close()@@ -194,7 +200,8 @@ class TestRekeySpecialPasswords:# Verify new password worksconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, new_password)cursor_new.close()@@ -218,7 +225,8 @@ class TestRekeySpecialPasswords:# Verify new password worksconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, new_password)cursor_new.close()@@ -242,7 +250,8 @@ class TestRekeySpecialPasswords:# Verify new password worksconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, new_password)cursor_new.close()@@ -268,7 +277,8 @@ class TestRekeySpecialPasswords:# Verify new password works and table still existsconn_new = sqlcipher_module.connect(str(db_path))cursor_new = conn_new.cursor()- apply_cipher_settings_before_key(cursor_new)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor_new, creation_mode=False)set_sqlcipher_key(cursor_new, new_password)cursor_new.close()@@ -302,7 +312,8 @@ class TestRekeyWithSQLAlchemy:# Create database with raw connection firstraw_conn = sqlcipher_module.connect(str(temp_db_path))cursor = raw_conn.cursor()- apply_cipher_settings_before_key(cursor)+ # New database, so use creation_mode=True+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "original_password")cursor.close()raw_conn.execute(@@ -321,9 +332,10 @@ class TestRekeyWithSQLAlchemy:@event.listens_for(engine, "connect")def set_cipher(dbapi_conn, connection_record):cursor = dbapi_conn.cursor()- apply_cipher_settings_before_key(cursor)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor, creation_mode=False)set_sqlcipher_key(cursor, "original_password")- apply_sqlcipher_pragmas(cursor)+ apply_sqlcipher_pragmas(cursor, creation_mode=False)cursor.close()with engine.connect() as conn:@@ -342,7 +354,8 @@ class TestRekeyWithSQLAlchemy:# Verify new password works with raw connectionraw_conn2 = sqlcipher_module.connect(str(temp_db_path))cursor2 = raw_conn2.cursor()- apply_cipher_settings_before_key(cursor2)+ # Existing database, so use creation_mode=False+ apply_cipher_settings_before_key(cursor2, creation_mode=False)set_sqlcipher_key(cursor2, "new_password")cursor2.close()diff --git a/tests/auth_tests/test_sqlcipher_settings.py b/tests/auth_tests/test_sqlcipher_settings.pyindex c32e86707b..248143343f 100644--- a/tests/auth_tests/test_sqlcipher_settings.py+++ b/tests/auth_tests/test_sqlcipher_settings.py@@ -145,7 +145,7 @@ class TestPerformancePragmaSettings:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -167,7 +167,7 @@ class TestPerformancePragmaSettings:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -185,7 +185,7 @@ class TestPerformancePragmaSettings:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -202,7 +202,7 @@ class TestPerformancePragmaSettings:"""Verify default journal mode is WAL."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -218,7 +218,7 @@ class TestPerformancePragmaSettings:"""Verify temp_store is always set to MEMORY."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -235,7 +235,7 @@ class TestPerformancePragmaSettings:"""Verify busy_timeout is set to 10000ms."""conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()@@ -259,7 +259,7 @@ class TestSettingsAppliedToDatabase:cursor = conn.cursor()# Apply settings before key- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")cursor.close()@@ -288,7 +288,7 @@ class TestSettingsAppliedToDatabase:conn = sqlcipher_module.connect(str(temp_db_path))cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=True)set_sqlcipher_key(cursor, "testpassword")apply_performance_pragmas(cursor)cursor.close()diff --git a/tests/auth_tests/test_sqlcipher_threads.py b/tests/auth_tests/test_sqlcipher_threads.pyindex 3e34838a81..bcfb26251e 100644--- a/tests/auth_tests/test_sqlcipher_threads.py+++ b/tests/auth_tests/test_sqlcipher_threads.py@@ -42,11 +42,13 @@ def sqlcipher_module():def create_configured_connection(sqlcipher_module, db_path, password):"""Helper to create a properly configured connection."""+ # Detect if we're creating a new database or opening an existing one+ creation_mode = not db_path.exists()conn = sqlcipher_module.connect(str(db_path), check_same_thread=False)cursor = conn.cursor()- apply_cipher_settings_before_key(cursor)+ apply_cipher_settings_before_key(cursor, creation_mode=creation_mode)set_sqlcipher_key(cursor, password)- apply_sqlcipher_pragmas(cursor)+ apply_sqlcipher_pragmas(cursor, creation_mode=creation_mode)apply_performance_pragmas(cursor)cursor.close()return conn