Solved

How to execute Interbase SQL commands with Delphi code

Posted on 1997-05-20
1
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now