Erm...

  • Thread starter Thread starter Chuck Haeberle
  • Start date Start date
C

Chuck Haeberle

I just submitted a request for help with a regex and it appeared and then
vanished with a "Message no longer avialable'...

I don't suppose anyone else can see it?
 
Chuck Haeberle said:
I just submitted a request for help with a regex and it appeared and then
vanished with a "Message no longer avialable'...

I don't suppose anyone else can see it?

Yup, I can see it fine. I wouldn't use regular expressions though - I'd
just parameterise the query and use the parameters directly.
 
Here is the reply you got

Chuck Haeberle said:
I need an expression to search a SQL statement
(any type, SELECT INSERT UPDATE OR
DELETE) and find all single apostrophes which
should be replaced with a double apostrophe
without affecting the apostrophes used to delimit
the string values:

You can't do this unambiguously. Here, for example ...

SELECT x FROM y WHERE text='something' OR text='other'

.... OR might be part of one long string with apostrophes in it.

A better idea is to pass a set of parameters to your data layer class and
use them to replace simple placeholders for their locations in the query
string. That way, you know which parts are parameters and can deal with them
accordingly.

void ExecuteSQL(string strQuery, params string[] strParameters);

My example would then be written:

MyDataLayer.ExecuteSQL("SELECT x FROM y WHERE text='?' OR text='?'",
"something", "other");
.... or ...
MyDataLayer.ExecuteSQL("SELECT x FROM y WHERE text='?'", "something' OR
text='other");

P.
 
Just to add my 2 cents, I don't think you should do this, whoever is using your datalayer will expect to double up the quotes and
will find it confusing that it does it for them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top