Gossamer Forum
Home : Products : DBMan : Customization :

Adding/modifyng ONE field in other/external db

Quote Reply
Adding/modifyng ONE field in other/external db
Hi there,

I need help with adding/modifyng ONE field in other/external db.
I have checked the forum and the FAQ for weeks, days and hours now (also the relational MOD), but can't simply find out how to do that...

Anyone who can deliver the complete routine (not sub) for that?

Thanks in advance
Quote Reply
Re: [seasky] Adding/modifyng ONE field in other/external db In reply to
Without much more information it's not possible to provide a complete solution as you are requesting :)

If you check the unofficial DBMan FAQ there are several threads which may help you find a solution:

I would suggest looking under the categories: Multiple, Files, and Fields

One thread which may be of help under the "Files" category is:

Update 2 databases - this shows how someone is updating 2 databases with specific information.

You would need to list all of the fields for your particular application.


It helps to look at various ways people have come up with solutions in the FAQ because for me anyway I gained an understanding of how the script worked and learned to come up with some of my own solutions by using examples. I'm not a programmer :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Adding/modifyng ONE field in other/external db In reply to
Thanks Lois, I will have a look at Update 2 databases, else I will be more specific in my next post.
Yes, I do work pretty much the same as you describe your own, but this time it seems there is no way. As above, I'll be back if no solution in Update 2 databases...

Thanks again
CSky
Quote Reply
Re: [seasky] Adding/modifyng ONE field in other/external db In reply to
The code in 'Update 2 databases' is too complex and also assumes that the file read has only two fields ($db_userid and Email) with the delimiter inbetween. I do not understand how it could be easily altered to fit my needs. I think I am in need of clear/distinct help, so, below, find a description of how things should work (and already work):

The Admin adds a general message to a static page which can be read by all users:

-Everybody who has not read the message gets a flashing icon (DONE)
-Those who have read the message will get a 'normal' non-flashing icon (NOT DONE)

My external database has 12 or (eventually) more fields to come. The 13th field in cfg looks like this:

Adminmessage => [12, 'alpha', 1, 1, 0, '', ''],

In the database, in every user's Adminmessage field it should either contain a 1 (message not read) or a 0 (message read).

The writing of either the 0 or the 1 to ALL user's Adminmessage-field I have already solved. So every user potentially knows when there's a new message and when not.

What I need to achieve is the individualization of the 0 or the 1, because, as it is now, I can only flag either 0 or 1 for ALL users, but when they have read the message individually, I haven't any idea how to write the routine to open (USERINFO, ">$db_script_path/userinfo.db") and having the zero (0) written to the respective users' Adminmessage-field (to ONLY have THAT users field containing a zero (0)), while the others that haven't read the message, still have a one (1)...

Hope this was an understandable description and thanks for listening.

CSky
Unsure
Quote Reply
Re: [seasky] Adding/modifyng ONE field in other/external db In reply to
While the first (green) snippet was the solution to my request above (I finally seem to have figured out how to write a 0 to an individual user's record), the second (red) snippet should add either a 0 or a 1 to ALL records, which doesn't work.

Instead, the userinfo.db file is emptied entirely and the file is locked for some minutes...

OK CODE:
----------------
open (DB, "<$data_file ") or &cgierr("unable to open $data_file.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
$found = 0;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
chomp ($line);
@data = &split_decode($line);
if ( $data[1] eq $prenumerant) {
$found=1;
$data[12]="0";
%hash = &array_to_hash(0,@data);
$output .= &join_encode(%hash);
$temp = $data[1];
}
else { $output .= "$line\n"; }
}


if ($found) {
open (DB, ">$data_file ") or &cgierr("unable to open db file.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $data_file.\nReason: $!");
}
print DB $output;
close DB;
}



NOT OK CODE:
------------------------
open (DB, "<$data_file ") or &cgierr("unable to open $data_file.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($nollstall eq "1") {
$data[12]="0";
}
else {
$data[12]="1";
}

%hash = &array_to_hash(0,@data);
$output .= &join_encode(%hash);
}

open (DB, ">$data_file ") or &cgierr("unable to open db file.\nReason: $!");
if ($db_use_flock) { flock(DB, 2); }
print DB $output;
close DB;


Can anyone see why?

Thanks in advance.

Csky