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

Re^3: Counting rows Sqlite

by afoken (Parson)
on May 11, 2010 at 05:54 UTC ( #839369=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Counting rows Sqlite
in thread Counting rows Sqlite

Tainting would also have been my answer to the problem of mixing untrusted user input with SQL fragments.

For constants (your "hard-coded literals"), I really don't care. I've used DBI nearly daily in the last few years, and I rarely needed constants. And for the few cases where I really had constants, I replaced them with placeholders and a constant bind value just because I have the habit to pass all values using placeholders. So having DBI warn or die when it finds a string or number literal in an SQL statement would not hurt much, it would just force you to pass even constants via placeholders. Of course, this "paranoia mode" would break some existing code, and it needs to be disabled by default for a long time. Any by the way: Because no user code needs the $dbh->quote() method in "paranoia mode", DBI should warn or die when non-DBD code calls this method.

I see a different problem that really blocks the implementation of this "paranoia mode": The different SQL dialects. For example, it is possible and sometimes needed to create PL/SQL code via DBI/DBD::Oracle, and that code may legally contain any hard-coded literal. So the actual parsing has to be done in the DBD code, at least for those special cases. DBI code may provide a default parser, for DBDs that don't have those special cases.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re^3: Counting rows Sqlite
Select or Download Code
Re^4: Counting rows Sqlite
by dsheroh (Parson) on May 11, 2010 at 07:22 UTC
    Any by the way: Because no user code needs the $dbh->quote() method in "paranoia mode", DBI should warn or die when non-DBD code calls this method.
    Agreed, and I'd even take the extra step of saying that ->quote() in user code should be seriously considered for deprecation, "paranoia mode" or no. There may be some valid case where it's needed that I haven't encountered, but it mostly just seems to be used by people coming from PHP and looking for an equivalent to mysql_real_and_for_true_escape_string_i_really_mean_it() because they can't be bothered to learn how to use placeholders (or, in the case of one individual I've argued the point with a few times, are convinced that placeholders are The Death Of Performance).
      the problem with getting rid of $dbh->quote is that then people will just start inserting values directly

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-07-22 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (129 votes), past polls