Gossamer Forum
Home : Products : DBMan : Customization :

Modify multiple records w\ all data hidden

(Page 1 of 2)
> >
Quote Reply
Modify multiple records w\ all data hidden
Hey all. I added some code to my db.cgi file from JPDeni last year to automatically add the contents of two fields together into one empty exsisting field. All I have to do is update a record without even changing anything, and it adds two fields and puts the sum into a blank field.

Now what I need to do is modify multiple fields at once, and all fields can be hidden.

Is there a way to do this? In case anyone is wondering, the .db file is being imported from other software on a daily basis with a blank field and two fields that I want to add up and have in the blank field right after importing the database each day.

Thank you very much.

Mike
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
You would have to explain what you're doing in much more explicit detail before I could tell you what you're doing. It would also help if you could point me to the code I gave you earlier so that I could build on what I wrote before.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Thanks for the reply. Here is the original thread:

http://www.gossamer-threads.com/perl/gforum/gforum.cgi?post=292282

I have the code supplied in the above thread added, which worked, but only for modifying each record one-by-one (I have over 800 records that will be needed to be updated daily as the database is imported from another program daily).

I've installed your modify multiple entries mod:

http://jpdeni.com/dbman/Mods/multmod.txt

But when I try to modify multiple entries at the same time it tells me that every field has too many characters compared to what I have allowed in the cfg file even though this clearly doesn't seem to be the case. I tried upping the maxlength in the cfg file for each field, which resulted in the record completely disappearing when edited.

Any ideas? Thanks a bunch

Mike
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
I've turned on debug mode and after unsucessfully modifying multiple records because each field is apparently too long, the debug info tells me that each field is trying to add ALL records' info to all fields.

For example:
Code:
Form Variables
-------------------------------------------
A : 5~~18~~15~~23~~13~~0~~34~~43~~30~~41~~8~~34~~3~~42~~12~~14

"A" is a field in my database. The 5, 18, 15, 23, etc is the "A" field for many many records in my database. So instead of just adding the data for this record it tries to add the data of all the other records to it.
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
Okay. You've got a database of hockey players. Each record is for an individual player. There's some sort of identifier and then there's Total Goals, Total Assists and Total Points. (I got this from the previous discussion.) You get more information -- goals and assists -- on each player on a regular basis and you want to be able to automatically update the .db file. Yes?

The modify multiple mod is not something that would come into play here at all. You want this to be done completely behind the scenes, if I get your drift. What I see as the optimum is for you to be able to upload a file with the stats you want to add, click a link in DBMan, have it run a little subroutine which automatically updates .db file as it incorporates the new stats file, and then gives you a note that says "It's all done" along with any errors that it might have encountered.

So.... The first thing is to know what the format of the file with the new stats is.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
The stats come to me as a .db file with all info seperated by semicolons, and I use this as my database for dbman. The only thing is, it has fields for goals and assists for each player but not points, however it does have a blank field which I want to be able to add up goals + assists and plunk the sum into.
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
Now I'm confused again. :)

Can you give me an example?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Ok :)

Lets say I get stats sent to me in a text file that I rename to default.db, and it lists each record like this:

|Joe Smith|2|3

And I want to have each line look like this in relation to the above example:

5|Joe Smith|2|3
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
So Joe Smith isn't already in the database and you're not really modifying anything, but rather just adding new records?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Joe Smith is in the database, and every day when the database is updated from the outside source, Joe Smith is reset back to this:

|Joe Smith|2|3

Therefore every day after the database is imported Joe Smith is reset to the above, and I would want to do a routine that puts Joe Smith to this:

5|Joe Smith|2|3
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
I get it. You're overwriting the existing data with the new data. I take it that, if there is no new data, the old data stays. If there's no old data, the new data is inserted. These last two situations may never happen, but it's the sort of thing that I have to take into consideration, just in case there's some sort of fluke.

I'll get to you once I finish with Syte's issue. So strange that months go by with no one posting here at all and then suddenly there's two requests for substantial mods at the same time. :) Ain't it the way?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Thanks!

I get a new .db file from an outside source on a daily basis, so every record will be "reset" to having no TotalPoints data in the first field on a daily basis. I update the database by simply uploading the entire new .db file and overwriting the entire old .db file daily. Hopefully we're on the same page :) Thanks again
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
Okay. So you don't really care what was previously in the database. All you care about is transforming the data in the daily database. That at least makes things easier. :)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Correct :) Thank you!
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Please don't forget about me again Smile
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
I haven't and I won't. :)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
The mod is in the attached file. I've not tested it because I had nothing to test it with. It should work, though.


Removed attachment.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Feb 14, 2007, 7:35 PM
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Thank you! I will try this code ASAP, possibly tonight. Thanks again
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
I've tried adding it and it results in all dbman pages having an internal server error.

If I delete sub transform_records then dbman works again.

If there's any information I can provide to make it easier please let me know. Thanks JPDeni.

Mike
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
Well, obviously there's some sort of syntax error in the code. If you'll post your db.cgi and html.pl files, it'll make it easier for me to find the problem.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
Thank you again. Here they are.
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
For some reason, .txt files are no longer displayed just as text, but are parsed. I'll try posting the changes here.

Delete the changes you made.

Code:

html.pl
sub html_footer
after
print qq!| <A HREF="$db_script_link_url&admin_display=1">Admin</A> ! if ($per_admin);
add
print qq!| <A HREF="$db_script_link_url&transform=1">Process file</A> ! if ($per_admin);


Code:

html.pl
new subroutine
add it anywhere, as long as it's not within another subroutine
sub &html_transform_success {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# transformed.
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Record(s) Transformed.</title>
</head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Record(s) Transformed.</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Record(s) Transformed
</b></font></center><br>
<$font>
The records were successfully transformed.
</font></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}


Code:

db.cgi
sub main
after
elsif ($in{'modify_record'}) { if ($per_mod) { &modify_record; } else { &html_unauth; } }
add
elsif ($in{'transform'}) { if ($per_admin) { &transform_records; } else { &html_unauth; } }


Code:

db.cgi
new subroutine
add it anywhere, as long as it's not within another subroutine

sub transform_records {
# --------------------------------------------------------
# This routine does the actual modification of a record. It expects
# to find in %in a record that is already in the database, and will
# rewrite the database with the new entry. First it checks to make
# sure that the modified record is ok with validate record.
# It then goes through the database looking for the right record to
# modify, if found, it prints out the modified record, and returns
# the user to a success page. Otherwise the user is returned to an error
# page with a reason why.
my ($status, $line, @lines, @data, $output, $found, $restricted);

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\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; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
$data[0] = $data[2] + $data[3];
$in{$db_cols[0]} = $data[0];
$in{$db_cols[1]} = $data[1];
$in{$db_cols[2]} = $data[2];
$in{$db_cols[3]} = $data[3];
$output .= &join_encode(%in);;
}
open (DB, ">$db_file_name") or &cgierr("error in modify_records. unable to open db file: $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 $output;
close DB; # automatically removes file lock
&auth_logging("modified record: $in{$db_key}") if ($auth_logging);
&html_transform_success;
}
}


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
I was able to see the txt file displayed as plain text by right-clicking and selecting Save As.
Quote Reply
Re: [Dempsey] Modify multiple records w\ all data hidden In reply to
Oh. Because what you had in your files was different than what was in the .txt file.

Did you try it again?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Modify multiple records w\ all data hidden In reply to
I originally tried adding the text you provided and it gave an internal server error, and that's when I made a few changes that you're seeing. When right-clicking and saving to a txt file the text looked exactly as you typed it out yesterday. I can try it again later tonight though :)

Thanks

Mike
> >