测试linux 的 libodb.根据官网案例创建项目 http://www.codesynthesis.com/products/odb/
ODB是应用于C++的一个开源、跨平台、跨数据库的对象关系映射(ORM)系统。
它可以让你持久化C++对象到关系数据库,而不必处理表、列或者SQL,无需手动编写任何映射代码。
ODB支持MySQL,SQLite,PostgreSQL,Oracle和微软SQL Server关系数据库以及C ++98/03和C ++11语言标准。
它还配备了用于Boost和Qt可选的配置文件,让你可以无缝地使用这些库持久化C++类的值类型、容器和智能指针。
它有易用性,简洁的代码,安全,数据库可移植性,优良的性能,可维护性等优点。
总之它具有完善的学习文档的非常棒的C++的ORM框架。
person-odb.hxx
person-odb.ixx
person-odb.cxx
person.sql
使用命名:odb -d <database> --generate-query --generate-schema person.hxx
<database>是数据类型如:mysql
如:odb -d mysql --generate-query --generate-schema person.hxx
//用户名、密码、数据库名称等默认是运行时,数据连接参数
auto_ptr<database> db (new odb::mysql::database ("root", "201314", "odb"));
apt install odb
安装libodb-2.4/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-boost-2.4/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-boost-dev/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-dev/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-mysql-2.4/lion,now 2.4.0-3 amd64 [已安装,自动]
libodb-mysql-dev/lion,now 2.4.0-3 amd64 [已安装]
libodb-pgsql-2.4/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-pgsql-dev/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-qt-2.4/lion,now 2.4.0-2+b1 amd64 [已安装,自动]
libodb-qt-dev/lion,now 2.4.0-2+b1 amd64 [已安装,自动]
libodb-sqlite-2.4/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
libodb-sqlite-dev/lion,now 2.4.0-1+b1 amd64 [已安装,自动]
odb/lion,now 2.4.0-5+b1 amd64 [已安装]
odb命名: -I
Add to the beginning of the list of directories to be searched for included header files. 将添加到要搜索包含头文件的目录列表的开头。--database|-d Generate code for the database. 为数据库生成代码。 --generate-query|-q Generate query support code 生成查询支持代码
--generate-prepared Generate prepared query execution support code. 生成准备好的查询执行支持代码。
--generate-session|-e Generate session support code. 生成会话支持代码。
--generate-schema|-s Generate the database schema. 生成数据库架构。 --generate-schema-only Generate only the database schema. 仅生成数据库架构。 --generate-prepared --omit-unprepared
--profile|-p Specify a profile that should be used during compilation. 指定编译期间应使用的配置文件。
--std Specify the C++ standard that should be used during compilation.
odb -d mysql --profile qt --generate-schema --generate-query --generate-session employee.hxx 无法编译 错误:
In file included from <odb-prologue-2>:1:0:
/usr/include/odb/qt/basic/mysql/default-mapping.hxx:8:26: fatal error: QtCore/QString: 没有那个文件或目录
#include <QtCore/QString>
^
compilation terminated.
修改命名: odb --database sqlite --profile qt --generate-schema --generate-query --generate-session -I/media/zlf/_dde_data/Qt5.12.3/5.12.3/gcc_64/include employee.hxx
Qt头文件编译错误 加入 --std c++11 Qt编译错误 -DQT_BOOTSTRAPPED 最终执行命名 odb -I /usr/include/x86_64-linux-gnu/qt5 --std c++11 -DQT_BOOTSTRAPPED -d mysql --profile qt --generate-schema --generate-query --generate-session employee.hxx
在进行查询时条件过滤(分页)时, 生成sql异常
修改代码后正常:
typedef odb::query<NoteTree> query;
typedef odb::result<NoteTree> result;
//有条件,将所有数据排序.也可以进行分页
query b(query::type == 1);
result r(db->query<NoteTree>(query(b) + " ORDER BY" + query::id + "desc", true));
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。