>>>>> Igor Tandetnik writes: >>>>> Ivan Shmakov <i...@gray.siamics.net> wrote:
>> I wonder, is it possible to create sqlite3_value * from scratch >> from within SQLite library's user code? > There's a circuitous route that leads there. You can prepare a > statement of the form "select ?;", bind the parameter with one of > sqlite3_bind_* functions, then step it once, and retrieve the value > right back with sqlite3_column_value. Note that the resulting > sqlite3_value is "unprotected" (see > http://sqlite.org/c3ref/value.html) and can only be used in limited > ways. And of course it's only valid until the "select ?;" statement > is reset or finalized. Unfortunately, the latter clearly prevents the kind of interface I've had in mind (below.) >> Given some way to construct a sqlite3_value wrapping object, I >> could instead rely on sqlite3_bind_value () alone, thus >> eliminating the necessity of type specifiers in the interface. > Well, a hypothetical API that constructs sqlite3_value from raw data > would have to take the type specifier anyway, wouldn't it? You would > just be moving the same logic to another place. Yes. But this still may make code clearer, and, occasionally, also more concise. Consider, e. g.: sqlite3_value *a = sqlite3_int64_value (1); assert (a != 0); sqlite3_value *b = sqlite3_text_value (-1, "qux"); sqlite3_value *c = sqlite3_blob_value (blob_size, blob); assert (b != 0); int r; r = db_triv_exec_bound (db, sql_1, a, b, 0); assert (r == SQLITE_OK); r = db_triv_exec_bound (db, sql_2, b, c, 0); assert (r == SQLITE_OK); r = db_triv_exec_bound (db, sql_3, c, a, 0); assert (r == SQLITE_OK); sqlite3_value_free (a); sqlite3_value_free (b); sqlite3_value_free (c); And I see no way to implement my_sqlite3_int64_value () using the identity SELECT (above), as it'd require my_sqlite3_value_free () to find the prepared statement associated with the value (to call sqlite3_finalize () on it, so to avoid a memory leak), and I know of no documented way of doing that. -- FSF associate member #7257 _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users