DBD::mysql::st execute failed

--20cf30433d84e0abc0049c1db831
Content-Type: text/plain; charset=ISO-8859-1

i'm getting this error:
DBD::mysql::st execute failed: Column count doesn't match value count at row
1 at ./test-get.pl line 91, <FILE> line 1.
DBD::mysql::st execute failed: Column count doesn't match value count at row
1 at ./test-get.pl line 91, <FILE> line 1.

and i've been counting placeholders, columns, and variables and everything
seems to match up. any ideas what i'm missing?

btw, line 91 is the $shipsth->execute( .. ) call. this seems to have 20
fields.


#!/usr/bin/perl

use strict;
use warnings;
#use Carp::Always;

use DateTime;
use DateTime::Format::Natural;
use LWP::UserAgent;
use LWP::Simple;
use Web::Scraper;
use Data::Dumper::Simple;

use lib '/home/shawn/test/ais';
use uscgDBConnect;

my $pageth = $dbh->prepare('INSERT INTO page (
vid, date, data
) VALUES( ?, ?, ? )'
) or die "QUERY FAIL: $DBI::errstr\n$!\n";

my $docsth = $dbh->prepare('INSERT INTO docs (
vid, issue, expiration, document, agency
) VALUES( ?, ?, ?, ?, ? )'
) or die "QUERY FAIL: $DBI::errstr\n$!\n";

my $shipth = $dbh->prepare('INSERT INTO ship (
vid, service, name, tonnage_gt, build, lastrmby,
altvin, depth, hullid, flag, endservice, cargoauth,
tonnage_grt, length, vin, tonnage_net, callsign,
imo, deadweight, breadth
) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
?, ?, ?, ?, ?, ?, ?, ?, ?, ? )'
) or die "QUERY FAIL: $DBI::errstr\n$!\n";


my( $infile ) = $ARGV[ 0 ] =~ m/^([\ A-Z0-9_.-]+)$/ig;
my( $vid ) = $ARGV[ 1 ] =~ m/^([\ A-Z0-9_.-]+)$/ig;

my $ship = scraper {
process '//*/div[ [at] id="PanelResults"]/table/tr/td', 'table[]' => scraper {
process '//span', 'name' => ' [at] id', 'attr' => ' [at] title';
};
process '//*//table[ [at] id="GridViewDocuments"]/tr', 'docs[]' => scraper {
process '//tr', 'attr' => ' [at] title';
};
};


open(FILE, "< $infile" );
my $content = do { local $/; <FILE> };

{

$pageth->execute( $vid, time(), $content );

my $res = $ship->scrape( $content )
or die "Can't define content to parser $!";


my %values;
foreach my $data ( [at] {$res->{ table } } ) { # Define scraped
data to simpler values hash

next unless $data->{ name } and $data->{ attr };
foreach my $line (split /\n/, $data->{ attr } ) {
my ( $key, $val ) = split /:/, $line;
$values{ $key } = killspace( $val );
}
}

foreach my $data ( [at] {$res->{ docs } } ) { # Define scraped
documents to simpler docs hash

next unless $data->{ attr };

my %docs;

foreach my $line (split /\n/, $data->{ attr } ) {
my ( $key, $val ) = split /:/, $line;
$docs{ $key } = killspace( $val );
}

$docsth->execute( $vid,
correctdate( $docs{ 'Issue Date' } ),
correctdate( $docs{ 'Expiration Date' } ),
$docs{ 'Document' },
$docs{ 'Agency' }
) or die "EXECUTE FAIL: $DBI::errstr\n $!\n";
}


$shipth->execute( $vid,
$values{ 'Service' },
$values{ 'Vessel Name' },
correctnum( $values{ 'Gross Tonnage(GT ITC)' } ),
correctdate( $values{ 'Build Year' } ),
$values{ 'Last Removed From Service By' },
$values{ 'Alternate VINs' },
correctnum( $values{ 'Depth' } ),
$values{ 'Hull Number' },
$values{ 'Vessel Flag' },
correctdate( $values{ 'Out Of Service Date' } ),
$values{ 'Cargo Authority' },
correctnum( $values{ 'Gross Tonnage(GRT)' } ),
correctnum( $values{ 'Length' } ),
$values{ 'VIN' },
correctnum( $values{ 'Net Tonnage(NRT)' } ),
$values{ 'Vessel Call Sign' },
$values{ 'IMO Number' },
correctnum( $values{ 'Deadweight' } ),
correctnum( $values{ 'Breadth' } )
) or die "EXECUTE FAIL: $DBI::errstr\n $!\n";
}

sub killspace {
my( $val ) = [at] _;

$val =~ s/[\000-\031]//g; # Remove non alpha-numeric characters
$val =~ s/\s+/ /g; # Remove multiple spaces in a row
$val =~ s/^\s//; # Remove leading space
$val =~ s/\s$//; # Remove trailing space

return $val;
}

sub correctdate { # make valid sql DATE field
my( $date ) = [at] _;

my $parser = DateTime::Format::Natural->new;
my $dt = $parser->parse_datetime( $date );

return $dt->ymd('-');
}

sub correctnum { # Remove letters
my( $string ) = [at] _;

$string =~ s/[a-zA-Z]+//g;

return $string;
}


--- SQL DB ---

mysql> describe page;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| vid | int(10) unsigned | NO | PRI | NULL | |
| date | int(10) unsigned | YES | | NULL | |
| data | text | YES | | NULL | |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe ship;
+------------+------------------+------+-----+---------+---- ---+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+---- ---+
| vid | int(10) unsigned | NO | PRI | NULL | |
| service | varchar(25) | YES | | NULL | |
| name | varchar(50) | YES | | NULL | |
| tonage_gt | decimal(5,2) | YES | | NULL | |
| build | tinyint(4) | YES | | NULL | |
| lastrmby | varchar(50) | YES | | NULL | |
| altvin | varchar(25) | YES | | NULL | |
| depth | decimal(5,2) | YES | | NULL | |
| hullid | int(10) unsigned | YES | | NULL | |
| flag | varchar(60) | YES | | NULL | |
| endservice | date | YES | | NULL | |
| cargoauth | varchar(50) | YES | | NULL | |
| tonage_grt | decimal(5,2) | YES | | NULL | |
| length | decimal(5,2) | YES | | NULL | |
| vin | int(10) unsigned | YES | | NULL | |
| tonage_net | decimal(5,2) | YES | | NULL | |
| callsign | varchar(10) | YES | | NULL | |
| imo | int(10) unsigned | YES | | NULL | |
| deadweight | int(10) unsigned | YES | | NULL | |
| breadth | decimal(5,2) | YES | | NULL | |
+------------+------------------+------+-----+---------+---- ---+
20 rows in set (0.00 sec)

mysql> describe docs;
+------------+------------------+------+-----+---------+---- ---+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+---- ---+
| vid | int(10) unsigned | NO | | NULL | |
| issue | date | YES | | NULL | |
| expiration | date | YES | | NULL | |
| document | varchar(250) | YES | | NULL | |
| agency | varchar(250) | YES | | NULL | |
+------------+------------------+------+-----+---------+---- ---+
5 rows in set (0.01 sec)

--20cf30433d84e0abc0049c1db831--
Shawn Wilson [ Sa, 12 Februar 2011 23:56 ] [ ID #2055054 ]

RE: :mysql::st execute failed

>From: shawn wilson [mailto:ag4ve.us [at] gmail.com]
>Sent: Saturday, February 12, 2011 5:56 PM
>To: beginners [at] perl.org
>Subject: DBD::mysql::st execute failed
>
>i'm getting this error:
>DBD::mysql::st execute failed: Column count doesn't match value count at
row
>1 at ./test-get.pl line 91, <FILE> line 1.
>DBD::mysql::st execute failed: Column count doesn't match value count at
row
>1 at ./test-get.pl line 91, <FILE> line 1.
>
>and i've been counting placeholders, columns, and variables and everything
>seems to match up. any ideas what i'm missing?
>
>btw, line 91 is the $shipsth->execute( .. ) call. this seems to have 20
>fields.
>
> lines deleted
>
Shawn,
I did not look too closely at this, but I did notice that you appear to be
missing a comma
On the prepare statement:

>my $shipth = $dbh->prepare('INSERT INTO ship (
> vid, service, name, tonnage_gt, build, lastrmby,
> altvin, depth, hullid, flag, endservice, cargoauth,
> tonnage_grt, length, vin, tonnage_net, callsign,
> imo, deadweight, breadth
> ) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
Appears there should be a comma at the end of previous line

> ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )'
> ) or die "QUERY FAIL: $DBI::errstr\n$!\n";
Ken




--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Ken Slater [ Mo, 14 Februar 2011 14:05 ] [ ID #2055136 ]
Perl » gmane.comp.lang.perl.beginners » DBD::mysql::st execute failed

Vorheriges Thema: file manipulation
Nächstes Thema: understanding the ||= operator