Subject Re: [firebird-support] Returning a value from a Stored Procedure
Author Rik Barker
Hi Martijn,

Thanks for taking the time to reply.

>It's like a Delphi "get method" to get the value of a property that does
>all sorts of stuff and modifies the object behind the screens. Do you
>code that as well? I doubt it.

>If you are select-ing, return data, don't modify it.

Ok, that makes sense.

> > INSERT INTO Artists (Name) VALUES (:NAME);
> > SELECT gen_id(ARTISTS_ID_GEN,0) FROM RDB$DATABASE INTO :FoundID;
>
>This isn't multi-user safe.

It's been the one part of my design that's had me concerned. It's in a
stored procedure for 2 reasons. The first is because I wasn't sure which
database engine I was going to use and I wanted to code the classes without
getting caught up in SQL engine specifics. Secondly, because I was trying
to make that as thread / user safe as possible.

Obviously, there's a before insert trigger populating the ID field that I
didn't post in my last mail that increments the generator. I thought the
combination of trigger and stored procedure was going to be the best design.

>If someone else uses this procedure/code, an INSERT could occur between
>your INSERT and the next SELECT. You will get the wrong ID here, because
>the generated has been incremented.

Should I be locking? Or is the design just rubbish?

Appreciate your thoughts.
Cheers,
Rik