in reply to Re^2: Distiguishing arguments: number-strings vs real integer
in thread Distiguishing arguments: number-strings vs real integer
I'm hacking a DBI abstraction, and I'm not sure about the side-effects of binding 42 vs "42" to a placeholder.
Isn't irrelevant what Perl thinks of a variable's type when DB already knows/was told what the type of that column should be at create time? If DB column was declared as INT then don't quote (and possibly warn user of a type mismatch if any), else quote.
Having said that I read in Programming the Perl DBI:
It's equally simple to specify multiple bind values within one statement, since bind_ param( ) takes the index, starting from 1, of the parameter to bind the given value to. For example:
$sth = $dbh->prepare( "
SELECT name, location
FROM megaliths
WHERE name = ?
AND mapref = ?
AND type LIKE ?
" );
$sth->bind_param( 1, "Avebury" );
$sth->bind_param( 2, $mapreference );
$sth->bind_param( 3, "%Stone Circle%" );
You may have noticed that we haven't called the quote( ) method on the values. Bind values are passed to the database separately from the SQL statement,[50] so there's no need to "wrap up" the value in SQL quoting rules.
[50] This is not strictly true, since some drivers emulate placeholders by doing a textual replacement of the placeholders with bind values before passing the SQL to the database. Such drivers use Perl's internal information to guess whether each value needs quoting or not. Refer to the driver documentation for more information. [emphasis mine]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Distiguishing arguments: number-strings vs real integer
by LanX (Saint) on Aug 10, 2018 at 14:02 UTC | |
by mr_ron (Deacon) on Aug 12, 2018 at 00:28 UTC | |
by LanX (Saint) on Aug 12, 2018 at 00:41 UTC |