sequoia sqlite debug stuff sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 18 Oct 2019 15:03:15 +0200
branchsync
changeset 41272fb3ecbf7c42
parent 4126 d6a2fa2086a0
child 4129 f5db0b647d54
sequoia sqlite debug stuff
src/pEpEngine.c
src/pgp_sequoia.c
     1.1 --- a/src/pEpEngine.c	Fri Oct 18 14:49:54 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Fri Oct 18 15:03:15 2019 +0200
     1.3 @@ -11,8 +11,7 @@
     1.4  #include <time.h>
     1.5  #include <stdlib.h>
     1.6  
     1.7 -#define _PEP_SQLITE_DEBUG 0
     1.8 -#if _PEP_SQLITE_DEBUG
     1.9 +#ifdef _PEP_SQLITE_DEBUG
    1.10  #include <sqlite3.h>
    1.11  #endif
    1.12  
    1.13 @@ -42,7 +41,7 @@
    1.14      }
    1.15  }
    1.16  
    1.17 -#if _PEP_SQLITE_DEBUG
    1.18 +#ifdef _PEP_SQLITE_DEBUG
    1.19  int sql_trace_callback (unsigned trace_constant, 
    1.20                          void* context_ptr,
    1.21                          void* P,
    1.22 @@ -875,7 +874,7 @@
    1.23          goto pEp_error;
    1.24      }
    1.25      
    1.26 -#if _PEP_SQLITE_DEBUG    
    1.27 +#ifdef _PEP_SQLITE_DEBUG    
    1.28      sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback, NULL);
    1.29  #endif
    1.30  
    1.31 @@ -906,7 +905,7 @@
    1.32  
    1.33      sqlite3_busy_timeout(_session->db, BUSY_WAIT_TIME);
    1.34  
    1.35 -#if _PEP_SQLITE_DEBUG
    1.36 +#ifdef _PEP_SQLITE_DEBUG
    1.37      sqlite3_trace_v2(_session->db, 
    1.38          SQLITE_TRACE_STMT | SQLITE_TRACE_ROW | SQLITE_TRACE_CLOSE,
    1.39          sql_trace_callback,
     2.1 --- a/src/pgp_sequoia.c	Fri Oct 18 14:49:54 2019 +0200
     2.2 +++ b/src/pgp_sequoia.c	Fri Oct 18 15:03:15 2019 +0200
     2.3 @@ -93,6 +93,34 @@
     2.4      }                                                               \
     2.5  } while(0)
     2.6  
     2.7 +#if 1
     2.8 +int sq_sql_trace_callback (unsigned trace_constant, 
     2.9 +                        void* context_ptr,
    2.10 +                        void* P,
    2.11 +                        void* X) {
    2.12 +    switch (trace_constant) {
    2.13 +        case SQLITE_TRACE_STMT:
    2.14 +            fprintf(stderr, "SEQUOIA_SQL_DEBUG: STMT - ");
    2.15 +            const char* X_str = (const char*) X;
    2.16 +            if (!EMPTYSTR(X_str) && X_str[0] == '-' && X_str[1] == '-')
    2.17 +                fprintf(stderr, "%s\n", X_str);
    2.18 +            else
    2.19 +                fprintf(stderr, "%s\n", sqlite3_expanded_sql((sqlite3_stmt*)P));
    2.20 +            break;
    2.21 +        case SQLITE_TRACE_ROW:
    2.22 +            fprintf(stderr, "SEQUOIA_SQL_DEBUG: ROW - ");
    2.23 +            fprintf(stderr, "%s\n", sqlite3_expanded_sql((sqlite3_stmt*)P));
    2.24 +            break;            
    2.25 +        case SQLITE_TRACE_CLOSE:
    2.26 +            fprintf(stderr, "SEQUOIA_SQL_DEBUG: CLOSE - ");
    2.27 +            break;
    2.28 +        default:
    2.29 +            break;
    2.30 +    }
    2.31 +    return 0;
    2.32 +}
    2.33 +#endif
    2.34 +
    2.35  PEP_STATUS pgp_config_cipher_suite(PEP_SESSION session,
    2.36          PEP_CIPHER_SUITE suite)
    2.37  {
    2.38 @@ -236,6 +264,13 @@
    2.39      free(path);
    2.40  #endif
    2.41  
    2.42 +#if 1      
    2.43 +    sqlite3_trace_v2(session->key_db, 
    2.44 +        SQLITE_TRACE_STMT | SQLITE_TRACE_ROW | SQLITE_TRACE_CLOSE,
    2.45 +        sq_sql_trace_callback,
    2.46 +        NULL);    
    2.47 +#endif            
    2.48 +
    2.49      if (sqlite_result != SQLITE_OK)
    2.50          ERROR_OUT(NULL, PEP_INIT_CANNOT_OPEN_DB,
    2.51                    "opening keys DB: %s", sqlite3_errmsg(session->key_db));