all groups > sql server odbc > january 2004 >
You're in the

sql server odbc

group:

Select "problem" Howto


Select "problem" Howto GTi
1/31/2004 3:15:23 PM
sql server odbc:
ODBC Beginner

Normal I use:
sprintf(qu,"SELECT Name, phone FROM PersonTable WHERE info='%s'",sText);
SQLExecDirect(hstmt1,qu,SQL_NTS);

This works fine, except when the sText is:
Test on 'data' field
Then I have the ' in the string.
What else can I use - SQLPrepare?.
Please give me some samples of using this in SQLPrepare.

Re: Select "problem" Howto Johan Svensson
1/31/2004 6:03:21 PM
The solution is to make sure you never have a single '-character in your
text string. You need to replace it with two single qoute characters instead
(not a double qoute character), because this will then be interpreted as the
text representation of the single qoute instead if the end of string
character.

Some examples:
Text is
Test on 'data' field
replace with
Test on ''data'' field

resulting query
SELECT Name, phone FROM PersonTable WHERE info='Test on ''data'' field'

Text is
This is my 'data'
replace with
This is my ''data''

resulting query
SELECT Name, phone FROM PersonTable WHERE info='This is my ''data'''


Note the existens of three single qoute characters in the second example.
This means that the first two are represting the single qoute character
string and the last one means end of text string.


Regards,
Johan


[quoted text, click to view]
ODBC Beginner

Normal I use:
sprintf(qu,"SELECT Name, phone FROM PersonTable WHERE info='%s'",sText);
SQLExecDirect(hstmt1,qu,SQL_NTS);

This works fine, except when the sText is:
Test on 'data' field
Then I have the ' in the string.
What else can I use - SQLPrepare?.
Please give me some samples of using this in SQLPrepare.


Re: Select "problem" Howto GTi
2/1/2004 12:59:12 PM
So, for this to work I have to add a single qoute character
to all single qoute characters in the string (...!)
Then the driver will remove the two single qoute character
with one single qoute character.

OK..?

"Johan Svensson" <hej(dot)johan(at)telia(dot)com@remove.spam> wrote in
message news:J5SSb.80921$dP1.207589@newsc.telia.net...
[quoted text, click to view]

Re: Select "problem" Howto Johan Svensson
2/1/2004 2:11:37 PM
Hi again,

Your conclusion in the first sentence is correct.

About your second comment, I do not know exactly where the transalation
takes place, but it is most likely not any network interface driver, more
likely it is in the query parser in the database itself. But once again, I
do not know this for sure, but I do know this is the only way you can get it
to work...


Regards,
Johan


[quoted text, click to view]
So, for this to work I have to add a single qoute character
to all single qoute characters in the string (...!)
Then the driver will remove the two single qoute character
with one single qoute character.

OK..?

"Johan Svensson" <hej(dot)johan(at)telia(dot)com@remove.spam> wrote in
message news:J5SSb.80921$dP1.207589@newsc.telia.net...
[quoted text, click to view]

AddThis Social Bookmark Button