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 > Entering a 'Tick' into a Field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-15-04, 10:54
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
Entering a 'Tick' into a Field

Got a message from a user about an error they are getting. They are trying to enter the name O'Brien into a text field that's defined as a VARCHAR(64). What's happening is that on the insert it's blowing up on the insert.

I tried running a stored procedure - via stored procedure builder - and entered a value with an apostrophe in the text..worked fine. Of course when I tried to run the stored procedure via command line or a straight insert, it fails because of the tick(s).

Is there an escape character or is there a setting as in SQL Server (quoted identifiers).

Thanks!
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #2 (permalink)  
Old 09-15-04, 11:15
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Try two ticks in front of the tick '''
Reply With Quote
  #3 (permalink)  
Old 09-15-04, 11:20
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
That will work fine for me and someone who workes with db's, but for an ordinary user, would be kind of bad design to put on the web page "please enter two apostrophe's before the actual apostrophe...

a database setting would be the preferred method, if at all possible...
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #4 (permalink)  
Old 09-15-04, 12:01
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ansonee
That will work fine for me and someone who workes with db's, but for an ordinary user, would be kind of bad design to put on the web page "please enter two apostrophe's before the actual apostrophe...
You don't build your SQL direcly from raw data provided by web users, do you? To me it would look like even worse design...

I would make the application responsible for data validation and, in the case of a single quote character, data translation before that data gets inserted into the database.
Reply With Quote
  #5 (permalink)  
Old 09-15-04, 12:05
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
We take exactly what they send to us...no data validation done on the app side....

Not my fault!!! I told them to...
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #6 (permalink)  
Old 09-15-04, 12:11
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
If it's web-based, you will want to scrub the incoming field anyway. There is probably a function in the language you are using to replace the ' with a '''. For example, if you are using Net.Data on z/os, the function is @DTW_rADDQUOTE
Reply With Quote
  #7 (permalink)  
Old 09-15-04, 12:13
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ansonee
We take exactly what they send to us...no data validation done on the app side....

Not my fault!!! I told them to...
Suggest your developers to read this: http://www.nextgenss.com/papers/adva..._injection.pdf - they may change their minds regarding validation :-)
Reply With Quote
  #8 (permalink)  
Old 09-15-04, 12:51
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
This app is being written in HTML.

So if I were to instruct the developers on how to resolve this, I would essentially tell them to check the fieeld and whenever you find a tick, replace that with three ticks?

Am I oversimplifying?

I'm talking to the developer responsible for this piece of the code and he says he just needs an escape character to toss in front of the troublesome tick....or something to that degree...
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."

Last edited by ansonee; 09-15-04 at 12:59.
Reply With Quote
  #9 (permalink)  
Old 09-15-04, 13:26
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ansonee
So if I were to instruct the developers on how to resolve this, I would essentially tell them to check the fieeld and whenever you find a tick, replace that with three ticks?
That's "two ticks", not "three". So, your sample string, "O'Brien" should arrive to DB2 as
Code:
'O''Brien'
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