ok, in the last post, i explained how to install firebirdsql with the basic (and perfectly acceptable) default settings. when i first decided to start working with firebird, i was intimidated because i really didn't know that much about sql and working with the included isql.exe command prompt seemed a bit cryptic to me. if you've been working with sql commands for a while, maybe you'd feel differently, but i needed a way to visually work with the tables, triggers, and domains like i've become used to in foxpro.

after initially trying a freely available product called marathon, i ran across a program called ems sql manager for interbase/firebird. ems makes visual database editors for mysql, sql server, postgresql, oracle, db2, and dbisam. i cannot say enough good about this product. on top of everything else the product does, the company offers a free lite version of many of their products which should appeal to any foxpro programmer out there. so far, the lite version has done everything i need it to do, but i can see down the road when i will probably need the full version, which for businesses costs $275.00. there is also a full studio version that includes a lot of the utilities that you can also purchase separately. ems also publishes products such as data export, data import, data pump migration tool, test data generator, db comparer, db extract, sql query, and data comparer. you can view all of their products for all of the different data systems here.

for the purposes of this article we'll be focusing on the ems sql manager for interbase/firebird lite. i want to take you through the process of creating a sample database that we will be using in some of the examples i'll post later. if you don't want to create the sample database manually, here's the link so you can download the sample.

the first step is to download the ibmanager program. the link i have provided will connect you to download.com and the ibmanager_lite.zip file is about 14mb and should start to download immediately. unzip the ibmanagerlite.exe and double-click this file to start the install process.

accept the defaults and when the installation is finished, the sql manager 2005 lite for interbase and firebird will start. (note: for the sake of clarity, i set the windows to be an mdi environment. to change your system to match, click options, environment options, windows and set the environment style to 'mdi environment'. i normally use the floating windows but it makes screenshots difficult.)

the first screen you will see is this one:

the previous screen is your "control panel" for firebird databases and it is the starting point whether you are designing a new database, or maintaining an existing one. any previously designed databases will be shown in the database box in the top left-hand corner. since this is a fresh install there are not any files, but we'll add one now.

the first thing that must be done is to register a new host. a host (server) can be defined for any computer on your network that is running firebirdsql server. i'm assuming that you followed our previous tutorial and installed the server on your local computer. if you didn't, simply replace 'localhost' you see in the screenshots with the computer name of the computer where you installed the firebird server.

to register a new host click 'database' on the main menu at the top and then click 'register host.' you should now see the screen below:

set the protocol to tpc/ip, the host name to localhost, leave the remaining fields set to their defaults and then click next. this will take you to the host options screen below:

we should take a moment and discuss the fbclient.dll. this is the main driver that you will use for connecting to the firebird server through either ems or an odbc connection. we will discuss odbc connections in a later post, but the most important thing to know is that each client will need to have access to this .dll in order to connect to the server. if you installed the server on your local machine, you should be able to locate the fbclient.dll in the c:\program files\firebird server folders. in version 1.5 of firebird this will be the main folder of the firebird installation. version 2.0 changes the folders somewhat and adds a folder under the main folder named 'bin' and installs the fbclient.dll there.

there is an error in the screenshot above which i corrected after i made the snapshot. the correct path to the verison 2.0 client library should be c:\program files\firebird\firebird_2_0\bin\fpclient.dll. you may choose to copy this file to some other folder to make it more accessible. for one customer, i installed it on a server folder so that clients have access to it across the network, but a better solution would be to install it in a client folder where you install your other dll, ocx or configuration files for your software in order to reduce network traffic. i haven't seen a lot of traffic being generated by this file being located on a server, but this would probably be more of an issue if you had 50 or more users on a network.

the default security database is located in the main program files folder where you installed the firebird server. you could leave this blank and ems will still work, but you will need to make some version of this security database available to the production server so you can control access to the production database.

to simplify your life, check the box labelled 'connect to the host automatically when connecting to any of its databases.' this prevents you from having to enter multiple logins and passwords whenever you want to access your tables.

click finish and the host server will be registered and you'll see the screen below:

make sure that the current host is selected in the databases window and then click 'create new database.' you can also click the create dropdown and select 'database' to accomplish the same thing. the following window will open:

choose the host name where you want the database to be created and hosted. then click next.

enter a fully qualified database name. you can click the disk icon at the end of the field to open a window to browse your drive and/or create a new folder. it is important to note that if the database will reside on a computer other than the local host, you will need to preceed the absolute path to database with the name of the server. for example, if you are creating a database on a server named 'myserver' and the absolute path is d:\mydata then then the fully qualified path will be 'myserver:d:\mydata' without the quotes. the default file name extension is .gdb, but the firebird convention is usually .fdb. any extension will work so choose what works for you.

the default login is 'sysdba' and the password is 'masterkey'.

in this example, i've changed the page size to 8192 even though the default is 4k. in some experiments i've been running, the connection speed has increased significantly. if the tables you plan on creating have large numbers of fields this can be a quick and easy way to improve performance and reduce network traffic. experiment yourself to find a page size that works best for your application and situation.

i selected ascii as the charset, but the server is capable of handling any one of several. pick what works for you and the app you want to build. i've used unicode and ascii and one big difference is that unicode needs an extra byte on fields to handle extended characters. for example, with unicode, you cannot define a character field with only a 1 byte length. the definition will require at least 2 bytes.

check the single database file and everything will be stored in one database file. this works well for me so far, but if anyone can contribute thoughts on this, please do.

click next to see the next screen.

you should see the details that you've selected on previous screens displayed for your confirmation. make sure the register the database after creating checkbox is selected.

clicking finish will cause the program to create your database and register it with the correct host. you will be returned to the main control screen and you should see your database listed in the databases treeview under the host you defined earlier. right click on the icon for your database and then left click on database registration info to see the next window.

click connection in the options list and you should see all of the connection details to the database your created. click test connect and you should be rewarded with an information pop-up that says 'connected!'

click the ok button to return to the connection screen. click options to see several other configuration choices.

click system objects to select which system objects will be displayed in the db explorer.

for the sake of this tutorial all items have been unchecked to keep the db explorer window uncluttered. however, i would advise you to take the time to go back and turn each of these options on individually so you can see the different items that are created behind the scenes. it will help you understand better at that time how everything relates. i do not advise allowing the editing of triggers for system tables and views. frankly, the idea scares me, but if you are a sql expert you can certainly give it a whirl. click data options to view additional data settings.

the only setting i changed from the defaults here is the get record count beforehand. when working in the design mode, it is sometimes helpful to know how many records are in a particular table. it can also be interesting information to watch in a production database. click ok to save your settings and return to the main control panel.

double-clicking on your defined database will expand the treeview to show you all of the different parts of your database. for now, we won't worry about any item in this list except the tables folder. right click on the tables folder and left click on the new table to start creating a new table. as you can see above, we've started creating a new table named 'bloggers' and have entered a note in the description field to give anyone a clue as to what will be stored in this table. click the fields tab and then right click in the blank white area and left click new field. the following window will appear.

as you can see you can define almost any attribute for a field at the time of creation. here we are creating a field named 'pk_uniqueid' and we are defining it as a primary key. for this tutorial just select a standard data type and in the type dropdown you'll see all of the different types of fields you have available to you in firebird. it is beyond the scope of this discussion to describe all of the field types, but for this first field we'll select integer. next we'll select the autoincrement tab to create a generator and a insert trigger.

a generator is place to store the next incremental number and the insert trigger will do the heavy lifting of making sure that any new record will receive a unique identifier. let's click the trigger tab.

you'll see that firebird will automatically create the sql code necessary to update a new record with the next generator value if the pk field is found to be null. the next screen shows the table as it should look after you've created all of the fields that you want in the table.

let's go back and edit the trigger for the pk_uniqueid. as you may have noticed in the previous screen, we created a field called 'dateadded.' ideally, i'd like this field to be updated with a date whenever a new record is added to the table. the following screen shows the code to do this is very easy to add to the pk trigger.

when you are satisfied that all of your changes have been made, click 'compile' and the system will generate the necessary sql code and attempt to compile it. if everything goes well, then you can click 'commit' and the changes will be written to the database. if there is a problem, you can rollback the change and fix the problem. this is a great feature because it has helped me identify many mistakes before they make it to the database. in this case, the table should be created and will appear in the databases treeview as in the screen below.

double-clicking on the table icon on the left hand side will open the table and you can then click the 'data' table and begin entering data. in this case, i've entered five records of different blogs and references to each one.

in our next tutorial, we'll install the odbc drivers for firebird and then create both dsn and dsn-less connections and use them from inside foxpro.

get ems sql manager for firebird! it will save you lots of tears, trouble and time!

get it today!

pht 

One Response to Visually Create, Edit & Maintain FirebirdSQL Databases

Leave a Reply

Your email address will not be published. Required fields are marked *