Difference between revisions of "Databases"

From Lazarus wiki
Jump to navigationJump to search
(database overview table)
Line 2: Line 2:
  
 
Work in progress..
 
Work in progress..
=Introduction=
 
  
This page is about creating databases applications with Lazarus using the DB-unit. In the DB unit all the basic functionality for working with databases is implemented, but to be usefull they need components which are dependent on the database you want to use.
+
== Introduction ==
  
The first part gives a short introduction on the several database-dependent components and how to install them, the second part is a short course in working with the DB-unit and the last part gives specific information about several supported databases.
+
Wie bei anderen Entwicklungssystemen auch spielt die Zusammenarbeit mit verschiedenen Datenbanken bei Lazarus eine nicht unbedeutende Rolle. Während ein Teil der Funktionalität schon mit FPC zur Verfügung steht, kommen andere Teile (insbesondere die visuellen Komponenten) erst mit Lazarus selbst hinzu. Die bei Lazarus enthaltenen Komponenten decken schon ein gewisses Spektrum an Datenbanken ab. Da aber immer Verbesserungsbedarf besteht und es auch exotischere Datenbanken gibt, existieren externe Komponenten / Bibliotheken, welche die Möglichkeiten von Lazarus erweitern.  
  
=First Part: General information about supported databases=
+
This page will be an entrance to the topic 'Lazarus and databases'. The following table provides an overview about the supported databases. She needs to be updated soon, because she is based on the time, when FPC 1.9.7 was released. One hint: You should only install the database components, for which you have the client libraries installed (if the database need client libaries). Otherwise it could happen, that Lazarus fails to start (because of missing files). Then you would have to reinstall Lazarus, because the uninstalling of the component isn't possible.
  
==Introduction==
+
=== Table 1 ===
 
 
The databases you can use with Lazarus, (actually with FPC, but that's not so important for the rest of the story) can be divided into two categories: The databases which are completely 'internal' and are written in Freepascal, and the 'external' databases to which connections are made with client-libraries. To use these client-libraries the appropiate bindings must be available. Most client-libraries come only with bindings for C, but FPC provides several packages with the pascal-bindings for database-clients. The supported databases are listed in table 1. (fpc 1.9.7 and above)
 
 
 
===Database Technologies Overview===
 
 
{| BORDER="1" CELLSPACING="0"
 
{| BORDER="1" CELLSPACING="0"
 
!STYLE="background:#ffdead;"|'''Database'''
 
!STYLE="background:#ffdead;"|'''Database'''
Line 27: Line 22:
 
|'''In memory'''||memds||No||No|| - || All
 
|'''In memory'''||memds||No||No|| - || All
 
|----
 
|----
|'''DBase'''||[[Lazarus_Tdbf_Tutorial | tDbf]]||No||No|| III+, IV, VII || All
+
|'''DBase'''||[[Lazarus_Tdbf_Tutorial | DBFLaz]]||No||No|| III+, IV, VII || All
 
|----
 
|----
|'''FoxPro'''||[[Lazarus_Tdbf_Tutorial | tDbf]]||No||No|| - || All
+
|'''FoxPro'''||[[Lazarus_Tdbf_Tutorial | DBFLaz]]||No||No|| - || All
 
|----
 
|----
 
|[http://www.sqlite.org/ '''SQLite''']||SQLite||Yes||No|| - || -
 
|[http://www.sqlite.org/ '''SQLite''']||SQLite||Yes||No|| - || -
 
|----
 
|----
|[http://www.mysql.com/ '''MySQL''']||MySQL||Yes||Yes|| 3 - 4.0 || i386: Linux, Win32
+
|[http://www.mysql.com/ '''MySQL''']||SQLdb||Yes||Yes|| 3 - 4.0 || i386: Linux, Win32
 
|----
 
|----
 
|[http://www.firebirdsql.org/ '''Firebird''']||IBase||Yes||Yes||1 - 1.5|| i386: Linux, Win32
 
|[http://www.firebirdsql.org/ '''Firebird''']||IBase||Yes||Yes||1 - 1.5|| i386: Linux, Win32
 
|----
 
|----
|[http://www.postgresql.org/ '''PostgreSQL''']||postgres||Yes||Yes|| 6.6 - 8 || i386: Linux, Win32
+
|[http://www.postgresql.org/ '''PostgreSQL''']||SQLdb||Yes||Yes|| 6.6 - 8 || i386: Linux, Win32
 
|----
 
|----
 
|'''ODBC'''||ODBC||Yes||Depends|| - || i386: Win32
 
|'''ODBC'''||ODBC||Yes||Depends|| - || i386: Win32
Line 43: Line 38:
 
|[http://www.borland.com/us/products/interbase/index.html '''Interbase''']||IBase||Yes||Yes||4 - 6|| i386: Linux, Win32
 
|[http://www.borland.com/us/products/interbase/index.html '''Interbase''']||IBase||Yes||Yes||4 - 6|| i386: Linux, Win32
 
|----
 
|----
|[http://www.oracle.com/ '''Oracle''']||Oracle||Yes||Yes|| - || -  
+
|[http://www.oracle.com/ '''Oracle''']||SQLdb||Yes||Yes|| - || -  
 
|}
 
|}
  
Line 54: Line 49:
 
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'.
 
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'.
  
== The database-components in Lazarus ==
+
== Additional informationen about Lazarus and databases ==
 +
 
 +
* FAQ: [[Lazarus DB Faq|Lazarus database FAQ]]
 +
* Tutorial: [[Lazarus Database Tutorial]]
 +
* MySQL: [[MySQLDatabases]]
 +
* Firebird: [[Firebird in action]]
 +
 
 +
== Differences to Delphi ==
 +
 
 +
Der vielleicht wichtigste Vorteil von Lazarus gegenüber Delphi ist die Plattformunabhängigkeit. Das bedeutet auf der anderen Seite, daß es für die Windows-spezifischen Teile bei Delphi (z.B. die BDE) keine direkten Entsprechungen bei Lazarus gibt. Gleiches gilt für die meisten Reporting-Werkzeuge. Bei der Konvertierung eines Delphiprogramms nach Lazarus sollte man auf die verschiedenen Dateisysteme achten, wenn das Programm auf allen von Lazarus unterstützten Plattformen laufen soll. Als Beispiel möchte ich nur die unterschiedlichen Trennzeichen im Pfadnamen ( \ bzw. / ) nennen.
 +
 
 +
== Database packages contained in Lazarus ==
 +
 
 +
=== sqldblaz.lpk ===
 +
Dieses Package bietet Zugriff auf verschiedene Datenbanken (z.B. MySQL oder Interbase/Firebird). Das Package wird standardmäßig mit Lazarus installiert (unter Windows). Die Komponenten (TSQLQuery, TSQLTransaction, TIBConnection, TODBCConnection, TOracleConnection, TMySQL40Connection, TMySQL41Connection, TMySQL50Connection, TPQConnection) befinden sich auf der 'SQLdb' Seite in der Komponentenpalette.
 +
 
 +
=== 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 ===
 +
Dieses Package bietet Zugriff auf Interbase und Firebird Datenbanken. Es ist den Komponenten bei Delphi nachempfunden, aber bei weitem nicht so umfangreich (enthält nur 3 Komponenten: TIBDatabase, TIBTransaction, TIBQuery). Außerdem erlauben diese Komponenten nur einen Lesezugriff. Das Package muß manuell installiert werden. Voraussetzung dafür ist das Vorhandensein der gds32.dll Datei (unter Windows). Fehlt diese, läßt sich Lazarus nach der Installation des Packages nicht mehr starten. Die Komponenten befinden sich auf der 'Interbase' Seite in der Komponentenpalette.
 +
 
 +
=== sqlitelaz.lpk ===
 +
Dieses Package bietet Zugriff auf SQLite Datenbanken. Weitere Informationen sind im [[Lazarus Database Tutorial/de|Lazarus Database Tutorial]] zu finden.
 +
 
 +
=== sdflaz.lpk ===
 +
Das Package wird standardmäßig mit Lazarus installiert. Die Komponente TSdfDataSet befindet sich auf der 'Data Access' Seite in der Komponentenpalette.
 +
 
 +
== External packages / libraries ==
 +
 
 +
=== Zeos library ===
 +
Diese Bibliothek bietet Zugriff auf verschiedene Datenbanken. Informationen zum Zusammenspiel von Zeos und Lazarus finden sie im [[Zeos tutorial/de|Zeos Tutorial]].
 +
 
 +
=== Pascal Data Objects ===
 +
Die Pascal Data Objects sind von Zeoslib abgeleitet. Es werden die mit MySQL 4.1 und 5.0 eingeführten Funktionen wie prepared statements, binding, und stored procedures von der Datenbank-API namens Pascal Data Objects unterstützt, die durch die PHP Data Objects inspiriert wurde.  Der für die Verwendung dieser neuen API notwendige Code und die Dokumentation sind ein einem Trac wiki zu finden:
 +
 
 +
https://trac.synsport.com:8000/index.php/pdo/wiki (Benutzername/Passwort sind guest/guest)
 +
 
 +
--[[User:Jrmarino|Jrmarino]] 11:28, 13 Mar 2006 (CET)
  
= Second part: Using the components in the DB unit =
+
=== TPSQL ===
 +
These components provide access via TCP/IP to PostgreSQL databases. You can find more information on [[TPSQL|this page]].
  
This section gives a short tutorial which holds for all the databases based on the db unit. Before you can use the db-unit, a database-component has to be installed. As an example tDbf is used, but every TDataset descendent could be used.
+
=== FIBL ===
 +
Diese Komponenten bieten Zugriff auf Interbase und Firebird Datenbanken. Die Homepage ist [http://sourceforge.net/projects/fibl http://sourceforge.net/projects/fibl].
  
'''Step one:'''
+
=== FBLib Firebird Library ===
Create a new Lazarus aplication
 
  
'''Step two:'''
+
[http://fblib.altervista.org/ FBLib] is an Open Source library (not data-sensitive) for a direct access to Firebird databases. It supports Borland Delphi / Kylix, Freepascal and Lazarus. It could be uncommonly for many users, that there is no connection via the TDatasource component.
Drop a [[Lazarus_Tdbf_Tutorial | tDBF component]] (or any other TDataset descendent, of course) on your form. This TDataset-(descendent) is to access the data in a table or query.  
 
  
'''Step three:'''
+
Gegenwärtig sind folgende Features enthalten:
Drop a TDatasource component on your form. The TDataset is to access the data in a table or query, the TDatasource is the 'link' between the TDataset and the visible components on the form, like a TDBEdit. Link the dataset and the datasource to each other by setting the 'Dataset' property of the TDatasource to the TDataset. (In this case: Dbf1)
 
  
 +
* Direkter Zugriff auf Firebird 1.0.x 1.5.x Classic oder SuperServer
 +
* Multiplattform [Win32,Gnu/Linux,FreeBSD)
 +
* Automatische Auswahl der Client Bibliothek 'fbclient' oder 'gds32'
 +
* Abfragen (Queries) mit Parametern
 +
* Unterstützt SQL Dialekt 1/3
 +
* LGPL Lizenzvertrag
 +
* Extrahieren von Metadaten
 +
* Simple Script Parser
 +
* Nur 100-150 KB werden zur finalen EXE hinzugefügt
 +
* Unterstützt BLOB Felder
 +
* Export von Daten als HTML SQL Script
 +
* Service manager (backup,restore,gfix...)
 +
* Events Alerter
  
 +
Sie können die Dokumentation von der [http://fblib.altervista.org/|FBLib Webseite] herunterladen.
  
 +
=== TechInsite Object Persistence Framework (tiOPF) ===
 +
More informationen about tiOPF can be found on this [[tiOPF|page]].
  
--[[User:Loesje|Loesje]] 14:39, 10 Feb 2005 (PST)
+
=== LazReport ===
 +
The homepage of the report generator is [http://lazreport.sourceforge.net/ http://lazreport.sourceforge.net/].
 +
More informationen (et al. an additional link) can be found [[Projects_using_Lazarus#LazReport| here]].
 +
LazReport depends on the Printer4Lazarus package.

Revision as of 20:34, 30 October 2006

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

Work in progress..

Introduction

Wie bei anderen Entwicklungssystemen auch spielt die Zusammenarbeit mit verschiedenen Datenbanken bei Lazarus eine nicht unbedeutende Rolle. Während ein Teil der Funktionalität schon mit FPC zur Verfügung steht, kommen andere Teile (insbesondere die visuellen Komponenten) erst mit Lazarus selbst hinzu. Die bei Lazarus enthaltenen Komponenten decken schon ein gewisses Spektrum an Datenbanken ab. Da aber immer Verbesserungsbedarf besteht und es auch exotischere Datenbanken gibt, existieren externe Komponenten / Bibliotheken, welche die Möglichkeiten von Lazarus erweitern.

This page will be an entrance to the topic 'Lazarus and databases'. The following table provides an overview about the supported databases. She needs to be updated soon, because she is based on the time, when FPC 1.9.7 was released. One hint: You should only install the database components, for which you have the client libraries installed (if the database need client libaries). Otherwise it could happen, that Lazarus fails to start (because of missing files). Then you would have to reinstall Lazarus, because the uninstalling of the component isn't possible.

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
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

If you want to use one of the databases-client libraries, those libraries has to be installed. Not only on the computer where you're programming on, but also on the computes where the application must run at. 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

Differences to Delphi

Der vielleicht wichtigste Vorteil von Lazarus gegenüber Delphi ist die Plattformunabhängigkeit. Das bedeutet auf der anderen Seite, daß es für die Windows-spezifischen Teile bei Delphi (z.B. die BDE) keine direkten Entsprechungen bei Lazarus gibt. Gleiches gilt für die meisten Reporting-Werkzeuge. Bei der Konvertierung eines Delphiprogramms nach Lazarus sollte man auf die verschiedenen Dateisysteme achten, wenn das Programm auf allen von Lazarus unterstützten Plattformen laufen soll. Als Beispiel möchte ich nur die unterschiedlichen Trennzeichen im Pfadnamen ( \ bzw. / ) nennen.

Database packages contained in Lazarus

sqldblaz.lpk

Dieses Package bietet Zugriff auf verschiedene Datenbanken (z.B. MySQL oder Interbase/Firebird). Das Package wird standardmäßig mit Lazarus installiert (unter Windows). Die Komponenten (TSQLQuery, TSQLTransaction, TIBConnection, TODBCConnection, TOracleConnection, TMySQL40Connection, TMySQL41Connection, TMySQL50Connection, TPQConnection) befinden sich auf der 'SQLdb' Seite in der Komponentenpalette.

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

Dieses Package bietet Zugriff auf Interbase und Firebird Datenbanken. Es ist den Komponenten bei Delphi nachempfunden, aber bei weitem nicht so umfangreich (enthält nur 3 Komponenten: TIBDatabase, TIBTransaction, TIBQuery). Außerdem erlauben diese Komponenten nur einen Lesezugriff. Das Package muß manuell installiert werden. Voraussetzung dafür ist das Vorhandensein der gds32.dll Datei (unter Windows). Fehlt diese, läßt sich Lazarus nach der Installation des Packages nicht mehr starten. Die Komponenten befinden sich auf der 'Interbase' Seite in der Komponentenpalette.

sqlitelaz.lpk

Dieses Package bietet Zugriff auf SQLite Datenbanken. Weitere Informationen sind im Lazarus Database Tutorial zu finden.

sdflaz.lpk

Das Package wird standardmäßig mit Lazarus installiert. Die Komponente TSdfDataSet befindet sich auf der 'Data Access' Seite in der Komponentenpalette.

External packages / libraries

Zeos library

Diese Bibliothek bietet Zugriff auf verschiedene Datenbanken. Informationen zum Zusammenspiel von Zeos und Lazarus finden sie im Zeos Tutorial.

Pascal Data Objects

Die Pascal Data Objects sind von Zeoslib abgeleitet. Es werden die mit MySQL 4.1 und 5.0 eingeführten Funktionen wie prepared statements, binding, und stored procedures von der Datenbank-API namens Pascal Data Objects unterstützt, die durch die PHP Data Objects inspiriert wurde. Der für die Verwendung dieser neuen API notwendige Code und die Dokumentation sind ein einem Trac wiki zu finden:

https://trac.synsport.com:8000/index.php/pdo/wiki (Benutzername/Passwort sind guest/guest)

--Jrmarino 11:28, 13 Mar 2006 (CET)

TPSQL

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

FIBL

Diese Komponenten bieten Zugriff auf Interbase und Firebird Datenbanken. Die Homepage ist http://sourceforge.net/projects/fibl.

FBLib Firebird Library

FBLib is an Open Source library (not data-sensitive) for a direct access to Firebird databases. It supports Borland Delphi / Kylix, Freepascal and Lazarus. It could be uncommonly for many users, that there is no connection via the TDatasource component.

Gegenwärtig sind folgende Features enthalten:

  • Direkter Zugriff auf Firebird 1.0.x 1.5.x Classic oder SuperServer
  • Multiplattform [Win32,Gnu/Linux,FreeBSD)
  • Automatische Auswahl der Client Bibliothek 'fbclient' oder 'gds32'
  • Abfragen (Queries) mit Parametern
  • Unterstützt SQL Dialekt 1/3
  • LGPL Lizenzvertrag
  • Extrahieren von Metadaten
  • Simple Script Parser
  • Nur 100-150 KB werden zur finalen EXE hinzugefügt
  • Unterstützt BLOB Felder
  • Export von Daten als HTML SQL Script
  • Service manager (backup,restore,gfix...)
  • Events Alerter

Sie können die Dokumentation von der Webseite herunterladen.

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.