---------- Original Message ----------
To: General Discussion of SQLite Database (sqlite-users@sqlite.org)
From: Eric Minbiole ([EMAIL PROTECTED])
Subject: Re: [sqlite] sqlite3_bind_text problem
Date: 15/11/2008 12:22:53a

> > Then a bind the values to that statement and write it to the DB. That 
> > all works except for the TEXT field "Name". I'm calling 
> > sqlite3_bind_text like this:
> > 
> >     char *Name = "Something";       
> >     sqlite3_bind_text(Stmt, 3, (const char*)Name, -1, SQLITE_STATIC);
> > 
> > And it return SQLITE_OK, however the value in the DB is NULL, or an 
> > empty string. Certainly not the "Something" I pass in. All the integer 
> > fields are written successfully so I know it's mostly working. The 
> > string is valid utf-8, null terminated C-string.
> 
> It's possible that the char* variable is going out of scope before 
> SQLite3 has a chance to commit the string data.  Try passing 
> SQLITE_TRANSIENT to sqlite3_bind_text(), rather than STATIC.  This will 
> cause SQLite to create a private copy of the string, ensuring that it 
> isn't destroyed prematurely.

I thought about that before and tried SQLITE_TRANSIENT and it made no 
difference. And I'm sure the lifetime of that string is longer than the query 
so I want to end up saving that extra memory/copy if I can.

There may be another variable that I didn't mention in my first post, and that 
is I'm compiling sqlite using Visual C++ 6 on windows atm and maybe there is a 
problem that only shows up in VC6 and not in gcc. So with that in mind I'm 
building the Mac port of my software (which is built using gcc) and try to 
reproduce the problem there. I guess if everything is perfect there then it's 
VC6's fault. If I get the same result then it's something else.
--
Matthew Allen


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to