Article View: borland.public.interbase.sql
Article #445Re: Single quotes in IB7 field values
From: Wayne Niddery (TeamB)
Date: Tue, 18 Mar 2008 14:04
Date: Tue, 18 Mar 2008 14:04
34 lines
2357 bytes
2357 bytes
"Brian" <AAA@AAA.AA> wrote in message
news:MPG.22498b10b5e30cfa989680@newsgroups.borland.com...
> My OCCUPANT_NAME field in my OCCUPANTS table contains some values
> with single quotes like Fred's Market for instance.
> Are there any escape characters I can use in My SQL strings?
> My front end application is Access2007 and I am using the DataDirect
> ODBC driver.
> Earlier versions of IB used to accept double quotes around a fields
> value.
If you are formatting SQL directly instead of using parameters then you must
double up single quotes, e.g:
s := 'where name = ''Fred''s Market''';
Delphi also has a QuotedStr function that makes this easier, e.g. if a user
enters Fred's Market in an edit control:
s := 'where name = ' + QuotedStr(Edit1.Text);
However, the best way to avoid these issues is to use parameterized queries.
Assign the SQL to the dataset as:
MyDataset.SQL.Text := 'select * from table where name = :name';
Then assign the parameter(s):
MyDataset.ParamByName('name') := Edit1.Text;
--
Wayne Niddery - TeamB (www.teamb.com)
Winwright, Inc. (www.winwright.ca)
Technical Details
Message-ID:
<47dfcc00$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.14.MISMATCH!news2.euro.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<MPG.22498b10b5e30cfa989680@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,55d6efaf53aa5888 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Wayne Niddery \(TeamB\)" <wniddery@chaffaci.on.ca> Newsgroups: borland.public.interbase.sql References: <MPG.22498b10b5e30cfa989680@newsgroups.borland.com> In-Reply-To: <MPG.22498b10b5e30cfa989680@newsgroups.borland.com> Subject: Re: Single quotes in IB7 field values Date: Tue, 18 Mar 2008 10:04:34 -0400 Lines: 35 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6000.16480 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545 NNTP-Posting-Host: 24.137.214.213 Message-ID: <47dfcc00$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1205849088 24.137.214.213 (18 Mar 2008 07:04:48 -0700) X-Authenticated-User: wniddery Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.14.MISMATCH!news2.euro.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail