Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Triggers in Interbase for Delphi

Posted on 2002-07-21
14
Medium Priority
?
276 Views
Last Modified: 2010-04-04
So as we all know, in Interbase we can´t increment for saying IdProduct with ONE. Therefore we need a trigger who calls a generatorID. For example:

**********
CREATE TRIGGER IdProduct FOR TblProducts
BEFORE INSERT
AS
BEGIN
NEW.IdProduct=GEN_ID(ProductGen,1);
END
**********

... knowing that the syntexis for the generator is :
**********
Create Generator ProductGen
**********

My question is: How can i create a trigger or Procedure who can transfer at the same time the NEW.IdProduct to another table for example TblProductDescription and at the same time this table need to autoincrement the field IdProductDescription with 1.....

TblProduct with fields:
IdProduct <----------------------------
Code                                          |
Name                                          |
Price                                         |
                                              |
TblProductDescription with fields:            |
IdProductDescription                          |
IdProduct <----------------------------
Description
Stock
Rate

0
Comment
Question by:Chalo
[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
14 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7167928
instead of using a trigger use a stored-proecdure for this like

--Interbase

CREATE PROCEDURE TblProducts_NEXT_ID  RETURNS (
  ID INTEGER
) AS
BEGIN
  ID = GEN_ID(ProductGen,1);
END

now you could use a storedproc-object and supply the id in the beforepost-event, if in insert-state like

--Delphi

Function Tform1.Get_Next_Id(SPName : String) : Integer;
begin
  Try
    StoredProc1.StoredProcName := SPName;
    StoredProc1.ExecProc;
    Result :=
      StoredProc1.ParamByName('ID').AsInteger;
  Except
    Raise;
  end;
end;

procedure Tfr_ppo.tblPPOBeforePost(DataSet: TDataSet);
begin
  if TblProducts.State = dsInsert then
  begin
    TblProducts.FieldByName('ID').AsInteger :=  get_next_id(TblProducts_NEXT_ID');
    //now you could use the value for assigning to the details
    fnewPPOID := TblProducts.FieldByName('ID').AsInteger;  //store in a var for ex.
  end;
end;

just as suggestion

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 360 total points
ID: 7167931
sorry, this header
procedure Tfr_ppo.tblPPOBeforePost(DataSet: TDataSet);

should be
procedure Tform1.TblProductsBeforePost(DataSet: TDataSet);

;-)
0
 
LVL 3

Expert Comment

by:cubud
ID: 7168101
I do this completely differently.

PurchaseOrder
=============
ID INTEGER NOT NULL,
OrderNumber INTEGER,
OtherColumns

PurchaseOrderLine
=================
ID INTEGER NOT NULL,
PURCHASEORDERID INTEGER NOT NULL,
OtherColumns

The PurchaseOrder table has an ID column which means nothing more than a unique ID for the records in the child table. I do
"SELECT GEN_ID(NEXTPOID, 1) FROM RDB$DATABASE AS NEXTID"
after I insert a PurchaseOrder so that the Purchase order has an ID for the children to point to.

Once the purchase order + lines have been posted without problems, and just before I commit my transaction, I then do
"SELECT GEN_ID(NEXTPONUMBER, 1) FROM RDB$DATABASE AS NEXTID"
and assign it to the OrderNumber column.

This means that the ID of the main table is meaningless, so I can therefore assign it at the start and not care if it is not comitted and thus causing the numbers to be out of sequence.

Pete
====
Record, Play, Read, Write, Compress audio files. http://www.DroopyEyes.com
Read / write articles about just about anything http://www.HowToDoThings.com
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7179520
hello?
0
 

Author Comment

by:Chalo
ID: 7187125
Sorry, i was on vacation.......
I've tried the examples of both kretzschmar and cubud, but i think that i'm doing something wrong....

Is it possible to send me some examples? My adress is Chalo34@Hotmail.Com  
Please write as subject: "Delphi-Interbase Triggers"
This as security. If not, all emails i 'don't know, will be deleted without reading.

PS: How can i declare a variable in interbase to store any graphic or picture (extension *.jpg)?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7187149
>How can i declare a variable in interbase to store any
>graphic or picture (extension *.jpg)?

the type must be blob
0
 

Author Comment

by:Chalo
ID: 7187171
The Blob type is only for text, isn't it?
Example:

"GRAPHIC" Blob Sub_Type BLR SEGMENT SIZE 80

With this declaration an error occures....
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7187192
>The Blob type is only for text, isn't it?
Binary Large OBject can store anything

well, have the subtypes not in mind yet
0
 

Author Comment

by:Chalo
ID: 7187200
Ok, let me try....
What about the triggers??
Are you using MSN Messenger??? Perhaps we can have a little conversation?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7187204
>Are you using MSN Messenger???
no, sorry, but i can send you a sample this evening
(in ~11 hours, i have no delphi nor interbase on hand yet)

meikl ;-)
0
 

Author Comment

by:Chalo
ID: 7187206
Ok, i will appreciate that...
Please, have in mind the subject "Delphi-Interbase Triggers"
0
 

Expert Comment

by:CleanupPing
ID: 9343022
Chalo:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9461363
Chalo,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to kretzschmar http:#7167931

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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