本文介绍了ODBC v Libpq:PostgreSQL的C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用C库连接和使用PostgreSQL数据库,我想知道ODBC和Libpq的优缺点.据我所知,libpq似乎更快,但我无法获得任何明确的答案或基准.

I am going to be using a C library to connect and use a PostgreSQL database, I was wondering what are the pros and cons to ODBC and Libpq. From what I can tell, libpq seems to be faster but I was not able to get any clear answers or benchmarks.

此外,还有没有比ODBC/Libpq更好的其他库了.

Also, is there any other library that might be better then ODBC/Libpq.

推荐答案

如果您想要一个标准的适配器为不同的数据库使用类似的API,则ODBC很有用.我个人认为这是一个糟糕的API,但是它已经被广泛理解并且有据可查.

ODBC is useful if you want a standard adapter that speaks a similar API for different databases. I personally think it's an awful API, but it's widely understood and well documented.

libpq更直接地与PostgreSQL对话.使用它可以获得更好的性能,但可能不足以对大多数应用程序产生任何影响,这些应用程序花费时间在查询执行,网络延迟等上,而不是在客户端库中.

libpq talks more directly to PostgreSQL. You can get better performance with it, but probably not enough more that it'll make any difference for most apps, which spend time on query execution, network latency, etc, not in the client library.

psqlODBC的较新版本建立在libpq上,并用作libpq的ODBC包装器.

Newer versions of psqlODBC are built on libpq and serve as an ODBC wrapper for libpq.

还有libdbi,它提供的API比ODBC糟透了.

There's also libdbi, which offers a less ghastly API than ODBC.

为完整性起见,还有服务器后端SPI,可由用C编写的用户定义函数使用并加载到PostgreSQL服务器中.在服务器扩展和功能之外没有用.

For completeness, there's also the server-backend SPI, which can be used by user-defined functions written in C and loaded into the PostgreSQL server. It's not useful outside server extensions and functions.

哦,还有ecpg.不要使用ecpg.它是一种超传统语言集成的SQL工具,主要用于简化从某些其他数据库引擎的移植.不要使用ecpg.真的.

Oh, and there's ecpg. Don't use ecpg. It's a super-legacy language-integrated-SQL tool that exists mainly for easier porting from certain other database engines. Don't use ecpg. Really.

对于C ++,有QtSQL接口(通常对于Qt,它是可怕且痛苦的限制,不要使用它)和libpq ++(可以,但基本上不需要维护).

For C++ there's the QtSQL interface (unusually for Qt, it's awful and painfully limited, don't use it) and libpq++ (OK but largely unmaintained).

我个人直接编写libpq代码,但这是因为我正在开发通常会进入PostgreSQL本身的代码.如果您无法想象除了PostgreSQL之外还想定位其他任何东西,那么您可能想编写libpq代码.否则可能将ODBC与psqlODBC一起使用.

Personally I write libpq code directly, but that's because I'm working on code that usually goes into PostgreSQL its self. If you can't imagine ever wanting to target anything except PostgreSQL you might want to write libpq code; otherwise probably use ODBC with psqlODBC.

这篇关于ODBC v Libpq:PostgreSQL的C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 07:55