跨平台SQL DB API c/c++

时间:2022-05-31 02:38:00

I am writing a database application in C linux. Currently I work on mysql but later we might migrate to postgres. Therefore my boss has asked my to prepare the application to be able to use either of the databases(mysql or postgres).

我正在用C linux编写一个数据库应用程序。目前我在使用mysql,但稍后我们可能会迁移到postgres。因此,我的老板要求我准备应用程序,以便能够使用数据库(mysql或postgres)。

Is there a free api which I can use for this purpose? Or any suggestion on how best I can do this?

是否有一个免费的api可以用于此目的?或者有什么建议我能做得最好?

2 个解决方案

#1


2  

The official answer to that is ODBC.

官方的答案是ODBC。

If you don't like that (and let's face it, no one really does), Qt has a database access module, QtSql. Obviously, this will require you to make heavy use of Qt in your application.

如果您不喜欢它(让我们面对它,没有人真正喜欢它),Qt有一个数据库访问模块QtSql。显然,这要求您在应用程序中大量使用Qt。

#2


1  

If you can find drivers for your platform, ODBC was supposedly meant to provide exactly this: a platform-independent way to talk to databases.

如果您能够找到平台的驱动程序,那么ODBC应该能够提供这样的功能:一种与平台无关的方式来与数据库对话。

(I say supposedly because in my experience, ODBC is such a mess that hooking up to an ODBC driver once turned out to be more difficult than just writing the code three times for three different databases.)

(我之所以这么说,可能是因为以我的经验来看,ODBC是如此的混乱,以至于连接到ODBC驱动程序之前要比仅仅为三个不同的数据库编写代码三次要困难得多。)

#1


2  

The official answer to that is ODBC.

官方的答案是ODBC。

If you don't like that (and let's face it, no one really does), Qt has a database access module, QtSql. Obviously, this will require you to make heavy use of Qt in your application.

如果您不喜欢它(让我们面对它,没有人真正喜欢它),Qt有一个数据库访问模块QtSql。显然,这要求您在应用程序中大量使用Qt。

#2


1  

If you can find drivers for your platform, ODBC was supposedly meant to provide exactly this: a platform-independent way to talk to databases.

如果您能够找到平台的驱动程序,那么ODBC应该能够提供这样的功能:一种与平台无关的方式来与数据库对话。

(I say supposedly because in my experience, ODBC is such a mess that hooking up to an ODBC driver once turned out to be more difficult than just writing the code three times for three different databases.)

(我之所以这么说,可能是因为以我的经验来看,ODBC是如此的混乱,以至于连接到ODBC驱动程序之前要比仅仅为三个不同的数据库编写代码三次要困难得多。)