>>>>> "Elio" == Elio Grieco <[EMAIL PROTECTED]> writes:

Elio> I finally noticed that in all the places where no rows were returned I
Elio> had used a here document to store the SQL in a variable before passing
Elio> it to DBI. Does anyone know why using a here document would result in
Elio> the SQL returning 0 rows regardless of the query?

Things to check (and this applies pretty universally to debugging
programs; it's not at all specific to DBI or Perl):

1. Are you checking for errors?  I prefer to use "RaiseError" on
   handle creation, then do most of my work in an "eval BLOCK". 

2. Are you sure you're passing what you think you're passing?  Are
   there whitespace characters that might confuse the SQL parser?  A
   useful technique here is debugging prints:

      my $sql = <<SQL;
SELECT *
  FROM big_table
SQL
      print "sql=|$sql|\n";

   Note that I include markers to show me the beginning and end of the
   string.

Also, does the problem go away if you convert to a multi-line string?
It's perfectly legal to do this (although I find it ugly):

   my $sql = "SELECT *
                FROM big_table";

You can also build it up from lots of little strings:

   my $sql = "SELECT *" .
             "  FROM big_table";

Basically, try to eliminate the here-doc as the cause.  I agree with
Michael Chase -- I use here-docs extensively to build SQL, and haven't
had a problem with it.  I don't recall if I used them with MySQL in
particular, but I'm pretty sure I did.

t.

Reply via email to