Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WE0TW-000505-W2 for pgsql-odbc@arkaria.postgresql.org; Thu, 13 Feb 2014 17:53:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WE0TW-0003oi-Em for pgsql-odbc@arkaria.postgresql.org; Thu, 13 Feb 2014 17:53:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WE0TV-0003ob-IZ for pgsql-odbc@postgresql.org; Thu, 13 Feb 2014 17:53:25 +0000 Received: from moutng.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WE0TS-0006BX-P7 for pgsql-odbc@postgresql.org; Thu, 13 Feb 2014 17:53:25 +0000 Received: from Endor (business-188-111-109-220.static.arcor-ip.net [188.111.109.220]) by mrelayeu.kundenserver.de (node=mreue006) with ESMTP (Nemesis) id 0LvdiS-1V6yOD3QuS-017Xy0; Thu, 13 Feb 2014 18:53:22 +0100 From: =?UTF-8?Q?Nils_G=C3=B6sche?= To: Subject: Null Characters in Strings, Version 9.3.1 Date: Thu, 13 Feb 2014 18:53:20 +0100 Message-ID: <006a01cf28e4$7c425450$74c6fcf0$@de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac8o5HuPUxnz54mVTgiWvqjv6Wz03w== Content-Language: de X-Provags-ID: V02:K0:7jOvGEGh4nH2DFF4cE37WUce/skEotVz8KD5II7K2vj PcElIM0ReTaqOElG7D1AXZc8qoEiL9e+xSLC8bkPeWoMh/SVfW UCjtGZOKnydSRWdXvEDq22rYkIkU06FLq5v7oZSG2h5q5XBUFi Cp1xDZ32PUbmZ3jUx0ZXGa5oa54TileJoD3dcB8VDsInYAoUsT mVlMC1eIDYIS4S/748sl4b9o4g0r563+bOrpklkXrdOArDNn8M 8YEPfMqCDnB+ZQt0IEnWbmPizKc8F3BiqNfH6KGa3L5Fq67xqS lOpH9uN4xZJsNE3wURrKFwOY/HZO+DxxSXP3VzOm1s4b064AhE VU9a/oIjTCciAtJEBYGk= X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org Hi! I have noticed a change of behavior in version 9.3.1 of the ODBC driver. I = am using the 32 bit version for testing, haven=E2=80=99t tried 64 bit yet. I am retrieving a string value from a table that has a column of type =E2= =80=98text=E2=80=99. This worked just fine with version 9.2.1 of the driver= , but since I upgraded the ODBC driver to 9.3.1, something strange is happe= ning: In psql, I do: select length(body) from macros where name =3D 'check_pruefziffer'; and it returns 459. The text contains only ASCII characters. If I retrieve the value in a C# program using the ODBC driver, I get a stri= ng that has a null character at position 459, but a total length of 487! T= he string up to position 458 is correct, but has now been extended with a n= ull character and a few junk characters. This shouldn=E2=80=99t be happening, right? Am I doing something wrong here= ? Here is some C# code that I wrote for testing: class Program { const string ConnString =3D @"Driver=3D{PostgreSQL Unicode};server= =3Dlocalhost;port=3D5432;database=3D...;uid...;pwd=3D..."; static void Main(string[] args) { try { using (var db =3D new OdbcConnection(ConnString)) { db.Open(); using (var trans =3D db.BeginTransaction()) { try { const string cmdText =3D @"SELECT body FROM mac= ros WHERE name =3D 'check_pruefziffer'"; using (var cmd =3D new OdbcCommand(cmdText, db,= trans)) { var ret =3D cmd.ExecuteScalar(); if (ret =3D=3D null) { Console.WriteLine("ret =3D=3D null"); } else { Console.WriteLine("ret is {0}: {1}", re= t.GetType(), ret); Console.WriteLine("\nChecking for null = byte..."); string s =3D (string) ret; int pos =3D s.IndexOf('\0'); if (pos >=3D 0) { Console.WriteLine("Found null byte = at {0}! Total =3D {1}", pos, s.Length); } else { Console.WriteLine("Not found."); } } } trans.Commit(); } catch { trans.Rollback(); throw; } } } } catch (Exception ex) { Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.M= essage); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); } } Here is the tail of the output: [SNIP] $computedZiffer =3D 10 - ($sum % 10) if ($computedZiffer -eq $pruefZiffer) { $ret =3D $true } } $ret ) { $ret =3D $true } } $ret Checking for null byte... Found null byte at 459! Total =3D 487 Press any key to exit... If you select the same value in psql, the tail looks like this: [SNIP] + $computedZiffer =3D 10 - ($sum % 10) + + if ($computedZiffer -eq $pruefZiffer) { $ret =3D $true } + } + $ret (1 row) The string that the C# program is getting contains a null byte plus some ju= nk after the $ret. Regards, --=20 Nils G=C3=B6sche "Don't ask for whom the tolls." --=20 Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc