Skip to content

Commit fafd98e

Browse files
Add PRAGMA cipher_profile support
1 parent 63f8f9e commit fafd98e

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ xcuserdata/*
3737
/sqlcipher.pc
3838
/sqlite3ext.h
3939
/libsqlcipher.la
40+
/.DS_Store

src/crypto.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
8989

9090
CODEC_TRACE(("sqlcipher_codec_pragma: entered db=%p iDb=%d pParse=%p zLeft=%s zRight=%s ctx=%p\n", db, iDb, pParse, zLeft, zRight, ctx));
9191

92+
93+
if( sqlite3StrICmp(zLeft, "cipher_profile")== 0 && zRight ){
94+
char *profile_status = sqlite3_mprintf("%d", sqlcipher_cipher_profile(db, zRight));
95+
codec_vdbe_return_static_string(pParse, "cipher_profile", profile_status);
96+
sqlite3_free(profile_status);
97+
} else
9298
if( sqlite3StrICmp(zLeft, "cipher_add_random")==0 && zRight ){
9399
if(ctx) {
94100
char *add_random_status = sqlite3_mprintf("%d", sqlcipher_codec_add_random(ctx, zRight, sqlite3Strlen30(zRight)));
@@ -243,6 +249,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
243249
return 1;
244250
}
245251

252+
246253
/*
247254
* sqlite3Codec can be called in multiple modes.
248255
* encrypt mode - expected to return a pointer to the

src/crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx)
214214
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx);
215215
int sqlcipher_codec_ctx_migrate(codec_ctx *ctx);
216216
int sqlcipher_codec_add_random(codec_ctx *ctx, const char *data, int random_sz);
217+
int sqlcipher_cipher_profile(sqlite3 *db, const char *destination);
218+
static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time);
217219
#endif
218220
#endif
219221
/* END SQLCIPHER */

src/crypto_impl.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,30 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz
11461146
return SQLITE_ERROR;
11471147
}
11481148

1149+
int sqlcipher_cipher_profile(sqlite3 *db, const char *destination){
1150+
FILE *f;
1151+
if( strcmp(destination,"stdout")==0 ){
1152+
f = stdout;
1153+
}else if( strcmp(destination, "stderr")==0 ){
1154+
f = stderr;
1155+
}else if( strcmp(destination, "off")==0 ){
1156+
f = 0;
1157+
}else{
1158+
f = fopen(destination, "wb");
1159+
if( f==0 ){
1160+
return SQLITE_ERROR;
1161+
}
1162+
}
1163+
sqlite3_profile(db, sqlcipher_profile_callback, f);
1164+
return SQLITE_OK;
1165+
}
1166+
1167+
static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time){
1168+
FILE *f = (FILE*)file;
1169+
double elapsed = run_time/1000000.0;
1170+
if( f ) fprintf(f, "Elapsed time:%.3f ms - %s\n", elapsed, sql);
1171+
}
1172+
11491173

11501174
#endif
11511175
/* END SQLCIPHER */

0 commit comments

Comments
 (0)