Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 1st, 2001, 06:31 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #2  
Old June 6th, 2001, 06:43 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old June 6th, 2001, 07:31 AM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post Umm

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.

Reply With Quote
  #4  
Old June 6th, 2001, 07:48 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #5  
Old June 6th, 2001, 10:52 AM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #6  
Old June 6th, 2001, 11:06 AM
robert.swift's Avatar
robert.swift robert.swift is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Manchester, UK
Posts: 80 robert.swift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > DBI::quote


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT