PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET escaping special operators, ', etc.

Reply

escaping special operators, ', etc.

 
Thread Tools Rate Thread
Old 11-04-2006, 06:39 PM   #1
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
 
Posts: n/a
Default escaping special operators, ', etc.


Hi;

In a select for Sql Server, the characters '_%[ are all special and have to
be escaped to be used as that character. A couple of questions:
1) Are there any others?
2) Is doubling ' to '' (that is two ' chars, not a single ") standard for
all vendors (Oracle, etc)?
3) I tried using \_ and \\_ and it didn't work. [_] does work but isn't \
also supposed to be an escape char? And if \ is an escape char - how is it
used as a regular char?
4) Does anyone know what the special chars and the way to escape them is for
Oracle (MS and Oracle .NET drivers), OleDbClient, MySqlClient, and DB2Client?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

  Reply With Quote
Old 11-04-2006, 07:06 PM   #2
=?Utf-8?B?L2Rldi9udWxs?=
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

If this is to prevent sql injections, you might want to use sql parameters in
..net. Makes the whole thing much easier :

check this article about injection in asp.net (you can use all the
techniques in windows forms apps too...) :

http://msdn.microsoft.com/library/d...paght000002.asp


"David Thielen" wrote:

> Hi;
>
> In a select for Sql Server, the characters '_%[ are all special and have to
> be escaped to be used as that character. A couple of questions:
> 1) Are there any others?
> 2) Is doubling ' to '' (that is two ' chars, not a single ") standard for
> all vendors (Oracle, etc)?
> 3) I tried using \_ and \\_ and it didn't work. [_] does work but isn't \
> also supposed to be an escape char? And if \ is an escape char - how is it
> used as a regular char?
> 4) Does anyone know what the special chars and the way to escape them is for
> Oracle (MS and Oracle .NET drivers), OleDbClient, MySqlClient, and DB2Client?
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>

  Reply With Quote
Old 11-04-2006, 07:58 PM   #3
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Hi;

Actually it's a little different than that. In some cases "A%" is all
records where that column's value starts with A and in other cases it's all
rows where that column is the literal value A%. Parameters can't help here.

thanks - dave

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"/dev/null" wrote:

> If this is to prevent sql injections, you might want to use sql parameters in
> .net. Makes the whole thing much easier :
>
> check this article about injection in asp.net (you can use all the
> techniques in windows forms apps too...) :
>
> http://msdn.microsoft.com/library/d...paght000002.asp
>
>
> "David Thielen" wrote:
>
> > Hi;
> >
> > In a select for Sql Server, the characters '_%[ are all special and have to
> > be escaped to be used as that character. A couple of questions:
> > 1) Are there any others?
> > 2) Is doubling ' to '' (that is two ' chars, not a single ") standard for
> > all vendors (Oracle, etc)?
> > 3) I tried using \_ and \\_ and it didn't work. [_] does work but isn't \
> > also supposed to be an escape char? And if \ is an escape char - how is it
> > used as a regular char?
> > 4) Does anyone know what the special chars and the way to escape them is for
> > Oracle (MS and Oracle .NET drivers), OleDbClient, MySqlClient, and DB2Client?
> >
> > --
> > thanks - dave
> > david_at_windward_dot_net
> > http://www.windwardreports.com
> >

  Reply With Quote
Old 11-04-2006, 08:50 PM   #4
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Dave,

I saw this short article today and thought it might be of some use to you:

http://www.devx.com/tips/Tip/31135

Kerry Moorman


"David Thielen" wrote:

> Hi;
>
> In a select for Sql Server, the characters '_%[ are all special and have to
> be escaped to be used as that character. A couple of questions:
> 1) Are there any others?
> 2) Is doubling ' to '' (that is two ' chars, not a single ") standard for
> all vendors (Oracle, etc)?
> 3) I tried using \_ and \\_ and it didn't work. [_] does work but isn't \
> also supposed to be an escape char? And if \ is an escape char - how is it
> used as a regular char?
> 4) Does anyone know what the special chars and the way to escape them is for
> Oracle (MS and Oracle .NET drivers), OleDbClient, MySqlClient, and DB2Client?
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>

  Reply With Quote
Old 12-04-2006, 04:01 AM   #5
Kevin Yu [MSFT]
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Hi dave,

If you use Parameters, the 'A%' string will all be translated to literal
values.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

  Reply With Quote
Old 12-04-2006, 04:12 AM   #6
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Hi;

I thought of that. However, there is no client independent way to set
parameters (JDBC does have that - ADO.NET does not).

And, we have cases where the person calling us does not want it to be a
literal value - so then we have to change the select string directly (yes I
know - SQL injection attacks are bad).

So I think we have to do this ourselves which brings me back to the original
questions.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"Kevin Yu [MSFT]" wrote:

> Hi dave,
>
> If you use Parameters, the 'A%' string will all be translated to literal
> values.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

  Reply With Quote
Old 13-04-2006, 09:02 AM   #7
Kevin Yu [MSFT]
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Yes, dave, I agree with you that there is no independent way and you have
to do it yourself.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

  Reply With Quote
Old 13-04-2006, 02:26 PM   #8
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

So...

In a select for Sql Server, the characters '_%[ are all special and have to
be escaped to be used as that character. A couple of questions:
1) Are there any others?
2) Is doubling ' to '' (that is two ' chars, not a single ") standard for
all vendors (Oracle, etc)?
3) I tried using \_ and \\_ and it didn't work. [_] does work but isn't \
also supposed to be an escape char? And if \ is an escape char - how is it
used as a regular char?
4) Does anyone know what the special chars and the way to escape them is for
Oracle (MS and Oracle .NET drivers), OleDbClient, MySqlClient, and DB2Client?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



"Kevin Yu [MSFT]" wrote:

> Yes, dave, I agree with you that there is no independent way and you have
> to do it yourself.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

  Reply With Quote
Old 17-04-2006, 10:58 AM   #9
Kevin Yu [MSFT]
Guest
 
Posts: n/a
Default RE: escaping special operators, ', etc.

Hi Dave,

1. There is no other special chars.
2. I'm not quite sure about whether other vendors do the same as TSQL.
3. \ is not an escape char.
4. The escape chars are independent for database engines, not for providers.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

  Reply With Quote
Reply



Thread Tools
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