[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[coldsync-hackers] finding a suitable record id for appendrecord
- To: <coldsync-hackers at lusars dot net>
- Subject: [coldsync-hackers] finding a suitable record id for appendrecord
- From: "Brian Johnson" <bjohnson at jecinc dot on.ca>
- Date: Tue, 16 Apr 2002 08:37:08 -0400
- Importance: Normal
- Reply-To: coldsync-hackers at lusars dot net
- Sender: owner-coldsync-hackers at lusars dot net
I keep running into the situation where I need to know the record id of a
new record I'm adding (to track it for syncing to another data source)
So far I've just been finding the biggest id number and adding one to for
each record I add like so:
my $counter = 0;
my $record;
foreach $record (@{$PDB->{records}}) {
if ( $record->{id} gt $counter ) {
$counter = $record->{id};
}
}
$counter = $counter + 1;
$record->{id} = $counter;
But I'm starting to get into a conduit where I realistically could very
quickly get to uppermost id number (around 32000 isn't it - it was post
SO .... I was wondering if we could work together to get a working routine
that everyone could use as needed
Since once we get to the top, the open id numbers could be scattered, we
need to check all the records.
I wondered about something like (is there a way to start the loop at the
last $counter value or fill up the ones at the high end of record id number
before filling in the rest? - I want to improve the speed)
$record = $PDB->append_Record;
$counter = $counter + 1;
$record->{id} = &get_record_id;
sub get_record_id {
my $counter = 0;
my $record;
foreach $record (@{$PDB->{records}}) {
# see if this record id is more than one more than the last one = blank
record(s) in there
if ( $record->{id} gt ($counter+1) ) {
# get out of for loop
last;
} else {
$counter = $record->{id}
}
} # for
$counter=$counter+1;
return $counter;
} # sub get_record_id
--
This message was sent through the coldsync-hackers mailing list. To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body. For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.