Poco Mysql使用

连接时用到的一些字段, POCO官方文档中也有说明

\Data\MySQL\src\SessionImpl.cpp:69

options["host"]= "localhost";

options["port"]= "3306";

options["user"]= "";

options["password"]= "";

options["db"]= "";

options["compress"]= "";

options["auto-reconnect"]= "";

 

 

 

//连接

std::string mysql_poco::_dbConnString = "host=xxx.17.xx.68;user=xxx;password=xxx;db=bizcnvhost;compress=true;auto-reconnect=true";

Connector::registerConnector();

_pSession =  newSession(SessionFactory::instance().create(Connector::KEY,_dbConnString));

//:

string s1 ="a1";

string s2 ="b2";

string s3 ="b3";

string s4 ="b4";        

*_pSession<<"INSERT INTO 表 VALUES(?,?,?,?)",use(s1),use(s2),use(s3),use(s4),now;

 

//

int count = 0;

*_pSession <<"SELECT COUNT(*) FROM 表", into(count), now;

 

注意: use into 的用法, use用于添加数据into 用于返回值

 

这好像似乎没什么,C接口同样可以实现,它的强处在下面:

1 操作自定义结构体, 例如插入一个自定义的结构体,或将返回的数据放到自定义的结构体中,

  1 定义你结构体,但必须重载 () 操作符

  2 特化模版类TypeHandler,并重写bind size extract prepare 4个静态函数, 原型在 poco-1.4.2p1-all\Data\include\Poco\Data\TypeHandler.h

 

2 操作元组

3 操作map

4 操作set

5 操作vector


具体请参考: Poco 提供的示例

Mysql 官方提供的c++库貌似有内存泄漏, 在windows 下没有,Linux 貌似就有

你可能感兴趣的:(c++,Poco)