Solved

Interbase 6.0 executeing SQL

Posted on 2001-06-24
1
197 Views
Last Modified: 2010-04-06
How can i execute SQL-Scripts from Delphi ?
i would like to generate a Table from within my application, but the Table has some Triggers.

for example :

CREATE TABLE "PA"
(
  "ID"     INTEGER NOT NULL,
  "PID"     INTEGER,
  "TIMESTAMPS"     INTEGER,
  "BS"     SMALLINT,
 PRIMARY KEY ("ID")
);
SET TERM ^ ;


/* Triggers only will work for SQL triggers */

CREATE TRIGGER "PA_INSERT" FOR "PA"
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
 NEW.TIMESTAMPS = GEN_ID(UID, 1);
END
 ^

CREATE TRIGGER "PA_UPDATE" FOR "PA"
ACTIVE BEFORE UPDATE POSITION 0
AS
BEGIN
 NEW.TIMESTAMPS = GEN_ID(UID, 1);
END
 ^

COMMIT WORK ^
SET TERM ;^
0
Comment
Question by:Andi4553
[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 1

Accepted Solution

by:
z_darius earned 100 total points
ID: 6223243
you need the following objects on the form along with properties as suggested below

1. give yourself a button:

object Button1: TButton

2. drop an IBDatabase component on the form
 
object IBDatabase1: TIBDatabase
    Connected = True
    DatabaseName = 'D:\zz\Work\A21.GDB' //use your path
    Params.Strings = (
      'user_name=sysdba'  //use your login
      'password=somepassword') //use your password
    LoginPrompt = False
    SQLDialect = 1

3. drop and IBSQL component on the form:

object IBSQL1: TIBSQL
    Database = IBDatabase1
    ParamCheck = True
    SQL.Strings property
    SQL.Strings = (
      'CREATE TRIGGER PA_INSERT FOR PA '
      'ACTIVE BEFORE INSERT POSITION 0'
      'AS'
      'BEGIN'
      'NEW.TIMESTAMPS = GEN_ID(UID, 1);'
      'END'
      '')
    Transaction = IBTransaction1

4. finally and IBTransaction component:

  object IBTransaction1: TIBTransaction
    Active = True
    DefaultDatabase = IBDatabase1
  end

now using one of the onClick events do something similar to the code below:

procedure TForm1.Button1Click(Sender: TObject);
begin
  IBSQL1.ExecQuery;
  IBTransaction1.Commit;
end;

that's all. I verified this to work against IB6.
One last suggestion: do not use quotes around names of tables, fields in tables and other database objects in your SQL code.

for instance:
Wrong ---->>> :

CREATE TABLE "PA"
(
 "ID"     INTEGER NOT NULL,
 "PID"     INTEGER,
 "TIMESTAMPS"     INTEGER,
 "BS"     SMALLINT,
PRIMARY KEY ("ID")
);

Right ---->>> :
CREATE TABLE PA
(
 ID     INTEGER NOT NULL,
 PID     INTEGER,
 TIMESTAMPS     INTEGER,
 BS     SMALLINT,
PRIMARY KEY (ID)
);

Also, when creating a trigger which uses a generator, make sure you have created the generator first.

oh, and good luck !
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

632 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