Re: Imbedding Special Characters in SQL
Posted in 1997
1. cr/lf are technically invalid characters in a char column so if you do insert these it's on your own risk. (We do insert other "illegal" characters in special types of data used for printer control codes and that works fine. We wouldn't dream of doing it in a case like yours though.) 2. Putting cr/lf in a name column like you intend to do looks to me to be very bad database design, but there may of course be valid reasons for it. Normaly I would however look into adding such things upon retrieval. Is there a spesific reason why you need them in the database? 3. When you use SQLExecDirect the sql statement is sent as is to the database engine. At its end the cr/lf is viewed as a new line of course, and if you check the SQL syntax (from Informix or the ANSI standard) your statement is illegal. A quoted string can't cross a newline, although it doesn't look to bad when you see it as you have written it. 4. The solution is to prepare/declare an insert statement or cursor using a variable for the values part of your statement. This variable can than contain the string you want to insert, including the cr/lf characters. "William H. Phinizy" <kb6hk@gte.net> wrote: :I wonder if anyone can offer some advice. We are creating an application in Visual C++ :wihich runs in Windows 3.1\\95 and will be adapted to use Informix 7.0 throught ODBC :(Openlink drivers). We are using the ODBC API, not ESQL. : :At present, we are having a heck of a time imbedding cr/lf characters into the quoted :string that is passed to SQLExecDirect(). : :Consider the following table: : : create table mytable ( : number integer primary, : name char(20), : comments varchar(20,50) : ) : :We wish to do the following (in effect): : : ///////////////////////////////////////////////// : // insert a name with a cr/lf : SQLExecDirect(hstmt,"insert into my.mytable (name) values ("George\\n\\rSmith"); : :does anyone know of a straightforward technique for doing this? Please reply to :kb6hk@gte.net as well. : :..my thanks in advance. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org