function

lastuid . database . sncode

VERSIONlatest Returns last uid of an auto_increment field.

LASTUID

NAME

lastuid - Returns last uid of an auto_increment field.

SYNOPSIS

lastuid(( [db:pointer] );

DESCRIPTION

This function is used to return the last UID, that is the user identifier last used in an auto_increment field.

In a database such as MYSQL, you can add information. When a next element is added, and if it’s an auto_increment, this information will be indexed. This is the UID.

The user might need this function to find the number (UID) characterizing the last piece of information added to the database

PARAMETER

db
Specifies alternate database pointer as return from connect function

RETURN

uid

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

res={_{
       a=sql("drop table IF EXISTS ? ;","sn_test1");
       a=sql("create table sn_test1 (uid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
       firstname varchar(255), lastname varchar(255), sn_cdate datetime, sn_mdate datetime,
           sn_cuid int, sn_muid int);");
       for(i=1;i<=5;++i) do
           a=sql("insert into sn_test1 set firstname = '?', lastname='?';", "f" .+ i,"l" .+ i );
           lastuid();
       endfor
       i=insert(table:"sn_test1",fields:{firstname:"pierre",lastname:"laplante"});
       i.uid;
       lastuid();
       .

       return res=1234566.

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>