[V4RB] autoincrement // New comment from ricardo

Ruslan Zasukhin ruslan_zasukhin at valentina-db.com
Tue Aug 18 01:58:08 CDT 2009


On 8/18/09 1:24 AM, "Rick" <ricksaiz at gmail.com> wrote:

Hi All,

> Joao,
> 
> As you are using V4RB I believe there is another way.
> There is no need of autoinc field for an index key. RedId is it already.
> 
> Create a cursor with recid in the field list selecting an empty record.
> Add a new record.
> Get the recid field for the new record under the cursor.
> Fill up the fields.
> Update.
> 
> Now you have the recid for "A". Use it in "B".

Yes this way also can be used if RecID behavior is okay for your tasks.

But if RECID is okay for you, then I wonder why at all to have that ID field
and fill it by values of recid ?!

Just use RecID field then.



> --------
> 
> Ruslan, I believe we need some function like LastRecIdQ("QUERY STRING")

> This function will return the LAST RecId affected/returned by the query. If
> the query is a single insert it solves the question of Joao, but give us extra
> powers like after an update/delete we can get the recId of the last affected
> row and use it for extra functions for example.

You mean predict future RecID ? :-)

This cannot be made. Because in case of multi-user, this future recID can be
eaten by other user.


> It could be used for cascaded querys like:
> 
> INSERT INTO B (F1,F2,PARENTID) VALUES (3,4,LastRecIdQ("INSERT INTO A (F1,F2)
> VALUES (1,2)"))

Guys,

What task you have on hands?

I think you can solve everything using RecID and ObjectPtr fields.


 
> Best regards,
> 
> RA.
> 
> -----Mensagem original-----
> De: Valentina Ticket [mailto:info at valentina-db.com]
> Enviada em: segunda-feira, 17 de agosto de 2009 09:19
> Para: ricksaiz at gmail.com
> Assunto: New comment from ruslan
> 
> Hi,<br />
> <br />
> 1) RecID is reused. So be careful.<br />
> <br />
> 2) to use RecID, I think it is possible write for this table TRIGGER  AFTER
> INSERT and then you get access to RecID value.<br />
> <br />
> 3) Another way, you self create special table in DB, which keeps pairs (if
> needed)<br />
>      tblLastValues ( fldTableName, fldValue )<br />
>             T1 - 145<br />
>             T2 - 12345<br />
>             T3 - 6<br />
> <br />
> To get next value for T3, you take its 6, <br />
>             SELECT fldValue FROM tblLastValues<br />
> <br />
> make <br />
>          UPDATE tblValues  ... SET fldValue = fldValue + 1<br />
> <br />
> and now you get on hands value you need.<br />
> <br />
> also you can CREATE FUNCTION ... with above two commands to do them on
> server-side.<br />
> <br />
> <br />
>  

-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list