in reply to Quote-like operators in a hash

Can you show us the code you use to loop over this data structure? Have you tried printing out the SQL before you execute it?

When you do this:

qq{"SELECT ..."}

...you wind up with a string that begins and ends with double quotes. You probably mean this:

qq{SELECT ...}

Replies are listed 'Best First'.
Re^2: Quote-like operators in a hash
by tux402 (Acolyte) on Jan 05, 2009 at 17:10 UTC
    I used,
    while(my($key,$value)=each(%sqlASDOverall)) { print sqlExecute($value,$key) }

    to loop over the hash. I printed out the SQL query, and it looks to be formatted correctly. This is the SQLExecute subroutine I use to run sql queries.
    sub sqlExecute { my @results; my $sth = $dbh->prepare($_[0]); $sth->execute() || die print "Could not execute SQL query :\n$_[0] +\n",$sth->erstr(),"\n"; while (my $result = $sth->fetchrow_array()) { push @results, $result; } return @results; }
      Try simplifying the statements the hash is passing by doing something super simple like, "SELECT NOW()" and see if that works. I would also add a debugging line just about the prepare call and print out the statement (just to make sure everything looks ok). It looks like that is where your problem is, for prepare to die with that error is weird. Although, I have never used the ODBC driver with DBI but I've never seen that error with the MySQL driver.
      ...I might be missing something, but it rather looks like prepare might be expecting a quoted string - have you tried my $sth = $dbh->prepare("$_[0]");, or similar ?

      Just a thought ...

      A user level that continues to overstate my experience :-))
        Your reply got me thinking on the right track. for some reason, when I did,
        print $key." : ".sqlExecute($value);

        something went wrong and it returned 1's instead of the query result. It seems like Perl didn't like the concatenations. I re-did the print to,
        print "\t\t".$key." : "; print sqlExecute($value); print "\n";

        I'm not sure why that changed things, but it did. If anyone knows why, I would like to hear it. Thanks to all who helped. I wouldn't have figured it out with your help.