Solved

How to execute Interbase SQL commands with Delphi code

Posted on 1997-05-20
1
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

626 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