Solved

Interbase 6.0 executeing SQL

Posted on 2001-06-24
1
190 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
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

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

Title # Comments Views Activity
Delphi cmd execution 6 56
Help on project with Soap 10 48
Printing problem 2 80
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 43
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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