【原創】如何在 libgda 和 SQLite 之間做出選擇

How to choose between Libgda and SQLite
如何在 libgda 和 SQLite 之間做出選擇

(本文爲 官方文檔 翻譯,以中英對照形式呈現)

Libgda has been added as a new external dependency for GNOME 2.26, with now two database libraries: Libgda and SQLite.
libgda 已做爲一個新外部依賴項被添加到 GNOME 2.26 中了,如此就出現了 libgda 和 SQLite 並存的局面。


This page offers some hints about how to make the choice between the two when writing an application which needs to store/access some data in a database.
本篇文章針對編寫須要進行存儲/訪問數據庫的應用程序時,如何在上述二者之間做出選擇給出了一些建議。


Comparison hints
差別方面

  • Of course if you want to either be able to access different databases types or you think you may need to in the future, Libgda is a better choice because with SQLite you can only access SQLite files. The comparison makes sense only if you want to create an SQLite database and have to decide between Libgda and SQLite to do it. Note that Libgda uses SQLite internally anyway (it's not a reimplementation) to access SQLite files.
  • 若是你打算在如今就可以訪問多種數據庫類型,或者你認爲在未來須要這麼作,libgda 是你的不二之選,由於 SQLite 只提供了對 SQLite 文件的訪問。上述的比較是基於這樣一個前提:你打算建立一個 SQLite 數據庫,而且在 libgda 和 SQLite 之間作出選擇。值得注意的是,libgda 在自身內部使用了 SQLite (並不是從新實現,而是使用)來訪問 SQLite 文件。

  • Dependencies point of view: if you want very few dependencies, SQLite is a better choice as it has no dependency whereas Libgda depends on GLib and LibXML2.
  • 從依賴性的角度:若是你指望軟件包的安裝依賴少,那麼 SQLite 是更好的選擇,由於它沒有任何其餘依賴,而 libgda 依賴於 GLib 和 LibXML2 。

  • Data access point of view: SQLite only allows reading data using a forward moving cursor, and Libgda allows you to choose between that mode and a random access data access mode (some caching is done). This point is important if you need to run a SELECT statement once and use the results several times.
  • 從數據訪問的角度:SQLite 僅支持經過前向移動指針來進行數據讀取,而 libgda 容許你在前向模式和隨機訪問模式(經過一些緩存策略實現)之間進行選擇。當你須要運行一次 SELECT 語句後屢次使用其返回結果時,後者的功能是重要的。

  • Low level control point of view: if you need some very specific SQLite features, then it's better to use SQLite as Libgda does not allow you to access SQLite's API direclty.
  • 從控制級別的角度:若是你須要使用某些特殊的 SQLite 特性,那麼你最好仍是直接使用 SQLite ,由於 libgda 不容許你直接對 SQLite API 進行訪問。

  • Additionnal features point of view: Libgda offers much more than just a wrapper around SQLite (or other database's APIs), if you need them, it's better to use Libgda than to reimplement them yourself.
  • 從附加特性的角度:libgda 所提供的功能遠遠不止對 SQLite API 的封裝(或者其餘數據庫 API),若是你須要這些附加功能,使用 libgda 絕對是你的首選,由於你不須要本身從新造輪子了。

  • Raw performances point of view: by design SQLite is better (but not by much).
  • 從性能表現的角度:在某些方面 SQLite 可能會更好(但也沒好那麼多)。

  • Data types point of view: Libgda (as most if not all databases engines) impose that for each column in each table the data be of the same type. SQLite does not impose this restriction (this means that for each row, the data in a column can be of a different type and it's up to the programmer to handle that).
  • 從數據類型的角度:libgda (像大多數數據庫引擎同樣)強制要求在表中每一列的數據必須具備相同的類型。SQLite 並無此限制(意味着,對於每一行而言,存在於某列中的數據可能具備不一樣的類型,取決於程序員如何處理)。


One important thing to keep in mind is that changing from using SQLite to using Libgda (or the other way around) can be a long an painfull experience, so you need to make sure you choose the right one right from the beginning.
須要銘記於心的一件事:將使用 SQLite 的代碼轉變爲使用 libgda (或者相反),將是一個漫長而痛苦的過程。因此你最好從一開始就確保你的選擇是明智的。


Common points
共性方面


Here are some (more or less) common points between Libgda and SQLite:
下面是 libgda 和 SQLite 之間的一些共性方面:

  • both work on all major OSes (Linux/Unix, Windows, MacOS)
  • 二者都可在大多數操做系統上工做(Linux/Unix, Windows, MacOS)

  • both are easy to use in the compilation process thanks to pkg-config
  • 二者從編譯的角度來說都算易於使用(基於pkg-config)

  • both are well maintained
  • 二者都獲得了很好的開發維護


Libgda's features SQLite does not have
SQLite 所不具備的 libgda 的特性


SQLite is a database engine implementation, and as such it's not meant to compete feature for feature with database abstraction libraries like Libgda, ODBC or JDBC. However it's important to know what features are implemented in Libgda which you may need to implement yourself in your application if you use SQLite directly.
SQLite 是一個數據庫引擎實現,正由於如此,其並不打算與 Libgda、ODBC 或 JDBC 一類的數據庫抽象庫進行各類特性比較。然而,你須要明確知道的是哪些特性在 libgda 中被實現了,而當你直接使用 SQLite 的時候卻須要你本身在程序中實現。

Those features are:
這些特性包括:

  • meta data retreival: obtaining information about database objects such as the tables and their columns, the triggers,...
  • 元數據獲取:獲取數據庫對象的信息,如表信息,表中的列信息,觸發器信息,等等

  • multi-threaded access to connections
  • 多線程同時對 connection 進行訪問

  • SQL parser
  • SQL 解析器

  • loading and saving XML or CSV files
  • 加載和保存 XML 或者 CSV 文件

  • UI interface to the data: even though it's not (yet) part of Libgda, Libgnomedb implements some data bound widgets
  • 訪問數據的 UI 接口:儘管這個尚不屬於 libgda 的一部分,libgnomedb 已實現了一些與數據綁定有關的小程序。
相關文章
相關標籤/搜索