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: "Arnar Birgisson" <ArnarB AT oddi.is>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] apostrophes in strings
  • Date: Mon, 23 Jun 2003 13:59:51 +0000

Hello there..

Doubling the quote is the standard way and it works from php in my
case:

$result = mssql_query("select 'it''s a giraffe!' ");

I don't use pear, you should check if Pear does some mangling with your
string before sending it off to SQL Server.

For future reference: PHP has very similar string represtentation as
Perl, double quoted strings are expanded for variables (f.x. "you are
number $i") and expressions inside {} (f.x. "my name is
{$userObject->somevariable['array index']}"), as well as
escape-sequences such as \n,\t etc. Single quoted strings are not
expanded, except for \'.

Arnar

>>> LowdenJK AT bernstein.com 20.6.2003 17:56:31 >>>
> 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.


_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds




Archive powered by MHonArc 2.6.24.

Top of Page