Posted by: Mirko BONANNO
Hi all,
We ware asked how we would like them to enhance the autoincrement
functionality in SB11 and particularly how to get back the value of the just
created primary key in order to insert children.
The solution provided today uses a @LASTINCVAL (I do not remember any more
how it was called exactly) to insert child records. How could this work for
example in a self-referencing relation? Ron asked if we wanted to add a
parameter to that function in order to specify the table name. IMHO this
would be a solution but not for all scenarios; how could we cope with a
multiple parent's relationship (like humans usually have) where a child
record has two parent records?
Well a 'state of the art' solution would "bind-back" the value! I imagine we
could do something like that:
insert into MyTable( MyPk, Col1, col2, ...
values( ;nMyReceivePk, :sCol1, :sCol2, ...
Note that I put a ';' instead of ':' (for the PK) so that the server would
know that I need the value back and that the autoincrement functionality
must be used. On the other hand the server would not use the autoincrement
if I would have used a ':' and would have behaved normally (= inserting the
value I'm passing). And maybe we could use that feature even for not null
with defaults columns.
Ok, assuming that I have no idea on the way inserts are implemented, I would
even appreciate another solution like...
Set nMyPkValue = SqlPrepareAndExecuteInsert( hSql, 'insert ......)
or maybe
Set bOk = bOk AND SqlPrepareAndExecuteInsert( hSql, nMyReceivePk, 'insert
......)
Any other suggestion ?
Mirko