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

Hi all,

I am following up on a problem that has been haunting me for a bit.

I have a script that is moving some unstructured data into a mysql db. I can access all tables in my db. But for reasons that escape me I can not select from two tables. I can insert and update those tables but not select.

I think this is an issue with the script as if I run the exact same select via command line it works fine. And again I can insert and update from the script so I don't think it's a permission issue.

I have no clue.

Anyone?

Thanks in advance!

Replies are listed 'Best First'.
Re: Can insert but not select
by kyle (Abbot) on Jan 03, 2009 at 05:27 UTC

    It is possible with some databases to have permission to INSERT and UPDATE but not SELECT.

    It would help us diagnose the problem if you'd show some code that's giving you the problem.

      Thanks! Here is the code in question.
      $rowCheckQuery = qq{SELECT color_id FROM color WHERE color=?}; foreach my $color (@color){ # trim whitespace $color =~ s/^\s+|\s+$//gm; # print "Color is - ", $color, " -\n\n"; my $sth = $dbh->prepare($rowCheckQuery); $sth->execute($color); while(my $color_test = $sth->fetchrow_arrayref) +{ push @color_test, $color_test; } }
      Also I double checked the user I am using for the script and it has global select permissions. I can select on other tables in the same db.... just very oddly not two of my tables. This might be more of a mysql issue. I'm not sure.

      Thanks again.

        And what behavior do you see from this?

        Note that fetchrow_arrayref always returns the same array reference (see the DBI documentation). That means if you want to store all the rows (as you appear to be attempting), you have to copy the array.

        while(my $color_test = $sth->fetchrow_arrayref) { push @color_test, [ @{$color_test} ]; }

        In addition to comments already made, you also want to prepare your statement outside of the loop. You are effectively negating the performance benefit of running the prepare command.

        --MidLifeXis

Re: Can insert but not select
by Anonymous Monk on Jan 03, 2009 at 12:43 UTC
    helping you would be easier if you can post the code from the script you are using. Theoretically it would be possible to have a user with insert and update permissions and without a select permission
      Thanks all,

      I posted the solution last night but it's worth reposting.

      After some reading on the mysql boards I realized several people were having the same issue. All were using active perl and all were using the mysqlPP driver. I switched to using the mysql driver and the issue vanished.

      Thanks again!
Re: Can insert but not select
by targetsmart (Curate) on Jan 03, 2009 at 09:58 UTC
    I suggest you to use default perl debugger or use Devel::sdb to debug your code of yourself, you will be able to solve your problem with ease I believe.