Jay Sprenkle wrote:
To use the sqlite3 return value to initialize a standard string in C++
you need to do the following:
const char* p = reinterpret_cast<const
char*>(sqlite3_column_text(pStmt, 0));
std::string zName(p);
The cast changes the type of the return value to match the type needed
by the string constructor. Then construct a string using that pointer.
You could combine the two statements into one and eliminate the
temporary pointer variable if you prefer.
I believe that will crash if the column is null. What does your string
constructor do with null pointers?
You are right, this will not work with NULL field values (it shouldn't
crash though, it should throw an exception). You will need to check for,
and handle, this special case in a manner appropriate for your
application. This might be sufficient:
const char* p = reinterpret_cast<const char*>(sqlite3_column_text(pStmt, 0));
if (p == NULL)
p = "<NULL>"; // or some other sentinel value
std::string zName(p);
Dennis Cote