If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > encoding question marks in prepared statements

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-09, 15:52
jamieal74 jamieal74 is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
encoding question marks in prepared statements

I have a prepared sql statement and need to encode question marks that appear in strings..

for example
select * from topics where status=? and name="test?"

i need to encode the question mark in the string test? otherwise db2 thinks this statement requires two parameters, vs one
Reply With Quote
  #2 (permalink)  
Old 06-02-09, 04:57
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Have you tried using single-quotes, which are the standard SQL string delimiters?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 06-02-09, 08:50
jamieal74 jamieal74 is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
hi stolze...this was just an example I should have used single quotes instead of double..problem still remains...

select * from topics where status=? and name='test?'
Reply With Quote
  #4 (permalink)  
Old 06-02-09, 09:03
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
You could of course use
Code:
select * from topics where status=? and name=?
and pass the text "test?" as a second parameter.
Is that an option for you?
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 06-02-09, 10:36
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by jamieal74
I have a prepared sql statement and need to encode question marks that appear in strings..

for example
select * from topics where status=? and name="test?"

i need to encode the question mark in the string test? otherwise db2 thinks this statement requires two parameters, vs one

select * from topics where status=? and name like 'test'||?
Reply With Quote
  #6 (permalink)  
Old 06-02-09, 16:45
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I haven't tried this myself, but my first assumption would be that it simply works as you expect, i.e. the 2nd '?' nested inside the string is not considered to be a parameter marker. If my assumption is wrong, please provide the DB2 version you are using (on which platform) and the exact error message that you are getting.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On