Gossamer Forum
Home : Products : DBMan : Customization :

Ask update 2 db

Quote Reply
Ask update 2 db
Hello all,

I have one default.db with ID and email fields.
Now I want setup one new email.db which field is ID Email 2 field only.

When user update the email in default.db, it will serach out the ID and then , auto REPLACE the new email into old email.

Thx


------------------
Quote Reply
Re: Ask update 2 db In reply to
In db.cgi, sub add_record, after

Code:
open (DB, ">>$db_file_name") or &cgierr("error in add_record.
unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB &join_encode(%in);
close DB; # automatically removes file lock

add

Code:
open (EMAIL, ">>$db_script_path/email.db") or &cgierr("error in add_record.
unable to open database: $email.db.\nReason: $!");
if ($db_use_flock) {
flock(EMAIL, 2) or &cgierr("unable to get exclusive lock on $email.db.\nReason: $!");
}
print EMAIL $db_userid . $db_delim . $in{'Email'} . "\n";
close EMAIL; # automatically removes file lock

In sub modify_record, after

Code:
&auth_logging("modified record: $in{$db_key}") if ($auth_logging);
&html_modify_success;

add

Code:
$found_email=0;
$output_email = '';
open (EMAIL, "<$db_script_path/email.db") or &cgierr("error in modify_records.
unable to open db file: email.db.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <EMAIL>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
if ($data[1] eq $in{$db_userid}) {
$output_email .= $in{$db_userid} . $db_delim . $in{'Email'} . "\n";
$found_email=1;
}
else {
$output_email .= $line . "\n";
}
}
unless ($found_email) {
$output_email .= $in{$db_userid} . $db_delim . $in{'Email'} . "\n";
}
open (EMAIL, ">$db_script_path/email.db") or &cgierr("error in modify_records.
unable to open db file: email.db.\nReason: $!");
if ($db_use_flock) {
flock(EMAIL, 2) or &cgierr("unable to get exclusive lock on
$email.db.\nReason: $!");
}
print EMAIL $output_email;
close EMAIL;

Has any of the other code I've given you worked? You have never said.


------------------
JPD







[This message has been edited by JPDeni (edited July 07, 1999).]
Quote Reply
Re: Ask update 2 db In reply to
Thx JPDeni

Quote Reply
Re: Ask update 2 db In reply to
Hello JPDeni

How about the del?

Thx
Quote Reply
Re: Ask update 2 db In reply to
What about it? I don't know what you mean.

------------------
JPD





Quote Reply
Re: Ask update 2 db In reply to
Hello JPDeni,

I mean delete the record.
How about the delete record in 2 db.

Thx
Quote Reply
Re: Ask update 2 db In reply to
In db.cgi, sub delete, change

Code:
$delete_list{$data[$db_key_pos]} ? # if this id is one we want to delete
($delete_list{$data[$db_key_pos]} = 0) : # then mark it deleted and don't print it to the new database.
($output .= $line . "\n"); # otherwise print it.

to

Code:
if $delete_list{$data[$db_key_pos]}) {
$delete_list{$data[$db_key_pos]} = 0;
$email_output = '';
open (EMAIL, "<$db_script_path/email.db") or &cgierr("error in delete_records.
unable to open email file: $email.db.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@email_lines = <EMAIL>;
close EMAIL;
foreach $email (@email_lines) {
unless ($email =~ /^$db_userid/) {
$email_output .= $email . "\n";
}
}
open (EMAIL, ">$db_script_path/email.db") or &cgierr("error in delete_records.
unable to open db file: email.db.\nReason: $!");
if ($db_use_flock) {
flock(EMAIL, 2) or &cgierr("unable to get exclusive lock on email.db.\nReason: $!");
}
print EMAIL $email_output;
close EMAIL;
}
else {
$output .= $line . "\n"
}

I noticed an error in what I gave you before. I'll fix it now.

------------------
JPD





Quote Reply
Re: Ask update 2 db In reply to
Hello JPDeni


The email.db record format is "Login_ID<a space>Email" It means the $db_lim = ' ' between 2 field.
However the default.db's $db_lim ='|'.

How can I do it?

Thx very much

Gab

------------------
Quote Reply
Re: Ask update 2 db In reply to
I answered this in the other post.

Change

Code:
print EMAIL $db_userid . $db_delim . $in{'Email'} . "\n";

to

Code:
print EMAIL "$db_userid $in{'Email'}\n";


------------------
JPD





Quote Reply
Re: Ask update 2 db In reply to
Hello JPDeni

I try it, but it can not search out the record for update in the modify mod.
I believe the $db_lim has problem.

Thx

Gab

------------------
Quote Reply
Re: Ask update 2 db In reply to
Okay, try changing

Code:
@data = &split_decode($line);
if ($data[1] eq $in{$db_userid}) {
$output_email .= $in{$db_userid} . $db_delim . $in{'Email'} . "\n";

to

Code:
if ($line =~ /^$db_userid /) {
$output_email .= "$in{$db_userid} $in{'Email'}\n";



------------------
JPD





Quote Reply
Re: Ask update 2 db In reply to
Hello JPDeni


Everything is work, thank you for your helping.

Thx

Gab