Shaun Seckman (Firaxis) wrote:
> Hello everyone,
>
> I'm in the process of writing some C++ wrappers to
> SQLite in order to shoehorn it into some legacy code. I'm curious if
> there is any performance impact to having several prepared statements
> active at any given time.
That depends. There is a time hit for preparing a query, but it is
minimal. That being said, I wrote a performance analyzer for our Delphi
wrappers which tracked the amount of time in each phase and eliminated
60% of our application's overall query time cost by caching prepared
queries.
> I was thinking about using a prepared
> statement per instance of a Query class. Also, what is the lifetime of
> the text received by sqlite3_column_text?
>
This one caught me. There is a parameter argument you can pass which
transfers the management of the string to the sqlite engine itself:
Note that this code is in Delphi, but you get the idea:
procedure TSqlite3PreparedStatement.bind(const oneBasedIndex: integer;
const value: ansistring);
begin
logParam(itsParamName, oneBasedIndex, value);
checkSqliteReturnResult(
_sqlite3_bind_text(itsSqlitePreparedStatement, oneBasedIndex,
pAnsiChar(value), length(value), pointer(SQLITE_TRANSIENT)),
bindingError('string', value, oneBasedIndex));
end;
SQLITE_TRANSIENT is the value you are looking for:
http://www.sqlite.org/c3ref/bind_blob.html
"The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
string after SQLite has finished with it. If the fifth argument is the
special value SQLITE_STATIC, then SQLite assumes that the information is
in static, unmanaged space and does not need to be freed. If the fifth
argument has the value SQLITE_TRANSIENT, then SQLite makes its own
private copy of the data immediately, before the sqlite3_bind_*()
routine returns."
HTH,
John
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users