Lazarus Database Overview/ru

From Lazarus wiki
Jump to navigationJump to search

English (en) español (es) français (fr) 日本語 (ja) polski (pl) русский (ru)

Databases portal

References:

Tutorials/practical articles:

Databases

Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos

Обзор

Эта статья представляет собой обзор баз данных, которые могут работать с Lazarus.

Lazarus поддерживает несколько баз данных "из коробки" (используя, например, фреймворк SQLDB), однако разработчик должен установить необходимые пакеты (клиентские библиотеки) для каждой из них дополнительно.

Вы можете получить доступ к базе данных посредством кода или путем добавления компонентов на форму. Data-aware компоненты предоставляют поля и подсоединяются путем установки свойства DataSource (Источник данных) для указания на TDataSource. Datasource представляет собой таблицу и подключается к компонентам базы данных (примеры: TPSQLDatabase, TSQLiteDataSet) путем установки свойства DataSet. Компоненты, учитывающие данные, расположены на вкладке Data Controls. Источник данных и элементы управления базой данных расположены на вкладке Data Access.

См. руководства встроенных в Lazarus/FPC компонентов доступа к базам данных, подходящих для Firebird, MySQL, SQLite, PostgreSQL и т.д.:

Lazarus и Interbase / Firebird

  • Firebird очень хорошо поддерживается "из коробки" FPC/Lazarus (с использованием SQLDB); пожалуйста, смотрите Firebird для получения подробностей.
  • Другие библиотеки Firebird имеют список альтернативных библиотек доступа (например, PDO, Zeos, FBlib)

Lazarus и MySQL

  • Пожалуйста, см. раздел mysql для получения подробностей по деталям различных методов доступа, которые включают:
  1. Встроенную поддержку SQLdb
  2. PDO
  3. Zeos
  4. MySQL data access Lazarus components

Lazarus и MSSQL/Sybase

Вы можете подключиться к базам данных Microsoft SQL Server, используя

  1. SQL Server data access Lazarus components. Они работают на Windows и Mac OS X. Бесплатны для загрузки.
  2. Встроенные SQLdb компоненты подключения к БД TMSSQLConnection и TSybaseConnection (начиная с Lazarus 1.0.8/FPC 2.6.2): см. Mssqlconn.
  3. Zeos компонент TZConnection (последний CVS, см. ссылки на Zeos в других местах на этой странице)
    1. На Windows вы можете выбрать между собственной библиотекой ntwdblib.dll (протокол mssql) или библиотеками FreeTDS (протокол FreeTDS_MsSQL-nnnn), где nnnn - один из четырех вариантов в зависимости от версии сервера. Для Delphi (не для Lazarus) существует также другой протокол Zeos ado для MSSQL 2005 или более поздней версии. При использовании протоколов mssql или ado генерируется платформонезависимый код.
    2. На Linux единственный способ - использовать протоколы и библиотеки FreeTDS (вы должны использовать libsybdb.so).
  4. ODBC (MSSQL и Sybase ASE) со SQLdb TODBCConnection (рассмотрите использование TMSSQLConnection и TSybaseConnection в качестве альтернативы)
    1. См. также Connecting to Microsoft SQL Server
    2. На Windows он использует собственные библиотеки ODBC Microsoft (например, sqlsrv32.dll для MSSQL 2000)
    3. На Linux он использует unixODBC + FreeTDS (пакеты unixodbc или iodbc, и tdsodbc). С 2012 года существует также драйвер ODBC для Microsoft SQL Server 1.0 для Linux, который является бинарным продуктом (без открытого исходного кода) и обеспечивает собственное подключение, но выпущен только для х64 и только для RedHat.

Lazarus и ODBC

ODBC - это общий стандарт подключения к базе данных, который доступен в Linux, Windows и OSX. Вам потребуется драйвер ODBC от поставщика базы данных и надстройка ODBC "data source" (также известный как DSN). Вы можете использовать компоненты SQLDB (TODBCConnection) для подключения к источнику данных ODBC. Смотрите ODBCConn для получения более подробной информации и примеров.

Microsoft Access

Вы можете использовать драйвер ODBC в Windows и Linux для доступа к базам данных Access; см. MS Access

Lazarus и Oracle

  • См. Oracle. Методы доступа включают в себя:
  1. Встроенную поддержку SQLDB
  2. Zeos
  3. Oracle data access Lazarus component

Прим.перев.: девартовский сайт почему-то внесен список спам-фильтра. Поэтому в выше приведенной ссылке удалите пробел из dev_art, чтобы перейти на оф.сайт ODAC

Lazarus and PostgreSQL

  • PostgreSQL is very well supported out of the box by FPC/Lazarus
  • Please see postgres for details on various access methods, which include:
  1. Built-in SQLdb support. Use component TPQConnection from the SQLdb tab of the Component Palette
  2. Zeos. Use component TZConnection with protocol 'postgresql' from palette Zeos Access
  3. PostgreSQL data access Lazarus component

Lazarus and SQLite

SQLite is an embedded database; the database code can be distributed as a library (.dll/.so/.dylib) with your application to make it self-contained (comparable to Firebird embedded). SQLite is quite popular due to its relative simplicity, speed, small size and cross-platform support.

Please see the SQLite page for details on various access methods, which include:

  1. Built-in SQLDb support. Use component TSQLite3Connection from palette SQLdb
  2. Zeos
  3. SQLitePass
  4. TSQLite3Dataset
  5. SQLite data access Lazarus components

Lazarus and Firebird/Interbase

InterBase (and FireBird) Data Access Components (IBDAC) is a library of components that provides native connectivity to InterBase, Firebird and Yaffil from Lazarus (and Free Pascal) on Windows, Mac OS X, iOS, Android, Linux, and FreeBSD for both 32-bit and 64-bit platforms. IBDAC-based applications connect to the server directly using the InterBase client. IBDAC is designed to help programmers develop faster and cleaner InterBase database applications.

IBDAC is a complete replacement for standard InterBase connectivity solutions. It presents an efficient alternative to InterBase Express Components, the Borland Database Engine (BDE), and the standard dbExpress driver for access to InterBase.

Firebird data access components for Lazarus are free to download.

Lazarus and dBase

FPC includes a simple database component that is derived from the Delphi TTable component called "TDbf" TDbf Website). It supports various DBase and Foxpro formats.

TDbf does not accept SQL commands but you can use the dataset methods etc and you can also use regular databound controls such as the DBGrid.

It doesn't require any sort of runtime database engine. However it's not the best option for large database applications.

See the TDbf Tutorial page for the tutorial as well as documentation.

You can use e.g. OpenOffice/LibreOffice Base to visually create/edit dbf files, or create DBFs in code using TDbf.

Lazarus and Paradox

Paradox was the default format for database files in old versions of Delphi. The concept is similar to DBase files/DBFs, where the "database" is a folder, and each table is a file inside that folder. Also, each index is a file too. To access this files from Lazarus we have these options:

  • TParadox: Install package "lazparadox 0.0" included in the standard distribution. When you install this package, you will see a new component labeled "PDX" in the "Data Access" palette. This component is not standalone, it uses a "native" library, namely the pdxlib library which is available for Linux and Windows. For example, to install in Debian, you could get pxlib1 from package manager. In Windows you need the pxlib.dll file.
  • TPdx: Paradox DataSet for Lazarus and Delphi from this site. This component is standalone (pure object pascal), not requiring any external library, but it can only read (not write) Paradox files. The package to install is "paradoxlaz.lpk" and the component should appear in the "Data Access" palette with PDX label (but orange colour).
  • TParadoxDataSet: is a TDataSet that can only read Paradox Files up to Version 7. The approach is similar to the TPdx component, the package to install is "lazparadox.lpk" and the component should also appear in the "Data Access" palette.

TSdfDataset and TFixedDataset

TSdfDataSet and TFixedFormatDataSet are two simple TDataSet descandants which offer a very simple textual storage format. These datasets are very convenient for small databases, because they are fully implemented as an Object Pascal unit, and thus require no external libraries. Also, their textual format allows them to be easily viewed/edited with a text editor.

See CSV for example code.

Lazarus and Advantage Database Server

See also

(Sorted alphabetically)

External links

  • Pascal Data Objects - a database API that worked for both FPC and Delphi and utilises native MySQL libraries for version 4.1 and 5.0 and Firebird SQL 1.5, and 2.0. It's inspired by PHP's PDO class.
  • Zeos+SQLite Tutorial - Good tutorial using screenshots and screencasts it explain how to use SQLite and Zeos, spanish (google translate does a good work in translating it to english)