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
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to