Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

string assignment.

by roju (Friar)
on Jul 15, 2003 at 19:23 UTC ( [id://274537]=note: print w/replies, xml ) Need Help??


in reply to executing a OSP with CGI

First, rewrite that assignment using the more perlish variable interpolation, instead of concatination. So you go

from: $SQLString = "exec OSP_FOO_BAR( '".$xvar."', ".$yvar.", ".$zvar.")";

to: $SQLString = "exec OSP_FOO_BAR( '$xvar', $yvar, $zvar)";

Both pieces of code are equivalent. Should the second two variables have 's around them?

Replies are listed 'Best First'.
Re: string assignment.
by cjcollier (Novice) on Jul 15, 2003 at 21:40 UTC

    I highly reccomend using the DBI's ? substitution operator unless you know that $xvar, $yvar or $zvar don't contain any meta characters. But you should use them anyway, since that's what they're made for ;)

    A short explanation:

    When sending a query to the DBI, you can use the ? character and the arguments to C<exec()> to have the contents being substituted be checked for what may otherwise be considered metacharacters (characters that mean something other than themselves, eg ' (begin/end string), % (mysql's glob character), & (the conjunction character), etc.).

    Here's an example:

    my $query = "SELECT * FROM lala WHERE moomoo = ?"; my $sth = $dbh->prepare($query); # at this point, the query string is parsed, and discovers # that there is one substituion. The DBI will require one # argument to the C<exec()> function and complain if it # doesn't see one. foreach my $moomoo_val ( @vals ){ # Note that the query is now cached, and can be # re-C<execute()>'d as many times as you wish. $sth->execute($moomoo_val); while(my $row = $sth->fetchrow_hashref){ print( join("\t", vals %$row), "\n" ); } }
    (this code not tested, and yes, I know the same thing could be acheived with less code.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-24 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found