Skip to content

Commit 440ca08

Browse files
committed
Hook sqlite3mc's attach key handler
Let's hook `sqlite3mcHandleAttachKey` method to handle if an encryption key is passed in attach.
1 parent d5cd477 commit 440ca08

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121872,6 +121872,10 @@ SQLITE_PRIVATE int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName){
121872121872
int libsql_handle_extra_attach_params(sqlite3* db, const char* zName, const char* zPath, sqlite3_value* pKey, char** zErrDyn);
121873121873
#endif
121874121874

121875+
#ifdef LIBSQL_ENCRYPTION
121876+
SQLITE_PRIVATE int sqlite3mcHandleAttachKey(sqlite3*, const char*, const char*, sqlite3_value*, char**);
121877+
#endif
121878+
121875121879
/*
121876121880
** An SQL user-function registered to do the work of an ATTACH statement. The
121877121881
** three arguments to the function come directly from an attach statement:
@@ -122031,6 +122035,16 @@ static void attachFunc(
122031122035
rc = libsql_handle_extra_attach_params(db, zName, zPath, argv, &zErrDyn);
122032122036
}
122033122037
#endif
122038+
122039+
#ifdef LIBSQL_ENCRYPTION
122040+
/* If the ATTACH statement came with key parameter, then lets handle it here. */
122041+
if( rc==SQLITE_OK ){
122042+
if( argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL ){
122043+
rc = sqlite3mcHandleAttachKey(db, zName, zPath, argv[2], &zErrDyn);
122044+
}
122045+
}
122046+
#endif
122047+
122034122048
sqlite3_free_filename( zPath );
122035122049

122036122050
/* If the file was opened successfully, read the schema for the new database.

libsql-sqlite3/src/attach.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName){
6161
int libsql_handle_extra_attach_params(sqlite3* db, const char* zName, const char* zPath, sqlite3_value* pKey, char** zErrDyn);
6262
#endif
6363

64+
#ifdef LIBSQL_ENCRYPTION
65+
SQLITE_PRIVATE int sqlite3mcHandleAttachKey(sqlite3*, const char*, const char*, sqlite3_value*, char**);
66+
#endif
67+
6468
/*
6569
** An SQL user-function registered to do the work of an ATTACH statement. The
6670
** three arguments to the function come directly from an attach statement:
@@ -220,6 +224,16 @@ static void attachFunc(
220224
rc = libsql_handle_extra_attach_params(db, zName, zPath, argv, &zErrDyn);
221225
}
222226
#endif
227+
228+
#ifdef LIBSQL_ENCRYPTION
229+
/* If the ATTACH statement came with key parameter, then lets handle it here. */
230+
if( rc==SQLITE_OK ){
231+
if( argv != NULL && argv[0] != NULL && argv[1] != NULL && argv[2] != NULL ){
232+
rc = sqlite3mcHandleAttachKey(db, zName, zPath, argv[2], &zErrDyn);
233+
}
234+
}
235+
#endif
236+
223237
sqlite3_free_filename( zPath );
224238

225239
/* If the file was opened successfully, read the schema for the new database.

0 commit comments

Comments
 (0)