Difference between revisions of "Accessing Firebird with ODBC"
m (Reverted edits by LindaHayes (Talk) to last revision by Mayhewn) |
|||
(14 intermediate revisions by 3 users not shown) | |||
Line 3: | Line 3: | ||
== Names == | == Names == | ||
A few names will be used throughout this guide. These are for you to pick. | A few names will be used throughout this guide. These are for you to pick. | ||
− | * <code> | + | * <code><sysdbapassword></code> The administrator password for this install of Firebird. |
− | * <code><username | + | * <code><database_path></code> Path to the database, eg. <code>/usr/share/fieldworks/</code> |
− | * <code> | + | * <code><database_name></code> Filename for the database, eg. <code>database.fdb</code> |
− | * <code><DSN_name | + | * <code><username></code> Name for a regular database user. |
+ | * <code><password></code> Password for the regular database user. | ||
+ | * <code><driver_name></code> Name for the ODBC driver. | ||
+ | * <code><DSN_name></code> Name for the ODBC description of the database. | ||
== Installing software == | == Installing software == | ||
Line 13: | Line 16: | ||
* Install firebird2-classic-server (set SYSDBA password) | * Install firebird2-classic-server (set SYSDBA password) | ||
* Install firebird2-dev | * Install firebird2-dev | ||
− | * Optional: Install firebird2-utils-classic | + | * Optional: Install firebird2-utils-classic |
'''Note:''' It's also possible to use firebird2-super-server. I don't fully understand the difference. | '''Note:''' It's also possible to use firebird2-super-server. I don't fully understand the difference. | ||
Line 22: | Line 25: | ||
'''Note 2:''' Retrospectively, using [http://www.firebirdsql.org/manual/ubusetup.html this guide for Ubuntu] would have probably been better. Aside from one or two package names, it should work on Debian. | '''Note 2:''' Retrospectively, using [http://www.firebirdsql.org/manual/ubusetup.html this guide for Ubuntu] would have probably been better. Aside from one or two package names, it should work on Debian. | ||
− | # gsec -user sysdba -pass | + | # gsec -user sysdba -pass <sysdbapassword> -add <username> -pw <password> |
− | $ cd | + | $ cd <database_path> |
# /usr/lib/firebird2/bin/isql (NOT the same as /bin/isql) | # /usr/lib/firebird2/bin/isql (NOT the same as /bin/isql) | ||
− | SQL> create database ' | + | SQL> create database '<datbase_name>' user '<username>' password '<password>'; |
− | SQL> connect test.fdb user | + | SQL> connect test.fdb user <username> password <password>; |
Data can then be added with normal SQL commands | Data can then be added with normal SQL commands | ||
Line 37: | Line 40: | ||
=== Database === | === Database === | ||
− | Use ODBCConfig. Create new DSN | + | <span style="color:red">'''Warning:'''</span> Putting the name and password in the DSN is a bit of a security risk. It is done in this example for convenience. |
+ | |||
+ | ==== Graphical setup ==== | ||
+ | |||
+ | Use ODBCConfig. Create a new Driver, then a new user DSN. | ||
+ | |||
+ | Source: The [http://www.unixodbc.org/doc/UserManual/ unixODBC User Manual]. | ||
'''Driver:''' | '''Driver:''' | ||
+ | * Name: <code><driver_name></code> | ||
* Driver: <code>/usr/lib/odbc/libOdbcFb32.so</code> | * Driver: <code>/usr/lib/odbc/libOdbcFb32.so</code> | ||
* Setup: <code>/usr/lib/odbc/libOdbcFb32.so</code> | * Setup: <code>/usr/lib/odbc/libOdbcFb32.so</code> | ||
− | ''' | + | |
+ | '''DSN:''' | ||
First, select the driver just created and click 'OK'. | First, select the driver just created and click 'OK'. | ||
− | * Name: <code> | + | * Name: <code><DSN_name></code> |
− | * Dbname: <code>localhost: | + | * Dbname: <code>localhost:<database_path><database_name></code> |
− | * User: <code> | + | * User: <code><username></code> |
− | * Password: <code> | + | * Password: <code><password></code> |
− | + | ||
+ | ==== Config file setup ==== | ||
+ | |||
+ | The above can also be created adding an entries to unixODBC's ini files, such as in these '''minimal''' examples. (The graphical tool does the same thing, but adds a lot more fields to the files. | ||
+ | |||
+ | '''Driver:''' | ||
+ | <code>/etc/odbcinst.ini</code> | ||
+ | [Firebird] | ||
+ | Driver = /usr/lib/odbc/libOdbcFb32.so | ||
+ | Setup = /usr/lib/odbc/libOdbcFb32.so | ||
+ | |||
+ | '''DSN:''' | ||
+ | <code>/home/user/.odbc.ini<code> for a single user or <code>/etc/odbc.ini</code> for all users) | ||
+ | [<DSN_name>] | ||
+ | Driver = <driver_name> | ||
+ | Dbname = localhost:<database_path><database_name> | ||
+ | User = <username> | ||
+ | Password = <password> | ||
== Connecting to the database == | == Connecting to the database == | ||
− | isql -v | + | isql -v <DSN_name> |
(It may be required to use <code>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/odbc</code>) | (It may be required to use <code>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/odbc</code>) | ||
− | Running the above command as either root or firebird will provide an ODBC SQL console | + | Running the above command as either root or firebird will provide an ODBC SQL console. |
+ | |||
+ | OpenOffice.org Base can also connect to ODBC databases. | ||
== Programming (C) == | == Programming (C) == | ||
+ | === Reference === | ||
+ | * The [http://www.unixodbc.org/ unixODBC site] has a bunch of good reference. Click 'Manuals' on the left. (The [http://www.unixodbc.org/doc/ProgrammerManual/Tutorial/ ODBC Programming Tutorial] worked fine for me, but the Easysoft ones do look more professional). | ||
+ | * The [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcabout_this_manual.asp MSDN ODBC Programmer's Reference] is the authoritative reference for the ODBC API, but there may be some differences between this and unixODBC. | ||
+ | |||
+ | [[Category:Database]] |
Latest revision as of 22:18, 4 August 2012
A guide to setting up Firebird and ODBC on a Linux system. This guide was created using Debian Etch, some details may vary for other distributions.
Contents
Names
A few names will be used throughout this guide. These are for you to pick.
-
<sysdbapassword>
The administrator password for this install of Firebird. -
<database_path>
Path to the database, eg./usr/share/fieldworks/
-
<database_name>
Filename for the database, eg.database.fdb
-
<username>
Name for a regular database user. -
<password>
Password for the regular database user. -
<driver_name>
Name for the ODBC driver. -
<DSN_name>
Name for the ODBC description of the database.
Installing software
- Install unixodbc* packages
- Install firebird2-classic-server (set SYSDBA password)
- Install firebird2-dev
- Optional: Install firebird2-utils-classic
Note: It's also possible to use firebird2-super-server. I don't fully understand the difference.
Creating a database
Note: The commands run as root here would be better run as the 'firebird' user.
Note 2: Retrospectively, using this guide for Ubuntu would have probably been better. Aside from one or two package names, it should work on Debian.
# gsec -user sysdba -pass <sysdbapassword> -add <username> -pw <password> $ cd <database_path> # /usr/lib/firebird2/bin/isql (NOT the same as /bin/isql) SQL> create database '<datbase_name>' user '<username>' password '<password>'; SQL> connect test.fdb user <username> password <password>;
Data can then be added with normal SQL commands
Setting up unixODBC
Drivers
- Download the Firebird ODBC version 2 source for Linux
- In
OdbcJdbc/Builds/Gcc.lin
runmake -f makefile.linux
- Copy the resulting
Release/libOdbcFb32.so
into/usr/lib/odbc
Database
Warning: Putting the name and password in the DSN is a bit of a security risk. It is done in this example for convenience.
Graphical setup
Use ODBCConfig. Create a new Driver, then a new user DSN.
Source: The unixODBC User Manual.
Driver:
- Name:
<driver_name>
- Driver:
/usr/lib/odbc/libOdbcFb32.so
- Setup:
/usr/lib/odbc/libOdbcFb32.so
DSN:
First, select the driver just created and click 'OK'.
- Name:
<DSN_name>
- Dbname:
localhost:<database_path><database_name>
- User:
<username>
- Password:
<password>
Config file setup
The above can also be created adding an entries to unixODBC's ini files, such as in these minimal examples. (The graphical tool does the same thing, but adds a lot more fields to the files.
Driver:
/etc/odbcinst.ini
[Firebird] Driver = /usr/lib/odbc/libOdbcFb32.so Setup = /usr/lib/odbc/libOdbcFb32.so
DSN:
/home/user/.odbc.ini<code> for a single user or <code>/etc/odbc.ini
for all users)
[<DSN_name>] Driver = <driver_name> Dbname = localhost:<database_path><database_name> User = <username> Password = <password>
Connecting to the database
isql -v <DSN_name>
(It may be required to use LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/odbc
)
Running the above command as either root or firebird will provide an ODBC SQL console.
OpenOffice.org Base can also connect to ODBC databases.
Programming (C)
Reference
- The unixODBC site has a bunch of good reference. Click 'Manuals' on the left. (The ODBC Programming Tutorial worked fine for me, but the Easysoft ones do look more professional).
- The MSDN ODBC Programmer's Reference is the authoritative reference for the ODBC API, but there may be some differences between this and unixODBC.