简体   繁体   English

C ++ ODB支持不同的DBMS

[英]C++ ODB Support Different DBMS

I have been looking at ODB ORM for some time now and had some practice with it. 我一直在研究ODB ORM已有一段时间,并对其进行了一些练习。 My problem is switching between different DBMS recompiling the code. 我的问题是在不同的DBMS之间重新切换代码。 From my Java background, I can simply change a config file and the ORM works eg Hibernate. 从我的Java背景,我可以简单地更改一个配置文件,而ORM可以运行,例如Hibernate。 This far I can compile the 'hello' example under 'odb-examples-2.2.0.tar.gz' and connect to MySQL and PostgreSQL successfully. 至此,我可以在“ odb-examples-2.2.0.tar.gz”下编译“ hello”示例,并成功连接到MySQL和PostgreSQL。

Please share your ways of resolving this. 请分享解决此问题的方法。 Code samples would also be very helpful. 代码示例也将非常有帮助。 I would like to simply change databases by say changing a config file. 我只想通过说说更改配置文件来更改数据库。 This far, referring to the manual has not helped yet. 到目前为止,参考手册还没有帮助。 My system needs to be cross-platform. 我的系统需要跨平台。

Thanks. 谢谢。

If dynamic support is sufficient for you, then the following example will do the trick. 如果动态支持足以满足您的需求,那么下面的示例即可解决问题 The following command line is needed before compiling the other files : 编译其他文件之前,需要以下命令行:

odb --std c++11 --multi-database dynamic -d common -d mysql -d sqlite \
--generate-query --generate-schema person.hxx

In my example I'm using the command line as they did in the manual (2.10). 在我的示例中,我像在手册(2.10)中一样使用命令行。 From what I've read, while you're using the odb::query, odb::transaction, you don't need to do anything else special to work with multiple databases. 根据我的阅读,当您使用odb :: query,odb :: transaction时,无需执行其他任何特殊操作即可使用多个数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM