PDA

View Full Version : Game Data - Adlers Hack 27 Trouble



MrBoston
09-29-2007, 05:30 PM
This might have been covered in other threads, if so I appologize (I could not find it). I am having trouble when running alers Hack 27 update_db.pl. I wonder if the format has changed? Perhaps a version conflict on MySql.pm?

I am not a perl expert so this is a bit frustrating. I am not trying to get PBP date, rather just the boxscores from each game. Any help would be appreciated.

error:

C:\Perl\bin>perl load_db.pl
iterating from Sun Apr 3 00:00:00 2005 to Fri Sep 28 12:40:26 2007
fetching box score for game gid_2005_04_03_anamlb_lanmlb_1
DBD::mysql::st execute failed: Data too long for column 'pos' at row 1 at C:/Per
l/site/lib/Mysql.pm line 175.
MySQL Error: Mysql=HASH(0x183f07c)->

C:\Perl\bin>

mikefast
09-29-2007, 08:02 PM
If I interpret the messages prior to the error correctly, the error is occurring when you try to update the fielding data. If so, can you insert a debug line into the Perl script save_to_db.pm to help isolate the problem?

If you insert the following print statement before Line 140 and tell me the results, I might be able to help you more.

print "$fldr_query\n"; # Insert this debug statement
$sth = $dbh->query($fldr_query); # This is Line 140

MrBoston
09-30-2007, 03:36 AM
Thanks for the help MIke. I have inserted your debug code at line 140 and obtained the following results. Maybe its coking on the double position RF-CF?

C:\Perl\bin>perl load_db.pl
iterating from Sun Apr 3 00:00:00 2005 to Fri Sep 28 22:50:24 2007
fetching box score for game gid_2005_04_03_anamlb_lanmlb_1
INSERT INTO fielding VALUES (285131,'lan','2005/04/03/anamlb-lanmlb-1','2005-04-
03','SS',0,0,0,0)
INSERT INTO fielding VALUES (213711,'lan','2005/04/03/anamlb-lanmlb-1','2005-04-
03','SS',0,2,0,0)
INSERT INTO fielding VALUES (434705,'lan','2005/04/03/anamlb-lanmlb-1','2005-04-
03','RF-CF',2,0,0,0)
DBD::mysql::st execute failed: Data too long for column 'pos' at row 1 at C:/Per
l/site/lib/Mysql.pm line 175.
DBD::mysql::st execute failed: Data too long for column 'pos' at row 1 at C:/Per
l/site/lib/Mysql.pm line 175.
MySQL Error: Mysql=HASH(0x183f07c)->

C:\Perl\bin>

mikefast
09-30-2007, 09:16 PM
Thanks for the help MIke. I have inserted your debug code at line 140 and obtained the following results. Maybe its coking on the double position RF-CF?

That's what it looks like to me. And if I look in my copy of Hacks on page 132, the fielding.pos field is defined as CHAR(2) in the database, so that would seem to explain the error.

I'm not sure what you're trying to do with this database, but that would determine whether you want to change the database to accept longer position strings or whether you want to truncate the position to only be the first position in the list.

SABR Matt
09-30-2007, 09:49 PM
You can get perl to read in that string as multiple variables separated by the dash (RF-CF, for example). That way you can save the RF and CF as primary and secondary position.

MrBoston
10-21-2007, 08:16 AM
Success. Thanks Matt.

wavygravy2k
04-10-2009, 01:51 PM
I know this is an old thread but someone might find this useful. I have a machine where I use:

use Mysql;

to connect to MySQL (4.1.x) and it automatically truncates the value.

On another machine I had issues connecting to MySQL (5.1.x) but was finally able to figure it out by using this 'module':

use DBI;

When I connect with DBI I run into the same errors MrBoston encountered. Anyways, instead of reading the string as multiple variables as SABR matt suggested I decided to find a way to truncate the value so it works like it did before. I added:

$batter->{pos} = substr $batter->{pos}, 0,1;

to save_to_db.pm on a line just before the INSERT INTO fielding... statement.