Subject Re: [ib-support] Re: exception
Author Jason Wharton
Sorry, I was in a hurry at the moment.

Let me see what I can find.

Here's an example that comes from the Survey sample application:

CREATE TRIGGER AI_TABLE_RESPONSE FOR TABLE_RESPONSE

ACTIVE AFTER INSERT POSITION 0

AS

BEGIN

BEGIN

INSERT INTO table_response_stats (

questionid,

rs_choice,

rs_count )

VALUES (

new.questionid,

new.choice,

1 );

WHEN sqlcode -803 DO

UPDATE table_response_stats

SET rs_count = rs_count + 1

WHERE questionid = new.questionid

AND rs_choice = new.choice;

END

END


HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com


----- Original Message -----
From: "Marcelo Miorelli" <jjkalki@...>
To: <ib-support@yahoogroups.com>
Sent: Saturday, February 03, 2001 2:11 PM
Subject: [ib-support] Re: exception


> Thanks for replying Jason, but it did not help me much.
> How can I do that? Someone has some example to show us?
> Whatabout the SQLCODE?
>
> Any help is appreciated.
>
>
> ----- Original Message -----
> From: "Jason Wharton" <jwharton@...>
> To: <ib-support@yahoogroups.com>
> Sent: Friday, February 02, 2001 1:25 PM
> Subject: Re: [ib-support] exception
>
>
> I've found that you have to nest the WHEN ... in its own BEGIN ... END
> block.
>
> HTH,
> Jason Wharton
> CPS - Mesa AZ
> http://www.ibobjects.com
>
>
> ----- Original Message -----
> From: "Marcelo Miorelli" <jjkalki@...>
> To: "Interbase Krishna Balarama" <ib-support@yahoogroups.com>
> Sent: Friday, February 02, 2001 8:18 AM
> Subject: [ib-support] exception
>
>
> > Untitled-1Hello dear all.
> > Suppose I have a simple table like this:
> >
> > TABLE PERSON:
> > COD_PERSON INTEGER NOT NULL,
> > DES_PERSON VARCHAR(40) NOT NULL;
> >
> > COD_PERSON IS THE PRIMARY KEY.
> >
> > and I create another unique index in the following way:
> >
> > create unique index SKPERSON on PERSON(DES_PERSON);
> >
> > till here everything fine.
> > Now I get a stored procedure to insert and update records on this table.
> > Something like this:
> >
> > CREATE PROCEDURE INPERSON (
> > P1 integer,
> > P2 VARCHAR(40),
> > P3 VARCHAR(1)
> > ) RETURNS (
> > R1 integer
> > ) AS
> > begin
> >
> > r1 = 1;
> > insert into person(cod_person,des_person) values(:p1,:p2);
> >
> > when SQLCODE -803 do begin /* 803 = violation of primary key
> constraint
> > */
> >
> > if (upper(p3) = 'Y') then begin
> >
> > update person
> > set des_person = :p2
> > where cod_person = :p1;
> >
> > end/*if*/
> > else begin
> >
> > r1 = -1;
> > exception PERSON_ALREADY_EXISTS;
> >
> > end/*else*/
> > end/*when*/
> > end
> >
> > Obs: Suppose this exception PERSON_ALREADY_EXISTS is already created,
and
> > the name of the person is unique only for the purpose of this example.
> >
> > I would like to put in this procedure another exception like "A person
> with
> > this name already exists in code %d".
> > How can I do this?
> > What is the SQLCODE?
> >
> > Thanks in advance,
> > Marcelo Miorelli
> >
> >
> >
> > To unsubscribe from this group, send an email to:
> > ib-support-unsubscribe@egroups.com
> >
> >
> >
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>