Add PRAGMA cipher_profile support
This commit is contained in:
parent
63f8f9eccc
commit
fafd98ef5d
|
@ -37,3 +37,4 @@ xcuserdata/*
|
|||
/sqlcipher.pc
|
||||
/sqlite3ext.h
|
||||
/libsqlcipher.la
|
||||
/.DS_Store
|
||||
|
|
|
@ -89,6 +89,12 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
|||
|
||||
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));
|
||||
|
||||
|
||||
if( sqlite3StrICmp(zLeft, "cipher_profile")== 0 && zRight ){
|
||||
char *profile_status = sqlite3_mprintf("%d", sqlcipher_cipher_profile(db, zRight));
|
||||
codec_vdbe_return_static_string(pParse, "cipher_profile", profile_status);
|
||||
sqlite3_free(profile_status);
|
||||
} else
|
||||
if( sqlite3StrICmp(zLeft, "cipher_add_random")==0 && zRight ){
|
||||
if(ctx) {
|
||||
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
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* sqlite3Codec can be called in multiple modes.
|
||||
* encrypt mode - expected to return a pointer to the
|
||||
|
|
|
@ -214,6 +214,8 @@ int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx)
|
|||
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx);
|
||||
int sqlcipher_codec_ctx_migrate(codec_ctx *ctx);
|
||||
int sqlcipher_codec_add_random(codec_ctx *ctx, const char *data, int random_sz);
|
||||
int sqlcipher_cipher_profile(sqlite3 *db, const char *destination);
|
||||
static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time);
|
||||
#endif
|
||||
#endif
|
||||
/* END SQLCIPHER */
|
||||
|
|
|
@ -1146,6 +1146,30 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz
|
|||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
int sqlcipher_cipher_profile(sqlite3 *db, const char *destination){
|
||||
FILE *f;
|
||||
if( strcmp(destination,"stdout")==0 ){
|
||||
f = stdout;
|
||||
}else if( strcmp(destination, "stderr")==0 ){
|
||||
f = stderr;
|
||||
}else if( strcmp(destination, "off")==0 ){
|
||||
f = 0;
|
||||
}else{
|
||||
f = fopen(destination, "wb");
|
||||
if( f==0 ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
}
|
||||
sqlite3_profile(db, sqlcipher_profile_callback, f);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time){
|
||||
FILE *f = (FILE*)file;
|
||||
double elapsed = run_time/1000000.0;
|
||||
if( f ) fprintf(f, "Elapsed time:%.3f ms - %s\n", elapsed, sql);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/* END SQLCIPHER */
|
||||
|
|
Loading…
Reference in New Issue