Re: An easy one
Posted in 1997
On Sun, 9 Nov 1997, Roberto Dircio Palacios Macedo wrote:
> Suppose I have this query:
>
> insert into my_queries values('thisquery','insert into xtable
> values('s','y');');>
> msql seems to get confused with the ' symbol, how can I use it in this query?
Well, so it should. The quote before the s terminates the second string,
and the only valid follower characters are comma or close parenthesis, and
s is neither of these.
To embed single quotes in a string, you double them:
INSERT INTO my_queries
VALUES('thisquery','insert into xtable values(''s'',''y'');');
With Informix products, you can also play games mixing double quotes and
single quotes, as in:
INSERT INTO my_queries
VALUES('thisquery','insert into xtable values("s","y");');
INSERT INTO my_queries
VALUES("thisquery","insert into xtable values('s','y');");
However, any use of double quotes to enclose strings is not wholly
reliable; if the user has the DELIMIDENT environment variable set in their
environment, then the meaning of the SQL changes (usually into a syntax
error, but the change is nonetheless undesirable for that).
Yours,
Jonathan Leffler (johnl@informix.com) #include <witticism.h>