Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

when is a string not a string?

by purge (Acolyte)
on May 03, 2002 at 10:31 UTC ( [id://163757]=perlquestion: print w/replies, xml ) Need Help??

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

I have the most odd problem with a piece of code connecting to an oracle database, it goes like this:
getData{ $sql = shift; my ($total_cols) = $dbh->selectrow_array($sql) or die($dbh->errstr); ...
doesn't work, gives me DBD::Oracle::db selectrow_array failed: ORA-00900: invalid SQL statement (DBD ERROR: OCIStmtExecute) but.. should I take an exact copy of the string $sql (I've even done an ascii comparison on it) and set it inside the subroutine, it works perfectly well, i.e:
getData{ $sql = shift; $sql = "SELECT COUNT(*) etc blah blah"; my ($total_cols) = $dbh->selectrow_array($sql) or die($dbh->errstr); ...
its driving me mad.. help!

Replies are listed 'Best First'.
Re: when is a string not a string?
by tachyon (Chancellor) on May 03, 2002 at 10:41 UTC

    Does this fail or die? I expect it dies....

    getData{ my $passed_sql = shift; my $sql = "SELECT COUNT(*) etc blah blah"; die "I am not passing expected SQL! I got '$passed_sql'\n" unless +$passed_sql eq $sql; my ($total_cols) = $dbh->selectrow_array($sql) or die($dbh->errstr +);

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      ooh yes your right... but this is odd, when i print out $passed_sql it appears blank (or some spaces perhaps) even though the same string prints perfectly inside a die, or print on its own!

        While I suspect there is some more pragmatic answer, you might get that kind of behaviour from passing an overloaded object to the code (f ex something that overloads stringifying and concatenation and makes a poor job at it), or some tied variable, I guess. What are you passing to this sub, anyway? (Obscure reference: It is not $2, is it?)

        Unless you are passing something you know to be strange magic, I would have another look at how this passed value behaves. Like this, perhaps:

        my $passed_sql = shift; my $sql = "SELECT COUNT(*) etc blah blah"; print STDERR "Trying[1] to print parameter alone: " print STDERR $passed_sql; print STDERR "\nTrying[2] list print: ", $passed_sql; print STDERR "\nTrying[3] interpolated: $passed_sql\n"; die if $sql ne $passed_sql; # Might as well ... my ($total_cols) = $dbh->selectrow_array($sql) or die($dbh->errstr +);

        Again, I expect the problem is easier (and might be fixed alread?), but if not, I hope this helps.

        The Sidhekin
        print "Just another Perl ${\(trickster and hacker)},"

        Sorry can't see how $passed_sql cana print OK and NOT OK????????????? segfault.

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: when is a string not a string?
by bjelli (Pilgrim) on May 03, 2002 at 12:12 UTC

    how are you calling getData? object-oriented-style will give you the object as first argument: $obj->getData("select ....");

    another thought: is the <kbd>sub</kbd> in front of getData missing?

    --
    Brigitte    'I never met a chocolate I didnt like'    Jellinek
    http://www.horus.com/~bjelli/         http://perlwelt.horus.at

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://163757]
Approved by tachyon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found