Gossamer Forum
Home : Products : DBMan : Installation :

Counter v. Unique ID

Quote Reply
Counter v. Unique ID
Hi,

What configuration should be used to have both a counter and a unique ID? My current settings are as follows:


$db_key = 'Name';
$db_key_track = 0;

If I set $db_key_track=1, The counter puts the number in the 'Name' box. The db_refs are:

ID => [0, 'numer', 5, 8, 0, '', ''],
Division => [1, 'alpha', 0, 255, 1, '', ''],
Name => [2, 'alpha', 32, 40, 1, '', ''],

If you are wondering why the 'not_null' for the ID Field is set to '0', I wanted the input box for the Add_User Form to be hidden, to be seen only when viewed. However, when I set it to '1', an error message was given to users that the ID number was missing, so I changed it to '0' and turned the counter off.

What should the settings be to maintain both a hidden ID Field for users and a counter still dropping in numbers in the ID Field?

Melvin
Quote Reply
Re: Counter v. Unique ID In reply to
Set the key to be 'ID':

$db_key = 'ID';
$db_track_key = 1;

and then make ID a hidden field. If you are using auto generate, then just set the form length to -1. Otherwise just add a hidden field on your html.pl.

Cheers,

Alex
Quote Reply
Re: Counter v. Unique ID In reply to
Alex,

Guess I was only partly clear in my explanation. The reason that I have the db_key set to 'name' is that I found people putting in multiple additions. So, I needed to make sure that the db_key was always unique to prevent this. Take a look at it yourself:

http://www.percolations.net/...bman/mod.cgi ?db=mod

Melvin
Quote Reply
Re: Counter v. Unique ID In reply to
Wanted to assign tracking numbers for future searches, rather than typing in names.

Melvin
Quote Reply
Re: Counter v. Unique ID In reply to
If you are using the name as the key then, why do you need an ID field? =)

Cheers,

Alex
Quote Reply
Re: Counter v. Unique ID In reply to
You could add into validate_record:

($data[3] eq $in{'Field'}) and return "duplicate field error";

Where 3 is the field number, and Field is the field name. This will provide the same uniqueness check that is done for the key for some other field.

Hope this helps,

Alex
Quote Reply
Re: Counter v. Unique ID In reply to
Alex,

Thanks for the tip. Below is my modification of validate_record. Is this the best place for your insert?

--------------BEGIN SCRIPT-------------
if ($in{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
($data[3] eq $in{'Field'}) and return "duplicate field error"; # Insert new validate text here
}
}
close DB;
------------END SCRIPT------------------

Melvin

------------------
Network solutions for Home & Office
Quote Reply
Re: Counter v. Unique ID In reply to
Hi Melvin,

It looks like the proper place to me...

One note though...
I think that in your case the line should look like
($data[2] eq $in{'Name'}) and return "duplicate field error"; # Insert new validate text here

Since you are trying to have unique names

cheers

-JO