Databases/pt

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) italiano (it) 日本語 (ja) português (pt) русский (ru) 中文(中国大陆)‎ (zh_CN)

Work in progress..

Introdução

Esta página será uma introdução ao tópico "Lazarus e Banco de Dados". A tabela seguinte provê uma visão geral sobre os bancos de dados que recebem suporte. Ela precisa ser atualizada logo porque é baseada no tempo em que o FPC 1.9.7 foi publicado. Uma dica: você deve somente instalar os componentes de bancos de dados para os quais você tem as bibliotecas-cliente instaladas (se o banco de dados precisar de bibliotecas-cliente). Senão pode acontecer que o Lazarus falhe ao iniciar, por causa de arquivos faltando. Então você precisaria reinstalar o Lazarus porque desinstalar os componentes seria impossível.

Table 1

Database Package name Need client lib? Need server? Supported versions Supported platforms
Textfiles sdf No No - All
In memory memds No No - All
DBase DBFLaz No No III+, IV, VII All
FoxPro DBFLaz No No - All
Paradox TParadoxDataSet No No up to Table Level 7 (and up ??) All
SQLite SQLite Yes No - -
MySQL SQLdb Yes Yes 3 - 4.0 i386: Linux, Win32
Firebird IBase Yes Yes 1 - 1.5 i386: Linux, Win32
PostgreSQL SQLdb Yes Yes 6.6 - 8 i386: Linux, Win32
ODBC ODBC Yes Depends - i386: Win32
Interbase IBase Yes Yes 4 - 6 i386: Linux, Win32
Oracle SQLdb Yes Yes - -

The bindings to the database-clients

Se você quiser usar uma das bibliotecas de cliente de bancos de dados, suas bibliotecas precisar ser instaladas. Não só no computador em que você está fazendo o seu programa, mas também nos computadores em que os programas vão ser executados. Note que algums bancos de dados (em particular MySQL) só funcionna se os bindings qu são compilados na aplicação são da mesma versão que a das bibliotecas instaladas.

Note that some databases (in particular MySQL) only work if the bindings which are compiled in the application are from the same version as those of the installed libraries. How to install those libraries (.so files on *nix systems, and .dll's on windows) you can find on the website of the database-developers. The binding units can be found in the packages/base directory in the fpc-sources. They basically consist of the client-api calls like mysql_connect_database, which are completely different for each database. It is possible to write database applications using these units, but it is most often far more work and bug-sensitive then using the DB-unit Lazarus components.

Most of these bindings-packages are hard-linked to the client-libraries. This means that if the application is compiled with one of these units in it, the whole application can not be linked if the client libraries are not available on the workstation. This means that if you do not have installed - by example - MySQL on your computer, and you are using the mysql4.pp unit in your program. The program woud not link. If you succeed to compile the program on a computer which has MySQL installed, it still won't even start on any other workstation without the appropriate MySQL-libraries.

To avoid such problems some of the packages are also able to link dynamical to the libraries. Before any calls to those libraries can be made, the unit has to be 'initialized'. This initialization fails if the database-client isn't installed on the computer. If the program is ready using the client-library, the unit has to be 'released'.

Additional informationen about Lazarus and databases

Database packages contained in Lazarus

sqldblaz.lpk

This package provides access to different databases (e.g. MySQL or Interbase/Firebird). The components Komponenten (TSQLQuery, TSQLTransaction, TIBConnection, TODBCConnection, TOracleConnection, TMySQL40Connection, TMySQL41Connection, TMySQL50Connection, TPQConnection) are on the 'SQLdb' tab in the component palette.

dbflaz.lpk

This package provides access to dBase and FoxPro databases. You can get more information in the Lazarus Tdbf Tutorial. The TDbf component is on the 'Data Access' tab in the component palette.

interbaselaz.lpk

This package provides access to Interbase and Firebird databases. The components are similar to Delphi but far from Delphi complexity (only e components included: TIBDatabase, TIBTransaction, TIBQuery). Furthermore these components allow only a read only access. The package must be installed manually. It depends on an installed gds32.dll file (under Windows). If you install the package without this file, Lazarus fails to start. The components are on the 'Interbase' tab in the component palette.

sqlitelaz.lpk

This package provides access to SQLite databases. You can get more information in the Lazarus Database Tutorial.

sdflaz.lpk

The component TSdfDataSet can be found on the 'Data Access' tab in the component palette.

External packages / libraries

Zeos library

This library provides access to different databases. Information about the interaction between Zeos and Lazarus can be found in the Zeos tutorial.

Pascal Data Objects

There is now an alternative. The functions introduced with MySQL 4.1 and 5.0 like prepared statements, binding, and stored procedures are supported by database API called Pascal Data Objects, which is inspired by PHP Data Objects. All the code and documentation necessary to use this new API is available on Sourceforge:

http://pdo.sourceforge.net

Jan 30, 2007: PDO has added drivers for Firebird 1.5 and Firebird 2.0

TPSQL

These components provide access via TCP/IP to PostgreSQL databases. You can find more information on this page.

FIBL

These components provide access to Interbase and Firebird databases. The homepage is http://sourceforge.net/projects/fibl.

FBLib Firebird Library

FBLib is an open Source Library No Data Aware for direct access to Firebird Relational Database from Borland Delphi / Kylix, Freepascal and Lazarus.

Current Features include:

  • Direct Access to Firebird 1.0.x 1.5.x Classic or SuperServer
  • Multiplatform [Win32,Gnu/Linux,FreeBSD)
  • Automatic select client library 'fbclient' or 'gds32'
  • Query with params
  • Support SQL Dialect 1/3
  • LGPL License agreement
  • Extract Metadata
  • Simple Script Parser
  • Only 100-150 KB added into final EXE
  • Support BLOB Fields
  • Export Data to HTML SQL Script
  • Service manager (backup,restore,gfix...)
  • Events Alerter

You can download documentation on FBLib's website.

TechInsite Object Persistence Framework (tiOPF)

More informationen about tiOPF can be found on this page.

LazReport

The homepage of the report generator is http://lazreport.sourceforge.net/. More informationen (et al. an additional link) can be found here. LazReport depends on the Printer4Lazarus package.