Subject | RE: [firebird-support] Executing an insert procedure |
---|---|
Author | Alan McDonald |
Post date | 2004-11-01T08:50:14Z |
> Hi all.as helen says - but just a note on logic, you are assuming the presence of
>
> 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 !!
>
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