Received: from send205.yahoomail.com (send205.mail.yahoo.com [128.11.68.129]) by hub.org (8.9.2/8.9.1) with SMTP id TAA56151 for ; Sun, 21 Mar 1999 19:58:56 -0500 (EST) (envelope-from peter_garner@yahoo.com) Message-ID: <19990322005855.7207.rocketmail@send205.yahoomail.com> Received: from [209.223.93.176] by send205.mail.yahoo.com; Sun, 21 Mar 1999 16:58:55 PST Date: Sun, 21 Mar 1999 16:58:55 -0800 (PST) From: Peter Garner Subject: Re: [SQL] string containing (') To: Atika , pgsql-sql@postgreSQL.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hi Atika! You need to escape the apostrophe, in other words, "Let's all get stoned" must be converted to "Let\'s all get stoned" Here is some java that does this : /** * Massages a String parameter so that parameter is palatable to the Database. For * example, "It's a good day!" would be converted to "It\'s a good day!". * * @param string The String we wish to massage * * @return A "fixed" version of the Argument String Object */ public static String fixupString ( String string ) { // Assume a worst case scenario where EVERY byte in the string needs to be escaped, i.e. make the Length of the NEW // Buffer twice the Length of the old Buffer char cCurrent = '\0' ; char carrBuffer [] = new char [string.length () * 2] ; int nBuffIdx = 0 ; for ( int n = 0 ; n < string.length () ; n++ ) { cCurrent = string.charAt ( n ) ; // See if the current character is an apostrophe or an '\'. I think the only reliable way to escape all apostrophes // and all '\' is to escape each and every one that is encountered. Otherwise one may not get the original Text back // out of the DBMS. For example if we have the string "1234\'5678" and we do not alter it since the apostrophe is // already escaped, we will get the string "1234'5678" when we retrieve it FROM the DBMS! if ( charNeedsEscaping ( cCurrent ) ) { carrBuffer [nBuffIdx++] = '\\' ; } /* endif */ carrBuffer [nBuffIdx++] = cCurrent ; } /* endfor */ String strgReturn = new String ( carrBuffer , 0 , nBuffIdx ) ; return strgReturn ; } /* static String fixupString ( String string ) */ ---Atika wrote: > > HI! > Can anyone help, > I want to store a string into a relation that might contain an apostrophe > ('). Is there anyway around this or can I not store such strings. > Thanks for your help == Peace, Peter We are Microsoft of Borg, you will be assimilated!!! Resistance is fut... ***BZZZRT*** THUD!!! [General Protection Fault in MSBorg32.DLL] Please contact the vendor of this Borg for more information _________________________________________________________ DO YOU YAHOO!? Get your free @yahoo.com address at http://mail.yahoo.com