angoca / db2tools

Set of routines that can ease your daily work.
GNU General Public License v2.0
1 stars 0 forks source link

Escape quotes in a message #12

Open angoca opened 10 years ago

angoca commented 10 years ago

Procedure to escape quotes in order to be used as escaped. This is useful when passing names that have quotes and they are going to be used in prepared statements

SET LENGTH = LENGTH(MSG); SET INDEX = 0; SET RET = ''; WHILE (INDEX < LENGTH) DO SET INDEX = POSSTR(MSG, ''''); IF (INDEX <> 0) THEN SET PRE = SUBSTR(MSG, 1, INDEX - 1); SET RET = RET || PRE || ''''''; SET MSG = SUBSTR(MSG, INDEX + 1); SET INDEX = 0; SET LENGTH = LENGTH(MSG); ELSE SET INDEX = LENGTH; SET RET = RET || MSG; END IF; END WHILE; RETURN RET;