Skip to Content.
Sympa Menu

freetds - RE: [freetds] apostrophes in strings

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: 'FreeTDS Development Group' <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] apostrophes in strings
  • Date: Fri, 20 Jun 2003 13:56:31 -0400

> From: Rusty Wright [mailto:rusty AT socrates.Berkeley.EDU]
> Sent: June 20, 2003 12:55 PM
>
> Is there a way to "quote" an apostrophe or single quote for MS SQL
> when inserting a string with a single quote in it? Or some way to
> embed it as part of the string (for example, like url encoding)?
>
> I'm using PHP and Pear. I've tried doubling the single quote, and
> preceding it with a backslash; neither way works.

You should be able to double the single quote:

1> select 'It''s alright. Da doo du da doo du....'
2> go

-------------------------------------
It's alright. Da doo du da doo du....

That's the only standard way, afaik. It works in tsql and sqsh. If it
doesn't work in PHP, it's a bug. You could work around it with:

1> select 'It' + char(39) + 's alright'
2> go

------------
It's alright

You can also alternate quoting characters (select "It's alright").

Note these are SQL quoting rules, which are weird. Other languages have
their own. I don't use PHP, so I don't know how strings are expressed, but
for instance Perl wouldn't permit doubling up the quote; the delimiting
character can't appear in the string without being escaped. (Fortunately
Perl is very flexible on the point, accepting as a delimiter single or
double quotes, or even any arbitrary character prefixed with "qq".)

HTH.

--jkl
-----------------------------------------
The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the original
message. Please note that we do not accept account orders and/or instructions
by e-mail, and therefore will not be responsible for carrying out such orders
and/or instructions.






Archive powered by MHonArc 2.6.24.

Top of Page