FAQ

On 2014-02-18 02:27, SSC_perl wrote:
I'm helping someone retrieve some info from a MySQL db and I'm having trouble sending multiple select statements with Perl. Here's a portion of the code:

use SQL::SplitStatement;
my $query_4 = "CREATE TEMPORARY TABLE `temp_ip` AS
(SELECT `ip`
FROM `ip_addresses` "
.$daily.
" AND TRIM(`referrer`) LIKE '' GROUP BY `ip` HAVING COUNT(*) > 1);
SELECT `ip`, `page`, `url`, `time_stamp`
FROM `ip_addresses` "
.$daily.
"AND TRIM(`referrer`) LIKE '' AND `ip` IN (SELECT `ip` FROM `temp_ip`)";

my $sql_splitter = SQL::SplitStatement->new(
keep_terminators => 1,
keep_extra_spaces => 1,
keep_comments => 0,
keep_empty_statements => 1
);
my @statements = $sql_splitter->split($query_4);
my $sql_string = join ' ', @statements;
my $sth_4 = $dbh->prepare($sql_string);
$sth_4->execute();

I believe what's throwing a wrench in it is the ";" separating the 2 select statements. That's why I'm using SQL::SplitStatement, but that doesn't seem to help, so I'm sure I'm doing something wrong. The SQL works fine, so my problem must be with my Perl code.

I've read everything I can get my hands on but no luck. Any help would be greatly appreciated.

my $sth_4;

for ( my $sql = $sql_splitter->split($query_4) ) {

      $sth_4 and $sth_4->{Active} and die "Unfinished business";

      if ($sql =~ /^\s*(?:create|delete|insert|set|update)\b/x {
          $dbh->do( $sql );
      }
      else {
          $sth_4 = $dbh->prepare( $sql );
          $sth_4->execute();
      }
}

(untested)

--
Ruud

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 18, '14 at 1:27a
activeFeb 20, '14 at 8:45p
posts3
users2
websiteperl.org

2 users in discussion

SSC_perl: 2 posts Dr.Ruud: 1 post

People

Translate

site design / logo © 2021 Grokbase