Getting Started with FDB

Installation

FDB is written as pure-Python module on top of Firebird client library (fbclient.so/dll) using ctypes, so make sure you have Firebird client properly installed before you try to install FDB, otherwise the installation will fail. FDB supports Firebird version 2.0 and higher.

FDB is distributed as setuptools package, so you’ll need setuptools or compatible package installed to install FDB properly.

Installation from PYPI

Run easy_install or pip:

$ pip install fdb

or:

$ easy_install fdb

Installation from source

Download the source tarball, uncompress it, then run the install command:

$ curl -O http://pypi.python.org/packages/source/f/fdb/fdb-1.2.tar.gz
$ tar -xzvf fdb-1.2.tar.gz
$ cd fdb-1.2
$ python setup.py install

Quick-start Guide

This brief tutorial aims to get the reader started by demonstrating elementary usage of FDB. It is not a comprehensive Python Database API tutorial, nor is it comprehensive in its coverage of anything else.

The numerous advanced features of FDB are covered in another section of this documentation, which is not in a tutorial format, though it is replete with examples.

Connecting to a Database

Example 1

A database connection is typically established with code such as this:

import fdb

# The server is named 'bison'; the database file is at '/temp/test.db'.
con = fdb.connect(dsn='bison:/temp/test.db', user='sysdba', password='pass')

# Or, equivalently:
con = fdb.connect(
    host='bison', database='/temp/test.db',
    user='sysdba', password='pass'
  )

Example 2

Suppose we want to connect to the database in SQL Dialect 1 and specifying UTF-8 as the character set of the connection:

import fdb

con = fdb.connect(
    dsn='bison:/temp/test.db',
    user='sysdba', password='pass',
    dialect=1, # necessary for all dialect 1 databases
    charset='UTF8' # specify a character set for the connection
  )

Executing SQL Statements

For this section, suppose we have a table defined and populated by the following SQL code:

create table languages
(
  name               varchar(20),
  year_released      integer
);

insert into languages (name, year_released) values ('C',        1972);