0

I want to print out the exact SQL statement sent to the database for logging purposes. I have looked at sqlite3_sql but it doesn't actually print out the SQL statement, just the original SQL I use as input to sqlite3_prepare_v2.

Here is my function to add a value to a row which I want to also print the sql statement.

int add_value(sqlite3* db, sqlite3_stmt * stmt, const char* oid, const char* value)
{
    char sql[256] = {0};
    sprintf(sql, "UPDATE table1 SET Value=? WHERE Field1=\"%s\"", oid);
    printf("%s\n", sql);

    int ret = ::sqlite3_prepare_v2(
        db,
        sql,
        strlen(sql),
        &stmt,
        0 );

    /* How do I print out the sql statement to be sent to the database? */

    ret = ::sqlite3_bind_text( stmt, 1, value, strlen(value), 0 );
    ret = sqlite3_step(stmt);

    return ret;
}

For a bit of background I am inserting integers and strings into the database. So the use of ? was to simplify the handling of the string - ie whether to put quotes round the value or not dependent on data type. But for debugging purposes I do want to log the sql statements.

Angus Comber
  • 9,316
  • 14
  • 59
  • 107

1 Answers1

0

Both the original SQL statement and the bound parameter values are sent to the database.

There is no mechanism to read out the parameter values. You have to log the values when calling sqlite3_bind_*.

CL.
  • 173,858
  • 17
  • 217
  • 259