|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
DBI::quote
This sub, taken from DBI, turns this quote:
"I prefer Perl myself, and since UOE is quite a large chain and didn't have database support when we started, I wouldn't think it would be worth the trouble... \\\ " into this: 'I prefer Perl myself, and since UOE is quite a large chain and didn\'t have database support when we started, I wouldn\'t think it would be worth the trouble... \\\\ ' But I can't see where, or how... I need to be able to undo it... Code:
sub quote {
my ($dbh, $str, $data_type) = @_;
return "NULL" unless defined $str;
unless ($data_type) {
$str =~ s/'/''/g; # ISO SQL2
return "'$str'";
}
# Optimise for standard numerics which need no quotes
return $str if $data_type == DBI::SQL_INTEGER
|| $data_type == DBI::SQL_SMALLINT
|| $data_type == DBI::SQL_DECIMAL
|| $data_type == DBI::SQL_FLOAT
|| $data_type == DBI::SQL_REAL
|| $data_type == DBI::SQL_DOUBLE
|| $data_type == DBI::SQL_NUMERIC;
my $ti = $dbh->type_info($data_type);
# XXX needs checking
my $lp = $ti ? $ti->{LITERAL_PREFIX} || "" : "'";
my $ls = $ti ? $ti->{LITERAL_SUFFIX} || "" : "'";
# XXX don't know what the standard says about escaping
# in the 'general case' (where $lp != "'").
# So we just do this and hope:
$str =~ s/$lp/$lp$lp/g
if $lp && $lp eq $ls && ($lp eq "'" || $lp eq '"');
return "$lp$str$ls";
}
What I don't understand is at what point it's adding in the '\' characters. Thanks to anyone that can help me! (Also posted here: http://ubbforums.infopop.com/cgi-bi...ic&f=7&t=001663) |
|
#2
|
||||
|
||||
|
hi,
i suggest you perldoc DBI and search for type_info. what is being passed in as $data_type, that is what is causing the script to fall through. my guess is your DBD is returning something in the LITERAL_PREFIX. robert. |
|
#3
|
|||
|
|||
|
Wrong problem... the thing is executing correctally... but I need to understand how to undo it after it's put in.
And I still can't see where it's sticking in the '\' characters to cancel things. |
|
#4
|
||||
|
||||
|
sorry i miss-understood. if you need to replace the \' with something else, you need to use something like:
$var =~ s/\\\'/WHATEVERYOUNEED/g; where $var is loaded with the output you want to modify. o'reilly do an excellent book on regex and the camel book will give you all the information you need to understand this type of regex. basically each of the characters you have need to be escaped with the \ so \' becomes \\\' - make sense? i hope this helps. robert. |
|
#5
|
|||
|
|||
|
Ok, but
Ok... well can you tell me where in DBI::quote it's actually adding the slashes? I can't seem to find it...
|
|
#6
|
||||
|
||||
|
it looks to me like:
$str =~ s/$lp/$lp$lp/g is the bit you are interested in. this would seem to be replacing something with itself twice. if the code my $lp = $ti ? $ti->{LITERAL_PREFIX} || "" : "'"; is returning a \ (which i think it probably is) then this is where it is coming from. robert. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > DBI::quote |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|