[Gambas-user] MySQL query problems with apostropies

nando nando_f at ...951...
Wed Apr 7 21:40:43 CEST 2010


Replace will work for quote and backslash
For double quote:

doublequote$ is chr$(34)
Replace$(mystring, chr$(34), "\" & chr$(34)

But, Benoit had an email of the nice solution.
-Fernando


---------- Original Message -----------
From: Keith Clark <keithclark at ...2185...>
To: nando_f at ...951..., mailing list for gambas users
<gambas-user at lists.sourceforge.net>
Sent: Wed, 07 Apr 2010 15:33:12 -0400
Subject: Re: [Gambas-user] MySQL query problems with apostropies

> On Tue, 2010-04-06 at 16:27 -0500, nando wrote:
> > Strings that contain these three characters: quote, double quote and backslash
> > need to be escaped.
> > You escape them by having a backslash immediately before it.
> > Example:
> >  Patty O'Lantern  would be...
> >  Patty O\'Lantern
> > 
> > One way is to make a small function that will insert a backslash
> > when it finds a quote or double quote or backslash. 
> > 
> > When you create your SQL string (Insert, Update, Select, etc)
> > you escape the strings for the char, varchar, text, or similar.
> > 
> > sql = "SELECT * FROM inventory WHERE part = ' & escape(mypart) & "';"
> > 
> > SELECT from the database will not return the 'escape' backslash.
> > It will appear normal.
> > 
> > Please note: / (on the question mark key) is not the backslash.
> > \ is the backslash.
> > 
> > -Fernando
> > 
> Can I not do this with Replace$?  I can with the single quote with
> Replace$($string,"'","\'"), but I cannot do the same with double quotes.
> 
> I'm not sure I understand this whole escape thing.
> 
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------




More information about the User mailing list