Received: from ucs.co.za (ucs.co.za [196.23.43.2]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eA997ks15212 for ; Thu, 9 Nov 2000 04:07:48 -0500 (EST) (envelope-from gaf@ucs.co.za) Received: from ucspost.ucs.co.za (IDENT:root@mailgw1.ucs.co.za [196.23.43.254]) by ucs.co.za (8.9.3/8.9.3) with ESMTP id LAA17414; Thu, 9 Nov 2000 11:17:54 +0200 Received: from jhb.ucs.co.za (jhb.ucs.co.za [172.31.1.73]) by ucspost.ucs.co.za (8.9.3/8.7.3) with ESMTP id LAA02830; Thu, 9 Nov 2000 11:06:12 +0200 Received: from ucs.co.za (IDENT:gaf@pc141.ucs.co.za [172.31.1.141]) by jhb.ucs.co.za (8.9.3/8.8.7) with ESMTP id LAA04006; Thu, 9 Nov 2000 11:11:07 +0200 Message-ID: <3A0A68FF.35ACA12C@ucs.co.za> Date: Thu, 09 Nov 2000 11:06:07 +0200 From: Grant Finnemore X-Mailer: Mozilla 4.61 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Christopher Farley CC: pgsql-interfaces@postgresql.org, petermount@maidstone.gov.uk Subject: Re: JDBC 'Unterminated quoted string' References: Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.postgresql.org id eA997ss15222 X-Archive-Number: 200011/107 X-Sequence-Number: 143 Christopher, A patch for the postgresql driver - class PreparedStatement.java in both jdbc1 and jdbc2. 274,285c274 < < /* If the string contains a null zero, when it reaches the < * backend, the C routines to manipulate a string will < * assume that the string is finished at this point. This < * will result in an 'Unterminated string constant' error < * from the backend. Hence, before inserting the character, < * check if it is a null zero, and if so, escape it. < */ < if (c != '\0') < b.append(c); < else < b.append("\\0"); --- > b.append(c); Regards, Grant Christopher Farley wrote: > If you setString(1,null), it does work. > > I am actually doing a setString(1,String.valueOf('\0')), which causes the > unterminated string error. > > Although this didn't fail under the previous RDBMS (PervasiveSQL), I > have considered that setting a Java char to '\0' is just bad programming > practice. However: > > - Both Postgresql and Java evaluate '\0' as ''. > > - You can't set a Java char to ''. > > - Many people have a need to map chars to a RDBMS > > So it seems reasonable to me that the JDBC driver should escape NULL chars > as '\\0' rather than pass the character unparsed where it will be treated > as a NUL terminator when it appears in a C string. > > Damn these primitive types in Java! > > ---- > Christopher Farley > Northern Brewer / 1150 Grand Avenue / St. Paul, MN 55105 > www.northernbrewer.com > > On Thu, 9 Nov 2000, Grant Finnemore wrote: > -- > Poorly planned software requires a genius to write it > and a hero to use it. Grant Finnemore BSc(Eng) (mailto:gaf@ucs.co.za) Software Engineer Universal Computer Services Tel (+27)(11)712-1366 PO Box 31266 Braamfontein 2017, South Africa Cell (+27)(82)604-5536 20th Floor, 209 Smit St., Braamfontein Fax (+27)(11)339-3421 Johannesburg, South Africa