PDA

View Full Version : how to insert an ' in a database



jh
16th August 2006, 19:18
hi,

i have an application which stores string that contain the character <'>.
this is also the delimiter of an value in a insert statement. so how can
i add a string which contains a ' in a access database?

example:
insert <R'w>:
INSERT INTO table1 (header1, header2) VALUES ('abc', 'R'w')

any hint?

best regards,
jh

jacek
16th August 2006, 19:57
It might depend on database, but in PostgreSQL you can use '' or \'.

BTW. In Qt there is QSqlQuery::bindValue() which handles this automatically.

jh
16th August 2006, 20:04
it is an MS Access database using ODBC.

bindValue has some problems adding strings to a column of type memo
which are longer than 128 characters.

jh

ball
17th August 2006, 03:47
In SQL, use an extra ['][\] to escape your ['] char, that is:

I 'm a boy. => I ''m a boy.

or

I 'm a boy. => I \'m a boy.