On Sunday, September 11, 2011 08:37:10 PM 陈抒 wrote:
> To get the correct Chinese words from MySQL via CppDB,make sure you add
> ";set_charset_name=utf8" into connection string.There is one example below:
> #include <string>
> #include <iostream>
> using namespace std;
> #include <cppdb/frontend.h>
>
> int main(int argc,char* argv[]){
> locale new_locale(locale("zh_CN.utf8"));
> locale old_loc = locale::global(new_locale);
> try{
> string
> connection_string("mysql:host=192.168.1.15;database=d01;user=data;password=
> skst;set_charset_name=utf8"); cppdb::session session(connection_string);
> string sql="select address from tape_local limit 0,1";
> cppdb::result res = session<<sql;
> while(res.next()){
> cout<<res.get<string>("address")<<endl;
> }
> }catch(std::exception const& ex){
> cout<<ex.what()<<endl;
> }catch(...){
> cout<<"Unknown exception"<<endl;
> }
> }
>
> I also wrote one document in Chinese here:
> http://blog.csdn.net/sheismylife/article/details/6767770
謝謝陈抒, 太感謝你.
I struggled with that for a long time.
Thank you for sharing the solution.
Artyom:
I had previously checked the documentation here:
http://cppcms.com/sql/cppdb/connstr.html
However, there are some parts that I hadn't understood, and there are some
parts that are not documented.
I am willing to prepare a patch to improve the documentation. However, there
are some parts that I still don't know or understand. Can we work together to
improve the official documentation? [Note, as previously mentioned, I cannot
login at sourceforge. It won't allow me].
set_charset_name is a cppdb construct. It is not found in the MySQL official
documentation, although MYSQL_SET_CHARSET_NAME is.
Should we document within cppdb itself all the mysql configuration options?
Or should we link to the mysql official documentation and let users know where
to check to see which options are available?
Also, I checked the other backends (postgres, etc.), and didn't find any
comparable support for connection string options. Don't other backends support
such options?
yours,
augustin.
新年快樂
.
|