This feature offers higher code legibility and data base
integrity; it also gives power to programming. This means that instead of
defining a given numbering that depends on the application calling it, the
developer makes sure that there will be no "holes" generated in the numbering,
which will be configured on the database.
Description
When a table
has a simple key, (which means that it is made up of a single attribute), and
there is a numerical data-type, it may be automatically numbered by using the
feature provided by database handlers with this aim in mind. The way to do this
in GeneXus is by configuring the auto-number property from the table's key
attribute. For this, it is necessary to be in the design model and configure the
key attribute's advanced properties of the auto-number group.
When using the
"Enabled" property, the automatic generation of the numbering in the associated
table is defined. This only affects database creations/reorganizations.
When
using the "Star" property, you may configure what will be the starting number in
order to proceed with automatic numbering. The "Step" property enables you to
configure the increase for the field (between two records).
Does it apply to compound keys?
No. It only applies when the attribute is, in itself, a table's
key. It does not apply for compound keys or secondary attributes. For instance,
for second-level auto-numbering the rule serial or a numbering procedure must be
used.
Is the property valid in procedures?
Yes. It is valid in all of the objects that allow data input
(transactions and procedures), both with Win and Web interface. It is supported
by the .NET, C/SQL, Visual Basic, Visual Fox Pro and Java languages, and all
database handlers, except for dbf.
How can I verify if the property is being considered?
As we said earlier, this property is valid for
creation and reorganization, which means that in the creation/reorganization
impact analysis, warnings are displayed when the auto-number property is
ignored.
When the property is assigned to a non-primary-key field, the
message is AutoNumbe=True ignored. Attribute %1 is not table %2's primary key.
It also warns if it is not implemented in the database handler, in which
case the message is: AutoNumber=True ignored for attribut %1. Autonumbering is
not supported in this DBMS.
How can the new key's value be obtained when releasing
records in a procedure?
By having a
transaction with the following structure:
AttId*
AttDsc
where AttId is N(6) and has the
auto-number property in True, and a procedure with the code:
new
Attdsc = &Attdsc
endnew
In order to obtain the key number, the AttId attribute
must be referenced immediately after the EndNew attribute. Keep in mind that
this may affect the procedure's browsing.
How is it implemented?
Not all the DBMS provide the same support in order to implement
this feature. The implementation's detailed information for each of the handlers
may be useful for database administrators; refer to the Release Notes.
Example
You can check out an example
at
http://www.gxopen.com.uy/hproject.asp?122