Solved

How to execute Interbase SQL commands with Delphi code

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

705 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

16 Experts available now in Live!

Get 1:1 Help Now