in reply to Loop Question

Couple of quick comments.

As already mentioned, "=" will almost always evaluate as true (however, if $Data{"CustomerNumber"} evaluates as false, then the entire statement will be false).

First, print out the SQL.

my $sql = "SELECT * FROM Cust_act_da WHERE CustomerNumber = $CustomerN +umber AND #TransType = P"; print $sql; $db->SQL( $sql );
Once you see the SQL, the error may be obvious. If not, try running the SQL manually and see what the results are.

Also, as a general rule, "select *" is generally not a good way to execute an SQL query (IMHO). It's not as efficient as selecting specifically what you want. Further, if the field names have been changed, this may obscure where your error is coming from.

Another thing that concerns me is that I see you are printing  . This suggests that this information is being printed to a Web page. What is the original source of the data? Blindly printing data to a Web page doesn't usually cause problems (though someone could insert a meta refresh tag that redirects your page), but since you don't untaint this data, I am concerned about what else you may be doing with this data that may be dangerous.

Of course, that last comment is totally unrelated to your question, but I always harp about anything that suggests to me that a poor security model is being used. No offense. See perlsec for more information.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: Loop Question
by Anonymous Monk on Mar 21, 2001 at 21:47 UTC
    When I run just the SQL manually in Access, it works fine. I get the output I want: All "P" transactions for "x" customer. I am getting this data from a database. I will try your suggestion to print out the SQL and see what happens from there. Thanks.
      I forgot to mention a couple of things:

      When instantiating the DBI object, make sure that you have "RaiseError" set to 1:

      my $dbh = DBI->connect("dbi:ODBC:$DSN", $USER, $PASSWORD, {RaiseError => 1})
      By doing that, you won't have to test for errors everywhere. It will automatically throw an exception on an error. Also, if you really want to see what DBI is doing under the hood, try the DBI->trace method. This node has a good example of how it works. (That's a shameless plug because it's one of my nodes :)

      Just make sure that you set the trace number low, at first. If it's too high, your output file will be flooded with a bunch of information that is probably meaningless.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      The SQL printed out fine. It is what I want it to query. I forgot to take the # sign out of the code when I copied it to the question. But that isn't the problem.