Difference between revisions of "ODBCConn"

From Free Pascal wiki
Jump to navigationJump to search
(→‎Installing ODBC and ODBC Drivers: added location of ODBC manager in Windows)
(→‎Unices: added instructions for Debian and Ubuntu)
Line 49: Line 49:
 
==== Unices ====
 
==== Unices ====
  
TODO
+
Two popular ODBC Driver Managers for Unix-based platforms are [http://www.unixodbc.org unixODBC] and [http://www.iodbc.org iODBC].
 +
<code>ODBCConn</code> is known to work with unixODBC; iODBC compatibility still has to be tested.
 +
 
 +
===== Debian =====
 +
 
 +
For Debian, you can install the ''unixodbc'' package:
 +
 
 +
aptitude install unixodbc
 +
aptitude install unixodbc-bin # if you want some GUI tools
 +
 
 +
The <code>odbcsqldyn</code> unit, and hence <code>odbcconn</code>, will search for a file called <code>libodbc.so</code>.
 +
It will ''not'' accept a file named like <code>libodbc.so.1</code> or <code>libodbc.so.1.0.0</code>.
 +
Debian's ''unixodbc'' package does not create a symlink with the name <code>/usr/lib/libodbc.so</code>; you must either
 +
* create the link yourself: <code>ln -s libodbc.so.1 /usr/lib/libodbc.so</code>, or
 +
* install the ''unixodbc-dev'' package, which does create the symlink.
 +
 
 +
If you installed the ''unixodbc-bin'' package, you can run the <code>ODBCConfig</code> program to configure ODBC drivers and DSNs.
 +
 
 +
[[Image:ODBCDataSourceAdministratorAbout.PNG]]
 +
 
 +
==== Ubuntu ====
 +
 
 +
For Ubuntu, follow the instruction for [[#Debian|Debian]].
 +
Note: the ''unixodbc-bin'' package might not be available from the default package repository.
  
 
=== ODBC Drivers ===
 
=== ODBC Drivers ===

Revision as of 22:56, 2 May 2007

The ODBCConn unit implements an SQLdb connection to ODBC data sources.

Overview

ODBC

ODBC (Open Database Connectivity) is a technology that allows one to connect to a whole variety of databases using a single API, the ODBC API.

TOBCConnection

FreePascal ships with ODBC headers; they are in the odbcsql and odbcsqldyn units. TODBCConnection is an TSQLConnection descendant providing a nice OOP wrapper for ODBC using the SQLdb framework.

In Lazarus, you can find the TODBCConnection component on the SQLdb component tab. You can also use the TODBCConnection component in your code by adding ODBCConn to your uses clause.

What has been implemented:

  • executing queries and retrieving result sets
  • most field types, including blobs
  • query parameters (string and integer types)
  • preparing queries
  • UpdateIndexDefs (so you can use ApplyUpdates); patch submitted to fpc-devel, May 2, 2007

What is left to be implemented:

  • proper transaction support; currently each connection corresponds to one transaction
  • some field types
    • SQL_TYPE_UTC* (these are mentioned in the ODBC docs, but seem not to be used in implementations)
    • SQL_INTERVAL_* (what would be the corresponding TFieldType?)
    • SQL_GUID (TGUIDField was not implemented, until recently)

Why use ODBC?

FreePascal ships with components for connecting to several databases, such as MySQL, PostGreSQL, Firebird, Oracle, etc. For those databases missing from the list, like MS Access, ODBC might be an outcome. Actually, the TODBCConnection component was developed originally to circumvent the strict MySQL license for applications that are not GPLed or do not obey MySQL AB's FLOSS exception.

Installing ODBC and ODBC Drivers

Before you can connect to your database using ODBC, you need to install

  • an ODBC Driver Manager
  • an ODBC driver specific to the DBMS you want to connect to

The ODBC Driver Manager

Windows

Windows has an ODBC Driver Manager built in. Its configuration is controlled by

  • the Data Sources (ODBC) item under the Administrative Tools in the Control Panel (Win 2000, XP)
  • the ODBC Data Sources (32-bit) item in the Control Panel (Win 9x, ME).
  • the ODBC item in the Control Panel (Win NT)

Unices

Two popular ODBC Driver Managers for Unix-based platforms are unixODBC and iODBC. ODBCConn is known to work with unixODBC; iODBC compatibility still has to be tested.

Debian

For Debian, you can install the unixodbc package:

aptitude install unixodbc
aptitude install unixodbc-bin # if you want some GUI tools

The odbcsqldyn unit, and hence odbcconn, will search for a file called libodbc.so. It will not accept a file named like libodbc.so.1 or libodbc.so.1.0.0. Debian's unixodbc package does not create a symlink with the name /usr/lib/libodbc.so; you must either

  • create the link yourself: ln -s libodbc.so.1 /usr/lib/libodbc.so, or
  • install the unixodbc-dev package, which does create the symlink.

If you installed the unixodbc-bin package, you can run the ODBCConfig program to configure ODBC drivers and DSNs.

ODBCDataSourceAdministratorAbout.PNG

Ubuntu

For Ubuntu, follow the instruction for Debian. Note: the unixodbc-bin package might not be available from the default package repository.

ODBC Drivers

TODO

Connecting to an ODBC data source

TODO

Debugging ODBC

TODO