Escape characters, JDBC and ColdFusion MX

Поиск
Список
Период
Сортировка
Искать

Escape characters, JDBC and ColdFusion MX

От:
Jochem van Dieten <jochemd@oli.tudelft.nl>
Дата:
Hi all,

I have a problem with inserting strings into a PostgreSQL database using 
ColdFusion MX. Somehow the backslash is not identified as an escape 
character. Single quotes are doubled up nicely and can be inserted very 
easily, ie the following pseudo code works:
string = "test ' test"
INSERT INTO table (textstring) VALUES ('#string#')

However, the following pseudo code does not work:
string = "test \' test"
INSERT INTO table (textstring) VALUES ('#string#')

This is internally translated into the following statement
INSERT INTO test (textstring) VALUES ('\''')

Naturally this fails due to the unbalanced quotes. The obvious 
workaround would be to write a function that doubles all the backslashes 
and then the problem is gone. But I feel like it is a workaround, and 
not a solution. But then again, there might be reasons for this that I 
am yet unaware of. And I don't even know if the translation is done by 
ColdFusion or the JDBC driver, let alone by which one it should be done.
But the problem is that other databases that I have tested do not have 
this problem (possibly because they do not consider a backslash an 
escape character), which sort of puts PostgreSQL at a disadvantage 
(which is particularly bad because PostgreSQL is the only free database 
that has Unicode completely supported, which is currently the main 
reason why people are looking for a new dbms).

So I would like to know if there is a reason for this behaviour and if 
there is something that I can do about it (i.e. let the JDBC driver 
double the backslashes automatically). Unfortunately, ColdFusion MX is 
largely a black box for me, so I do not know if it is necessary/possible 
to change something there.
Alternatively, if anyone can provide some reference which indicates that 
ColdFusion MX should do this, I would be equaly happy to bug Macromedia 
for a solution :)

In case you want to see the problem for yourself, you can just enter the 
teststrings in the input box at http://130.161.67.251:8500/index.cfm

setup:
ColdFusion MX using Unicode
JDBC binary from jdbc.postgresql.org, Java2 version for PostgreSQL 7.2
PostgreSQL 7.2.1 with multibyte and a default encoding of unicode

Jochem

-- 
Jochem van Dieten
Team Macromedia Volunteer for ColdFusion
http://www.macromedia.com/support/forums/team_macromedia/

Re: Escape characters, JDBC and ColdFusion MX

От:
Jochem van Dieten <jochemd@oli.tudelft.nl>
Дата:
Jochem van Dieten wrote:
> 
> I have a problem with inserting strings into a PostgreSQL database using 
> ColdFusion MX. Somehow the backslash is not identified as an escape 
> character.

Macromedia Tech Support came with a solution for this one. The solution 
is to use the ColdFusion MX  tag that uses the 
PreparedStatement class. And, contrary to the native ColdFusion MX 
 tag, the PostgreSQL JDBC driver knows how to escape a backslash :)

Jochem

FAQ