[nzlug] quoting perl strings
Simon Green
simon at simongreen.net
Mon Oct 1 11:15:14 NZST 2007
On 01/10/2007, Robin Sheat <robin at kallisti.net.nz> wrote:
> However, if you're doing something like taking a text file and throwing it
> into a database as a once-off operation, this is a bit of overkill. In that
> case, turn ' into \' and probably " into \" and it should do the trick. If
> you're in Perl, apply something like tr/\"\'/\\\"\\\'/ to it to convert
> (untested - and I always get my \s wrong).
And here lies the problem.With doing the above:
1) Assuming you were doing it in MySQL, you forgot to escape the
backslash as well. And every time you do the insert, you'd need to
have some ugly tr statement (or a call to a function that does this)..
2) Secondly, once you decide that MySQL doesn't cut the mustard and
need to use Oracle[1], it won't work. In Oracle, single quotes get
turned into double quotes, and nothing else is escape (this is the SQL
compliant way by the way). If you had use DBI, that would be a
problem, since you don't need to escape your strings.
-- simon
[1] No this is not going to turn to a MySQL vs Oracle debate. :-)
More information about the NZLUG
mailing list