Contents Index How default values are chosen Detecting the number of available default values

UltraLite Database User's Guide
   Synchronization for UltraLite Applications
    Designing synchronization for your UltraLite database
      Maintaining primary key uniqueness

Determining the most recently assigned value

You can retrieve the value that was chosen during the most recently insert operation. Since these values are often used for primary keys, knowing the generated value may let you more easily insert rows that reference the primary key of the first row.

From embedded SQL, you can obtain the most recently assigned global autoincrement default value using the following statement.

select @@identity

From the C++ API, the value is available using the GetLastIdentity() method on the ULConnection object

The returned value is an unsigned 64-bit integer, database data type UNSIGNED BIGINT. Since this statement only allows you to determine the most recently assigned default value, you should retrieve this value soon after executing the insert statement to avoid spurious results.

Occasionally, a single insert statement may include more than one column of type global autoincrement. In this case, the return value is one of the generated default values, but there is no reliable means to determine which one. For this reason, you should design your database and write your insert statements so as to avoid this situation.


Contents Index How default values are chosen Detecting the number of available default values