@@ -1608,8 +1608,14 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz
16081608#if !defined(SQLITE_OMIT_TRACE )
16091609static int sqlcipher_profile_callback (unsigned int trace , void * file , void * stmt , void * run_time ){
16101610 FILE * f = (FILE * ) file ;
1611+ char * fmt = "Elapsed time:%.3f ms - %s\n" ;
16111612 double elapsed = (* ((sqlite3_uint64 * )run_time ))/1000000.0 ;
1612- if (f ) fprintf (f , "Elapsed time:%.3f ms - %s\n" , elapsed , sqlite3_sql ((sqlite3_stmt * )stmt ));
1613+ #ifdef __ANDROID__
1614+ if (f == NULL ) {
1615+ __android_log_print (ANDROID_LOG_DEBUG , "sqlcipher" , fmt , elapsed , sqlite3_sql ((sqlite3_stmt * )stmt );
1616+ }
1617+ #endif
1618+ if (f ) fprintf (f , fmt , elapsed , sqlite3_sql ((sqlite3_stmt * )stmt ));
16131619 return SQLITE_OK ;
16141620}
16151621#endif
@@ -1618,21 +1624,25 @@ int sqlcipher_cipher_profile(sqlite3 *db, const char *destination){
16181624#if defined(SQLITE_OMIT_TRACE )
16191625 return SQLITE_ERROR ;
16201626#else
1621- FILE * f ;
1622- if (sqlite3_stricmp (destination , "stdout" ) == 0 ){
1623- f = stdout ;
1624- }else if (sqlite3_stricmp (destination , "stderr" ) == 0 ){
1625- f = stderr ;
1626- }else if (sqlite3_stricmp (destination , "off" ) == 0 ){
1627- f = 0 ;
1628- }else {
1627+ FILE * f = NULL ;
1628+ if (sqlite3_stricmp (destination , "off" ) == 0 ){
1629+ sqlite3_trace_v2 (db , 0 , NULL , NULL ); /* disable tracing */
1630+ } else {
1631+ if (sqlite3_stricmp (destination , "stdout" ) == 0 ){
1632+ f = stdout ;
1633+ }else if (sqlite3_stricmp (destination , "stderr" ) == 0 ){
1634+ f = stderr ;
1635+ }else if (sqlite3_stricmp (destination , "logcat" ) == 0 ){
1636+ f = NULL ; /* file pointer will be NULL indicating logcat on android */
1637+ }else {
16291638#if !defined(SQLCIPHER_PROFILE_USE_FOPEN ) && (defined(_WIN32 ) && (__STDC_VERSION__ > 199901L ) || defined(SQLITE_OS_WINRT ))
1630- if (fopen_s (& f , destination , "a" ) != 0 ) return SQLITE_ERROR ;
1639+ if (fopen_s (& f , destination , "a" ) != 0 ) return SQLITE_ERROR ;
16311640#else
1632- if ((f = fopen (destination , "a" )) == 0 ) return SQLITE_ERROR ;
1641+ if ((f = fopen (destination , "a" )) == 0 ) return SQLITE_ERROR ;
16331642#endif
1643+ }
1644+ sqlite3_trace_v2 (db , SQLITE_TRACE_PROFILE , sqlcipher_profile_callback , f );
16341645 }
1635- sqlite3_trace_v2 (db , SQLITE_TRACE_PROFILE , sqlcipher_profile_callback , f );
16361646 return SQLITE_OK ;
16371647#endif
16381648}
0 commit comments