Re: [Cppcms-users] cppdb , weird data corruption when using cppms::util::md5hex in cppdb::statemen
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-11-14 12:39:18
|
Do you use latest version? http://cppcms.com/sql/cppdb/changelog.html There are some sqlite3 related changed that changed behavior of strings that exited the scope. Also in general the strings values (reference to them) should remain valid until the statement is executed/queried. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: SIMON Allan <All...@su...> >To: "cpp...@li..." <cpp...@li...> >Sent: Wednesday, November 14, 2012 12:33 PM >Subject: [Cppcms-users] cppdb , weird data corruption when using cppms::util::md5hex in cppdb::statement::bind > > > >Hello > >I've met a quiet weird problem > >When trying to execute the code below, that simply insert some data in a Sqlite3 database, the data inserted are corrupted >however if I put first the result of md5hex in a const string and then bind with this string, the data corruption does not appear > > >here is the code > > ---------------------------- >#include <cppdb/frontend.h> >#include <cppcms/util.h> >#include <iostream> >#include <booster/posix_time.h> > > >int main() >{ > > cppdb::session sql("sqlite3:db=toto.db"); > cppdb::statement addUser = sql.prepare( > "INSERT INTO users(username, password, email, since)" > "VALUES(?,?,?,?)" > ); > > > const std::string login = "bbbb"; > std::string pass = "toto"; > std::string email = "023...@su..."; > > addUser.bind(login); > addUser.bind( > cppcms::util::md5hex(pass) > ); > std::cout << cppcms::util::md5hex(pass) << std::endl; > addUser.bind(email); > addUser.bind( > booster::ptime::now().get_seconds() > ); > > addUser.exec(); > addUser.reset(); > >} >------------------------------ > >here is the dump of the database > >CREATE TABLE users ( > "id" integer primary key autoincrement not null , > "username" text not null unique, -- his nickname > "email" text not null unique, -- his email address > "image" text not null default "unknown" , -- his personnal image > "password" text not null, -- his password hashed > "since" integer not null, -- his registering date > "homepage" text default "", -- his personnal webpage/website > "description" text default "" -- his self-written description > ); >INSERT INTO "users" VALUES(1,'toto','12...@su...','unknown','23...@su...?ab494817525c6',1352888183,'',''); > > >As you can see the password's hash is mixed with the email field, by doing the test several time, sometimes the hash is mixed with other data (the username for example) > >I've compiled with this command > >clang++ main.cpp -lcppdb -lcppcms -lbooster > >Thanks for your help > > > > >Regards, > >Allan SIMON >Tatoeba Administrator (Sysko) > >------------------------------------------------------------------------------ >Monitor your physical, virtual and cloud infrastructure from a single >web console. Get in-depth insight into apps, servers, databases, vmware, >SAP, cloud infrastructure, etc. Download 30-day Free Trial. >Pricing starts from $795 for 25 servers or applications! >http://p.sf.net/sfu/zoho_dev2dev_nov >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |