Solved

How to execute Interbase SQL commands with Delphi code

Posted on 1997-05-20
1
255 Views
Last Modified: 2010-04-04
Last week, I bought Delhi 3 Professional, which comes with a local InterBase database server, but sadly without any manuals concerning how to use Interbase databases from within Delphi.

Until now, I succesfully created some tables, one named documents, and one named objects.  The documents table was created using the folowing SQL statement :
 
 CREATE TABLE DOCUMENTS (
   DOC_ID INTEGER NOT NULL,
   DOC_TYPE CHAR(25),
   DOC_NBR_OBJ INTEGER NOT NULL,
   DOC_ROOT_OBJ INTEGER,
   DOC_INFO_OBJ INTEGER,
   DOC_CRE_DATE DATE DEFAULT "NOW" NOTNULL,
   DOC_MOD_DATE DATE
 )
 
I also created a generator, which gives a unice incremental number to each document record :
 
 CREATE GENERATOR DOC_ID_GEN;
 SET GENERATOR DOC_ID_GEN TO 14
 
 The trigger :
 
 CREATE TRIGGER SET_DOC_ID FOR DOCUMENTS BEFORE INSERT POSITION 0 AS
 BEGIN
      NEW.DOC_ID = Gen_ID (DOC_ID_GEN, 1);
 END
 
 Now I used an SQL command from withing the Database explorer to test if this trigger works correctly :

 INSERT INTO DOCUMENTS (DOC_TYPE, DOC_NBR_OBJ)
 VALUES ('Cre w SQL in DB Explorer', 3);
 
 Until here everything works correctly.  The record is added, and it is given a unique number which increments for each added record.
 
 Now comes my question : How can I code such commands into Delphi ? Is there some way I can execute SQL commands from withing the code of a Delphi program, which components should I use, and how do I code it.

If anybody can help me with this problem, I would really appreciate it.
 
 Any comments or help can be sent to :
 
 --
 
 Stefaan Lesage
 Fotek nv; Belgium
 Stefaan@fotek.com
0
Comment
Question by:Kingetje
1 Comment
 
LVL 7

Accepted Solution

by:
RBertora earned 100 total points
ID: 1336506
Yes you can execute these commands from delphi.

You must create an alias to the IB database using the BDE configuration utility.

you should simply provide a path and file name of the .GDB interbase database file on your machine,
also a preffered logon name....

After having created the alias, I have found that you  must reboot the machine after.

Now the delphi code:

drop a TQuery on your form, set the DatabaseNAme property to your alias, this should be a drop down list including your new alias.

You can edit the SQL property, here you should place your query:

Insert into documents.... etc

then from say Button1click  you can call Query1.ExecSql;

This will do what you want it too.

Cheers,
Rob.






0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question