C++ SOCI

今天看项目,看到一个用法

sql->once << "sqlstring..." ,into(s1),into(s2)...  不甚理解,于是问项目组的老大,老大给我讲了这个sql的用法,

说上面这个是sql语句的立即执行,然后把执行语句后查询出来的内容传到元组项s1,s2里面

然后还有比如 sql->prepare  则是把语句先缓存起来,等待一定时间之后或者积累了很多条之后,进行批处理执行

大开眼界,以前完全不知道有这样的c++的用法,找到了一些完整的概念说明和用法


SOCI is a database access library for C++ that makes the illusion of embedding SQL queries in the regular C++ code, staying entirely within the Standard C++.

The idea is to provide C++ programmers a way to access SQL databases in the most natural and intuitive way. If you find existing libraries too difficult for your needs or just distracting, SOCI can be a good alternative.

The simplest motivating code example for the SQL query that is supposed to retrieve a single row is:

int id = ...;
string name;
int salary;

sql << "select name, salary from persons where id = " << id,
       into(name), into(salary);

and the following benefits from extensive support for object-relational mapping:

int id = ...;
Person p;

sql << "select first_name, last_name, date_of_birth "
       "from persons where id = " << id,
       into(p);

Integration with STL is also supported:

Rowset<string> rs = (sql.prepare << "select name from persons");
copy(rs.begin(), rs.end(), ostream_iterator<string>(cout, "\n"));

SOCI offers also extensive integration with Boost datatypes (optional, tuple and fusion) and flexible support for user-defined datatypes.

Even though SOCI is mainly a C++ library, it also allows to use it from other programming languages. Currently the package contains the Ada binding, with more bindings likely to come in the future.

Starting from its 2.0.0 release, SOCI uses the plug-in architecture for backends - this allows to target various database servers. Currently (3.2.1), the following database systems are supported:

  • DB2
  • Firebird
  • MySQL
  • ODBC (generic backend)
  • Oracle
  • PostgreSQL
  • SQLite3

The intent of the library is to cover as many database technologies as possible. For this, the project has to rely on volunteer contributions from other programmers, who have expertise with the existing database interfaces and would like to help writing dedicated backends.



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值