visual studio 2010 - Encoding problems during INSERT with Sqlite3 C++ and VisualStudio2010 -


i'm developing small wrapper project using sqlite3 c++ api , visualstudio 2010. far goes , checking tool sqlitedatabasebrowser, main problem information try insert in table appears corrupted / doesn't appear @ all. table appears correctly created utf8 encoding.

i tried using character set configuration values in vs "use multy-byte character set" , tried "use unicode character set" got no change in result. both gave me same problem corrupted data. use typical std::strings converted legacy c char* , i've seen in several examples should work sqlite3_bind_text(...) functions api provides.

    sqlite3_bind_int(stmt, 1, newshop.getid());     sqlite3_bind_text(stmt, 2, newshop.getname().c_str(), -1, sqlite_static);     sqlite3_bind_text(stmt, 3, newshop.getlocation().c_str(), -1, sqlite_static);     sqlite3_bind_text(stmt, 4, newshop.getpicturepath().c_str(), -1, sqlite_static);     sqlite3_bind_text(stmt, 5, newshop.getregisters().c_str(), -1, sqlite_static);     sqlite3_bind_text(stmt, 6, newshop.getmixes().c_str(), -1, sqlite_static);     sqlite3_bind_text(stmt, 7, newshop.getallowedusers().c_str(), -1, sqlite_static);     sqlite3_bind_int(stmt, 8, newshop.isavailable() == true?1:0); 

newshop instance of class contains information in std::strings , int. have bindings int type, work , without problem, others totally messed up. when strings hardcoded, ok until try insert special characters such "áàä" , such.

the table created statement:

char *szsql = "create table if not exists shops (id integer primary key not null, name text not null, location text, picturepath text, registers text, mixes text, users text, available integer not null);"; int rc = sqlite3_exec(db, szsql, null, 0, null); 

this how looks when insert data using code snippet above:

database encoding problems

sending winunit test looks like:

shop shone = shop(1234, "its nothing", "manhattan", "seinfeld.jpg", "1111,2222,3333", "1000x1,2000x7", "10,11,12", true);  shop shtwo = shop(4321, "louie", "manhattan", "", "1111,5555", "50000x1,10000x5", "60,70", true);  win_assert_equal(0, auxsql.insertshop(shone)); win_assert_equal(0, auxsql.insertshop(shtwo)); 

neither insertion, commit, creation of sql statement or other function call sqlite3 api return error code.

i found solution. nothing related encoding, thought because of characters being strangely represented in db browser , nothing related length.

the problem in last parameter of binding. pass sqlite_static, should have passed sqlite_transient, object returned calls want bind possibly destructed before query executed. explained in other question:

sqlite3_bind_text sqlite_static vs sqlite_transient c++ string


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -