cparrett has asked for the wisdom of the Perl Monks concerning the following question:

The programs pulls a symbol from a table and then uses that symbol to lookup other values, everything works well except for the last statement where I try to insert that data into another table where I get the "die"

#!/usr/bin/perl # PERL MODULES WE WILL BE USING # use strict; # use warnings; # use diagnostics; use DBI; use DBD::mysql; use Finance::Quote; use Data::Dumper; # CONFIG VARIABLES my $platform = "mysql"; my $database = "foci"; my $host = "localhost"; my $port = "3306"; my $user = "cparrett"; my $pw = "cayman"; my $DIVTABLE="dividends"; # DATA SOURCE NAME my $dsn = "dbi:mysql:$database:localhost:3306"; # PERL DBI CONNECT my $connect = DBI->connect($dsn, $user, $pw)or die "NOT WORKING"; # PREPARE THE QUERY To GET SYMBOL FROM SECTORS TABLE my $GET_SYMBOLKEY = "SELECT SYMBOL FROM sectors"; my $SYMBOLKEY = $connect->prepare($GET_SYMBOLKEY ); # EXECUTE THE QUERY, ONLY NEED TO EXECUTE ONCE $SYMBOLKEY->execute(); my $symbol; # BIND TABLE COLUMN SYMBOL TO VARIABLES $symbol $SYMBOLKEY->bind_columns(undef,\$symbol); # DEFINE A QUERY TO INSERT DATA INTO DIVIDENDS TABLE my $GETDIVDATA= "INSERT INTO $DIVTABLE(SYMBOL, DATE, DIV, EXDIV, DIVDA +TE, DIVYIELD, EPS) VALUES (?,?,?,?,?,?,?)"; my $DIVDATA = $connect->prepare($GETDIVDATA)or die "NOT WORKING"; #GET THE FINANCIAL DATA my $q = Finance::Quote->new; # LOOP THROUGH RESULTS while($SYMBOLKEY->fetch()) { my %data; %data = $q->fetch('nyse', "$symbol"); my $S=$symbol; my $D=$data{$symbol,"date"}; my $DV=$data{$symbol,"div"}; my $EDV=$data{$symbol,"ex_div"}; my $DVD=$data{$symbol,"div_date"}; my $DVY=$data{$symbol,"div_yield"}; my $ES=$data{$symbol,"eps"}; $DIVDATA->execute($S,$D,$DV,$EDV,$DVD,$DVY,$ES) or die "NOT WORKING"; }

Replies are listed 'Best First'.
Re: INSERT NOT EXECUTING
by Skeeve (Parson) on Aug 05, 2013 at 18:32 UTC

    Instead of die "NOT WORKING" you should as well spit out the error string:

    die "NOT WORKING: ".$DIVDATA->errstr;


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: INSERT NOT EXECUTING
by davido (Cardinal) on Aug 05, 2013 at 18:37 UTC

    "NOT WORKING" is the worst possible error message. It's only slightly better than silent failure. Why not use DBI's built-in error reporting? You could use the RaiseError attribute at "connect" time, or you could explicitly call the errstr() method:

    $DIVDATA->execute($S,$D,$DV,$EDV,$DVD,$DVY,$ES) or die $DIVDATA->errst +r;

    Then rather than us trying to guess what the problem is, your application can tell you itself.


    Dave

Re: INSERT NOT EXECUTING
by runrig (Abbot) on Aug 05, 2013 at 19:38 UTC
    To reiterate what you've already been told, but more specifically, change this:
    my $connect = DBI->connect($dsn, $user, $pw)or die "NOT WORKING";
    To this:
    my $connect = DBI->connect($dsn, $user, $pw, {RaiseError => 1});

      I tried all the comments, all I get from the output is "Died at Monk.pl line 67." Line 67 is the execute line for the insert statement. Is this an issue with the MySQL Table???

        Is this an issue with the MySQL Table???
        Don't know. But why do you have strict and warnings commented out?