Terry MacDonald wrote:

Hi,

New to the list, so apologies if this has already been answered, I just can't find anything on my searches.

I am writings something in C++ and I am also using the prepare/step/finalize approach to retrieve values from the sqlite database: no callbacks - messy in C++.

There may be a simple answer to this but HOW do I get my return value from using sqlite_column_text (a const unsigned char*) into a c++ string?

example...

  string zName = sqlite3_column_text(pStmt,0) ;

fails as does numerous variations using static_cast, const_cast

If it returned const char* no problem, but the const unsigned char* aaaahhhh! the STL uses char* not unsigned char*

Please say I'm stoopid and the answer is straight forward.

Cheers

Terry,

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.

HTH
Dennis Cote

Reply via email to