Has anybody ever wondered if there is an Open Source alternative to SQL Server or Access databases? Well, I have, and I found Interbase. Interbase is a Client/Server database from Borland. It is Open Source. It runs on Windows, Linux and bunch of other *nix platforms. It has a very small memory footprint and it is relatively fast.
It will also support large database files (larger then 2 gig. I know a guy that has a 300 Gig database up and running)
Anyhow, in this article I will describe the issues and the necessary tools to get you up and running with Interbase.
First let me tell you about the benefits of Interbase:
For starters you need to get the server and client software. You can get the original Open Source version (Source and Binaries) from Borland at:
or get it a modified version (Firebird) from:
Download and install the server and client binaries. The Interbase server ships with a ODBC driver, but I hate ODBC and use ADO/OleDB on a day to day basis. So I had to find an OleDB driver for Interbase. Luckily there are numerous available. You can find a links to download sites on this site:
I opted for the IBProvider from http://www.lcpi.lipetsk.ru/prog/eng/index.html because they had some VB samples of how to use the provider with ADO. The version that you can download is an Evaluation for 30 days. If you want a completely free OleDB provider then use: Http://www.oledb.net/?Page=FAQ . However, all my sample code is tested with IBProvider only.
Once you have downloaded and installed all the files, you are ready for development. IB (Interbase) ships with a sample database called employee.gdb. We will use this database as an example. (You can find it in ‘C:Program FilesBorlandInterBaseexamplesDatabase’ , provided you installed the server in the default location). Anyhow, lets start with the basics:
Connecting to Interbase
Lets establish a connection to the database. A sample connection:
Dim adoConn As New ADODB.Connection
adoConn.ConnectionString = "provider=LCPI.IBProvider;data source=localhost:C:Interbase DBsEmployee.gdb;ctype=win1251;user id=SYSDBA;password=masterkey"
Ok, here are a few things to consider:
Default user name and password (like SA in SQLServer) are SYSDBA and masterkey (case sensitive). The ‘data source’ parameter has a following syntax: IP Address:file location on the remote system . If you installed the server on your development machine then use localhost or your IP. If you installed it on a remote machine then use the IP Address of the machine. The file location is a bit weird. It is local to the server and you can’t use UNC paths.
Once the connection is open, we can start working with the database.
Working with an Interbase database
For the most part, working with Interbase is as easy as working with SQL Server or Access. However there are a few things to consider:
For one, Interbase uses dialects, basically it’s the SQL syntax that you issue your commands to the database. IB 6.0 can use Dialect 1 (legacy) and Dialect 3. The sample databases are in written in Dialect 1. If you decide to use Dialect 3 (as I have), you will notice some weird behavior. If your database has lower case table and field names, you will have to surround them with double quotes. For instance: Select "CompanyName", "Address" from "tblCustomers". Needless to say this will create havoc with VB programmers J. One workaround is to use caps for table and field names. (Btw, don’t ask me why this is the way it is.) For Instance: SELECT COMPAN_YNAME, ADDRESS FROM TBLCUSTOMERS.
The other issue that I have found is: you cannot use adCmdStoredProc as your command type. Workaround for this: use adCmdText. But more to this later.
Ok, so how would we get some data in and out of our database? Well, you can use your normal recordset object to execute a SQL statement or you can use stored procedures.
Here is a sample of a simple select statement:
Dim rst As New Recordset
rst.Source = "SELECT CUSTOMER.CONTACT_FIRST, " & _
"CUSTOMER.CONTACT_LAST, CUSTOMER.COUNTRY " & _
rst.ActiveConnection = adoConn
And here is a simple stored procedure execution:
Dim rst As New Recordset
Dim cmd As New ADODB.Command
.ActiveConnection = adoConn
.CommandText = "Select * FROM DEPT_BUDGET (100)"
Set rst = cmd.Execute
Notice that if your stored procedure returns any rows, you have to use the ‘SELECT * FROM stored procedure name’ syntax. If your procedure does not return any records, you can use ‘EXECUTE stored procedure name’.
Also, the way you pass parameters in and out of the procedure is a bit peculiar. Lets say you have an insert stored procedure that will accept 3 parameters. To pass those parameters you can use inline syntax: For instance, ‘execute procedure PROC_INSERT_TBLCUSTOMERS (comma delimited parameter values)’ or you can use this syntax:
.ActiveConnection = adoConn
.CommandText = " execute procedure PROC_INSERT_TBLCUSTOMERS (?,?,?)"
cmd(0) = parameter value
cmd(1) = parameter value
cmd(2) = parameter value
Anyhow, these are the basics. If you guys are interested in Interbase, I will write a 2nd part of the tutorial that will cover some advanced features like working with Images, Arrays, UDF functions and tools for Interbase. For now take a look at the sample code for this tutorial, and take a look at the sample databases that are provided by Borland.