dBASE Programming - Re: Autoinc field

This is Interesting: Free IT Magazines  
Home > Archive > dBASE Programming > March 2005 > Re: Autoinc field





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Autoinc field
Gerald Lightsey

2005-03-28, 6:10 pm

On Sat, 19 Mar 2005 05:31:30 +1200, in the dbase.programming group,
Dinesh Chauhan said...
> I have table level 4 in my database. How can I make keyfield(index) Autoinc
> field? Because I want to validate that field with unique field value so I
> can not enter the duplicate value for that field.. Like Romain Strieff has
> said "Using an AUTOINC field makes all this moot, no coding needed, they're
> always UNIQUE".
>
> From: dBVIPS@use.net (Romain Strieff [dBVIPS])
> Newsgroups: dbase.programming
> Subject: Re: Entryfield Validation
> Date: Sat, 24 Jul 1999 05:39:39 +0200
>
> Better move to form-level validation, done when the user tries to save.
> Your code won't work anyway if you move the record pointer in the same
> rowset during the append, it would have to use an additional copy of the
> table to do such things as moving the mointer during buffer operations.
>
> Using an AUTOINC field makes all this moot, no coding needed, they're
> always UNIQUE.


I'm not sure if I am answering what you want to know, but I will give it
a try and hope for the best.

If you are using level 4 tables the creation an autoinc field is NOT
automatic as it CAN BE when using level 7 tables. That's the bad news.
The good news is that you can still create and use autoinc fields in
your code WITHOUT SOME OF THE RESTRICTIONS you run into with the
automatic autoinc fields you can have in level 7 tables. Obviously, you
can also have your own created autoinc fields in level 7 tables that do
not depend upon the automatic features available within level 7.

There are probably as many ways to approach this as there are
programmers, but here is what I do. Within my datamodule I have a table
named Autoinc.dbf with the following structure.
INCTABLE C 10
INCFIELD C 10
INCVALUE N 10 0
_DBASELOCK C 24

The table is indexed on lower(inctable + incfield) tag TABLEFIELD. It
has the capability of maintaining the autoincrement numbers required for
an entire application.

In a table such as Provider.dbf I have a field named PROVAUTO which is
my autoinc field. My own preference is to have that number be Character
data type, zero filled ahead. The first number I would assign would be
"0000000001". To start the system off I place the following values in
the table above, ("provider", "provauto", 0).

The typical code I use to generate the autoinc number, for example when
I am saving a new record in Provider.dbf, is in the snippet that
follows. (watch for word-wrap)
*---------------------------------------------------------------------
// use the appropriate number of spaces to pad the table name
// and field name to EXACTLY match the composite index key
form.mydatamodule1.autoinc1.rowset.findKey( "provider" + space(2) +
"provauto" + space(2) )

incOldNValue := form.mydatamodule1.autoinc1.rowset.fields
["incvalue"].value

++ form.mydatamodule1.autoinc1.rowset.fields["incvalue"].value

form.mydatamodule1.autoinc1.rowset.save()

incNewCValue := str(incOldNValue + 1,10,0,"0")
*---------------------------------------------------------------------

incNewCValue is the character value I will input into the new provider
record's provauto field before I save it, as well as anywhere else I
need it for other linked tables.

Gerald

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com