nathan-b
September 3rd, 2013, 02:06 AM
Hi!
I'm writing a c++ program that uses sqlite and I need to get the data from a result column as a string, so I use this function:
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
The problem is I need to convert the const unsigned char* to a std::string or a QString (the gui is in Qt). I googled and lots of people seem to have the same issue but the most common suggestion is apparently just
reinterpret_cast<const char*>(sqlite3_column_text()) which seems kind of like one of those if-you-have-a-hammer-everything-seems-like-a-nail situations. I think the const unsigned char* is binary UTF-8 data, so casting it would work as long as everything was ascii but I'm writing a music player so I need to be able to store and retrieve strings like "Björk". Is something like libicu the solution here?
I'm thinking of just using the Qt SQL interface, but I don't want to get tied down to where all I know is Qt. I want to know how to use C++ with other libraries too. If all I use is one API for everything I might as well just use Java. :p
I'm writing a c++ program that uses sqlite and I need to get the data from a result column as a string, so I use this function:
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
The problem is I need to convert the const unsigned char* to a std::string or a QString (the gui is in Qt). I googled and lots of people seem to have the same issue but the most common suggestion is apparently just
reinterpret_cast<const char*>(sqlite3_column_text()) which seems kind of like one of those if-you-have-a-hammer-everything-seems-like-a-nail situations. I think the const unsigned char* is binary UTF-8 data, so casting it would work as long as everything was ascii but I'm writing a music player so I need to be able to store and retrieve strings like "Björk". Is something like libicu the solution here?
I'm thinking of just using the Qt SQL interface, but I don't want to get tied down to where all I know is Qt. I want to know how to use C++ with other libraries too. If all I use is one API for everything I might as well just use Java. :p