c - How to get exact SQL statement sent to database -
this question has answer here:
- enable query logging in sqlite 3 1 answer
i want print out exact sql statement sent database logging purposes. have looked @ sqlite3_sql doesn't print out sql statement, original sql use input sqlite3_prepare_v2.
here function add value row want print 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=? field1=\"%s\"", oid); printf("%s\n", sql); int ret = ::sqlite3_prepare_v2( db, sql, strlen(sql), &stmt, 0 ); /* how print out sql statement sent database? */ ret = ::sqlite3_bind_text( stmt, 1, value, strlen(value), 0 ); ret = sqlite3_step(stmt); return ret; }
for bit of background inserting integers , strings database. use of ? simplify handling of string - ie whether put quotes round value or not dependent on data type. debugging purposes want log sql statements.
both original sql statement , bound parameter values sent database.
there no mechanism read out parameter values. have log values when calling sqlite3_bind_*
.
Comments
Post a Comment