report SQLCipher version alongside SQLite version in shell

This commit is contained in:
Stephen Lombardo 2020-04-20 20:38:57 -04:00
parent 94e4c45fc6
commit 299fe42a53
4 changed files with 43 additions and 10 deletions

View File

@ -155,12 +155,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
}
} else
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
#ifdef CIPHER_VERSION_QUALIFIER
char *version = sqlite3_mprintf("%s %s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_QUALIFIER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#else
char *version = sqlite3_mprintf("%s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#endif
codec_vdbe_return_string(pParse, "cipher_version", version, P4_DYNAMIC);
codec_vdbe_return_string(pParse, "cipher_version", sqlcipher_version(), P4_DYNAMIC);
}else
if( sqlite3StrICmp(zLeft, "cipher")==0 ){
if(ctx) {

View File

@ -365,6 +365,15 @@ void* sqlcipher_malloc(int sz) {
return ptr;
}
char* sqlcipher_version() {
#ifdef CIPHER_VERSION_QUALIFIER
char *version = sqlite3_mprintf("%s %s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_QUALIFIER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#else
char *version = sqlite3_mprintf("%s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#endif
return version;
}
/**
* Initialize new cipher_ctx struct. This function will allocate memory
* for the cipher context and for the key

View File

@ -9523,6 +9523,16 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid());
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
{
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
utf8_printf(p->out, "SQLCipher %s\n", sqlcipher_ver);
sqlite3_free(sqlcipher_ver);
}
#endif
/* END SQLCIPHER */
#if SQLITE_HAVE_ZLIB
utf8_printf(p->out, "zlib version %s\n", zlibVersion());
#endif
@ -10416,7 +10426,17 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
}else if( strcmp(z,"-bail")==0 ){
bail_on_error = 1;
}else if( strcmp(z,"-version")==0 ){
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
printf("%s %s", sqlite3_libversion(), sqlite3_sourceid());
printf(" (SQLCipher %s)\n", sqlcipher_ver);
sqlite3_free(sqlcipher_ver);
#else
printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
#endif
/* BEGIN SQLCIPHER */
return 0;
}else if( strcmp(z,"-interactive")==0 ){
stdin_is_interactive = 1;
@ -10523,17 +10543,25 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
char *zHome;
char *zHistory;
int nHistory;
printf(
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
"SQLCipher version %s %.19s\n" /*extra-version-info*/
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
printf(
"SQLite version %s %.19s" /*extra-version-info*/
" (SQLCipher %s)\n" /*sqlcipher version info*/
"Enter \".help\" for usage hints.\n",
sqlite3_libversion(), sqlite3_sourceid(), sqlcipher_ver
);
sqlite3_free(sqlcipher_ver);
#else
printf(
"SQLite version %s %.19s\n" /*extra-version-info*/
#endif
/* END SQLCIPHER */
"Enter \".help\" for usage hints.\n",
sqlite3_libversion(), sqlite3_sourceid()
);
#endif
/* END SQLCIPHER */
if( warnInmemoryDb ){
printf("Connected to a ");
printBold("transient in-memory database");

View File

@ -80,6 +80,7 @@ void* sqlcipher_memset(void *, unsigned char, int);
int sqlcipher_ismemset(const void *, unsigned char, int);
int sqlcipher_memcmp(const void *, const void *, int);
void sqlcipher_free(void *, int);
char* sqlcipher_version();
/* provider interfaces */
int sqlcipher_register_provider(sqlcipher_provider *);