Search Tools Links Login

Interbase and ADO (open source DB for Windows)


Visual Basic 6, or VB Classic

This tutorial will give you a crash cource in working with Interbase (A free, open source databese from Borland) and ADO. It will show you where to get the database engine and teach you some simple basics.

Original Author: BDCSoftware

Code




Interbase ADO Tutorial


Interbase
ADO Tutorial


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 the 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:



  1.   style='font-family:Arial'>Open Source

  2.   style='font-family:Arial'>Fast

  3.   style='font-family:Arial'>Small size

  4.   style='font-family:Arial'>Very easy distribution (scripts for Wise or InstallShield
    are available)

  5.   style='font-family:Arial'>Works ADO

  6.   style='font-family:Arial'>Works with ODBC

  7.   style='font-family:Arial'>Awesome transaction management (readers never block
    writers and vice versa)

  8.   style='font-family:Arial'>Multiple platform support (Linux/Unix)

  9.   style='font-family:Arial'>Superb support for BOLB fields (Images and memo
    fields)

  10.   style='font-family:Arial'>Support for Arrays (you can store Arrays in individual
    fields)


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:


href="http://www.borland.com/devsupport/interbase/opensource/">http://www.borland.com/devsupport/interbase/opensource/


or get it a modified version (Firebird) from:



http://www.ibphoenix.com/ibp_download.html


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:



http://www.interbase2000.org/tools_conn.htm


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: href="http://www.oledb.net/?Page=FAQ">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"


?á?á?á adoConn.Openstyle='font-family:Arial'>


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
Jstyle='font-family:Arial'>. 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 on 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 "
& _

?á?á?á?á?á?á?á?á?á?á?á?á?á?á?á "FROM CUSTOMER"?á?á?á?á?á?á?á?á?á?á?á?á?á


?á?á?á rst.ActiveConnection
= adoConn

?á?á?á adoConn.BeginTrans

?á?á?á rst.Open

?á?á?á adoConn.CommitTrans


And here is a simple stored procedure execution:


?á?á?á Dim
rst As New Recordset

?á?á?á Dim cmd As New ADODB.Command


?á?á?á adoConn.Open?á?á?á


?á?á?á With cmd

?á?á?á?á?á?á?á .ActiveConnection = adoConn

?á?á?á?á?á?á?á .CommandText = "Select * FROM DEPT_BUDGET (100)"

?á?á?á End With


?á?á?á adoConn.BeginTrans

?á?á?á ?á?á?á?áSet rst = cmd.Execute

?á?á?á adoConn.CommitTrans


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:


With
cmd

?á?á?á?á?á?á?á
.ActiveConnection = adoConn

?á?á?á?á?á?á?á .CommandText = " execute procedure PROC_INSERT_TBLCUSTOMERS
(?,?,?)”

End With


adoConn.BeginTrans

?á?á?á?á?á?á?á cmd(0) = parameter value

?á?á?á?á?á?á?á cmd(1) = parameter value

?á?á?á?á?á?á?á cmd(2) = parameter value

?á?á?á?á?á?á?á cmd.Execute

adoConn.CommitTrans


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.


Raf




About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 89 times

Categories

Visual Basic 6

Attachments

Interbase_4273812172001.zip
Posted: 9/3/2020 3:45:00 PM
Size: 7,516 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.