Subject RE: [firebird-support] Executing an insert procedure
Author Alan McDonald
> Hi all.
>
> I'm trying to implement a stored procedure to perform updates on Debian
> Linux packaged FB1.5. Full text of procedure below:
>
> CREATE PROCEDURE UPDATE_ZIPCODE (ID INTEGER, ZIPCODE CHARACTER (10),
> STATE CHARACTER (2), CITY VARCHAR (30))
> RETURNS (NEWID INTEGER)
> AS
> BEGIN
> IF (id IS NOT NULL) THEN
> BEGIN
> UPDATE ZIPCODES SET zipcode=:zipcode, state=:state, city=:city WHERE
> id=:id;
> newid=id;
> END
> ELSE
> BEGIN
> newid = GEN_ID(gen_zipcode_id,1);
> INSERT INTO ZIPCODES (id, zipcode, city, state)
> VALUES (:newid, :zipcode, :city, :state);
> END
> END !!
>

as helen says - but just a note on logic, you are assuming the presence of
id just because it's being passed to the procedure.
A better logic would be to select for id and see if the record exists before
trying to update it. It may not exist, but updating where id does not exist
will be silent. YOu wont know if anything at all has happened.
Alan