Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

DBD:ANYDATA - Execution ERROR: No such column

by lwicks (Friar)
on Sep 13, 2004 at 23:27 UTC ( [id://390702]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Everyone,
It's getting late here and my brain is fried, so I am casting this problem out to the monks to help me if possible.

I am writing a DBD::ANYDATA sql script (below) which I want to update the "wins" field in an existing table. I presently get the following error:

Execution ERROR: No such column 'JUDOKA.WINS' called from /nfs/cust/4/7/3/judoco/e-judo/simulate.cgi at 197.

The segment of code in question is:

# Use DBI to connect to the judoka_csv datafile #----------------------------------------------- my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # +tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'judoka', 'CSV', 'data/judoka_csv', 'ad_catal +og'); # Connect to the users_csv data file # select from the datafile the id for the user ID from th +e array paased from the previous sub routine my $sql_query = "SELECT * FROM judoka WHERE judoka_id = ? +"; # this is the SQL command we want to execute my $sql_params = ($winner); # Th +eese are the parameteres we will use in the SQL command above print $query->p("$sql_query\n[$sql_params]\n") if $DEBUG; + # if we are in debug mode print the SQL statement my $sth = $dbh->prepare( $sql_query ); + # prepare the SQL command $sth->execute( $sql_params ); +# excecute the SQL using our parameters my @winner_data = $sth->fetchrow_array; # this line takes + the results of the select and puts it in the array called RESULTS $dbh->disconnect(); # we are done with the datbase for no +w, so disconnect from it (MAY NOT BE NECESSARY) print $query->p("result = ", @winner_data)if $DEBUG; + # Prints the result of our SQL command if we are in debug +mode. # grab the number of wins and then add one to it and inse +rt back into the DB my $wins = $winner_data[10] + 1; print $query->p("winner =",$winner," and Wins = ", $wins) +if $DEBUG; my $sql_insert ="UPDATE judoka SET wins = ? WHERE judoka_ +id = ?"; my @sql_insert_params = ($wins,$winner); print $query->p("$sql_insert\n[@sql_insert_params]\n") if + $DEBUG; # if we are in debug mode print the SQL stat +ement $sth = $dbh->prepare( $sql_insert ); +# prepare the SQL command $sth->execute( @sql_insert_params ); + # excecute the SQL using our parameters
Please forgive the messy code and what is no doubt a simple problem! Lance

Kia Kaha, Kia Toa, Kia Manawanui!
Be Strong, Be Brave, Be perservering!

Replies are listed 'Best First'.
Re: DBD:ANYDATA - Execution ERROR: No such column
by jZed (Prior) on Sep 13, 2004 at 23:45 UTC
    It's possible you have an older DBD::AnyData that had a bug with capitalization of column names. You should be using version 0.08. If that's not the problem, then you'll need to tell us which line is 197 so we know where the error is occurring.
      Hi jZed,
      Thanks for the reply. I am presently using AnyData::Standalone . The Anydata.pm file tells me that it is version 0.08, so it does not seem that is the problem. (unless the bug survived in the standalone version???)

      It is a line that reads:
      <quote> update_stats($passed_info1,$passed_info124);</quote>
      The update_stats sub is below:

      sub update_stats { # $internal_user_data[10] = wins # $internal_user_data[11] = losses # $internal_user_data[14] = strength my @internal_data = @_; print $query->p("Data Passed to update_stats = ",@internal_data); my $winner = $internal_data[0]; my $loser = $internal_data[1]; my @judoka_data; # Use DBI to connect to the judoka_csv datafile #----------------------------------------------- my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # +tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'judoka', 'CSV', 'data/judoka_csv', 'ad_catal +og'); # Connect to the users_csv data file # select from the datafile the id for the user ID from th +e array paased from the previous sub routine my $sql_query = "SELECT * FROM judoka WHERE judoka_id = ? +"; # this is the SQL command we want to execute my $sql_params = ($winner); # Th +eese are the parameteres we will use in the SQL command above print $query->p("$sql_query\n[$sql_params]\n") if $DEBUG; + # if we are in debug mode print the SQL statement my $sth = $dbh->prepare( $sql_query ); + # prepare the SQL command $sth->execute( $sql_params ); +# excecute the SQL using our parameters my @winner_data = $sth->fetchrow_array; # this line takes + the results of the select and puts it in the array called RESULTS $dbh->disconnect(); # we are done with the datbase for no +w, so disconnect from it (MAY NOT BE NECESSARY) print $query->p("result = ", @winner_data)if $DEBUG; + # Prints the result of our SQL command if we are in debug +mode. # grab the number of wins and then add one to it and inse +rt back into the DB my $wins = $winner_data[10] + 1; print $query->p("winner =",$winner," and Wins = ", $wins) +if $DEBUG; my $sql_insert ="UPDATE judoka SET wins = ? WHERE judoka_ +id = ?"; my @sql_insert_params = ($wins,$winner); print $query->p("$sql_insert\n[@sql_insert_params]\n") if + $DEBUG; # if we are in debug mode print the SQL stat +ement $sth = $dbh->prepare( $sql_insert ); +# prepare the SQL command $sth->execute( @sql_insert_params ); + # excecute the SQL using our parameters }

      Please pardon the shoddy code, this is far from quality work, but you have to start somewhere right? :-)

      Thanks,
      Lance

      Kia Kaha, Kia Toa, Kia Manawanui!
      Be Strong, Be Brave, Be perservering!

        OH DEAR

        Spotted and corrected my error!! I really was tired last night!!

        The error was that I had disconnected from the database!!!
        $dbh->disconnect();
        Just before trying to do the UPDATE!!!

        Well, goes to show that sometimes just going through the problem for someone else helps you see your mistakes!!
        Sorry for the waste of time.

        Lance

        Kia Kaha, Kia Toa, Kia Manawanui!
        Be Strong, Be Brave, Be perservering!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://390702]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found