ODBCConn

From Free Pascal wiki
Revision as of 17:41, 2 May 2007 by Kuifware (talk | contribs) (→‎Installing ODBC and ODBC Drivers: added location of ODBC manager in Windows)
Jump to navigationJump to search

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

TODO

ODBC Drivers

TODO

Connecting to an ODBC data source

TODO

Debugging ODBC

TODO