> I'd expect that after sqlite3_step is done I can safely change > that buffers, but it seems not. > Is it a bug? Feature or incorrect use of SQLITE_STATIC
It's an incorrect use of SQLITE_STATIC. Only call to sqlite3_finalize() can guarantee you that buffer won't be used again. Probably a pair of calls to sqlite3_reset() and sqlite3_clear_bindings() would do that too. But nothing else. "sqlite3_step is done" doesn't mean statement has finished executing. The value can be used in the next call to sqlite3_step or (as your program proves) in a call to other sqlite3_* function. Pavel On Tue, May 22, 2012 at 4:02 PM, Artyom Beilis <[email protected]> wrote: > Hello, > > One of the things that is useful is sqlite3_bind_text is SQLITE_STATIC that > allows to reduce memory copy. I assumed that I need to keep the value valid > until I execute that statement, however I discovered it does not work this > way: > > Following simple program prints "xbcd" instead of expected "abcd"... > #include <sqlite3.h> > > #include <assert.h> > #include <stdio.h> > > int main() > { > sqlite3 *conn = 0; > assert(sqlite3_open(":memory:",&conn) == 0); > sqlite3_stmt *st = 0; > assert(sqlite3_prepare(conn,"SELECT ?",-1,&st,0)==0); > char buf[5] = "abcd"; > sqlite3_bind_text(st,1,buf,-1,SQLITE_STATIC); > assert(sqlite3_step(st)==SQLITE_ROW); > buf[0]='x'; > char const *s = (char const *)sqlite3_column_text(st,0); > printf("%s\n",s); > sqlite3_finalize(st); > sqlite3_close(conn); > return 0; > } > > > I'd expect that after sqlite3_step is done I can safely change > that buffers, but it seems not. > Is it a bug? Feature or incorrect use of SQLITE_STATIC > > Thanks! > > > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

