Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameterized query fails when inserting certain Unicode characters

I have a problem when trying to insert certain characters through query with parameters.

When I run the following query (no parameters involved), everything works fine.

string insertQuery = "insert into 'testschema'.texttypestestobject(columnshortstring,columnlongstring)values('¬','test')";
DB2Command myCommand = new DB2Command(insertQuery, conn);
myCommand.ExecuteNonQuery();

However, if I run the query like the following, it fails.

string insertQuery = "insert into 'testschema'.texttypestestobject(columnshortstring,columnlongstring)values(@p0,@p1')";
DB2Command myCommand = new DB2Command(insertQuery, conn);
myCommand.Parameters.Add(new DB2Parameter("@p0", "¬"));
myCommand.Parameters.Add(new DB2Parameter("@p1", "test"));
myCommand.ExecuteNonQuery();

The error is:

Executing Sql 'insert into 'testschema'.texttypestestobject(columnshortstring,columnlongstring)values(@p0,@p1)'
with parameters '{¬},{ test}' exception 'IBM.Data.DB2.DB2Exception (0x80004005):
ERROR [IX000] [IBM][IDS/NT64] Code-set conversion function failed due to illegal
sequence or invalid value.

Informix server 11.70 (64 bit) and Client SDK 3.50 is installed, and working properly. Database is created with en_US.utf8 or cs_CZ.8859-2.

One of the characters that fail is '¬' (Unicode 172).

Has anyone seen this error? What could be the cause? Is there some additional configuration that needs to be performed on the driver?

like image 202
vedran Avatar asked Jan 18 '12 09:01

vedran


1 Answers

I got a response from ibm developer forum. This was a bug that was fixed with the latest fix pack.

It can be resolved by either installing the fix pack or setting the environment variable DB2CODEPAGE=1208

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14779728&#14779728

like image 53
vedran Avatar answered Oct 23 '22 05:10

vedran