Received: from gyw.com (gyw.com [209.55.67.177]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f2JEr4603758 for ; Mon, 19 Mar 2001 09:53:08 -0500 (EST) (envelope-from tjk@tksoft.com) Received: from smtp3.tksoft.com (smtp3.tksoft.com [192.168.50.56] (may be forged)) by gyw.com (8.8.8/8.8.8) with ESMTP id HAA14808; Mon, 19 Mar 2001 07:10:15 -0800 Received: (from tjk@tksoft.com) by smtp3.tksoft.com (8.8.8/8.8.8) id GAA01225; Mon, 19 Mar 2001 06:58:41 -0800 From: "tjk@tksoft.com" Message-Id: <200103191458.GAA01225@smtp3.tksoft.com> Subject: Re: handling special characters in sql strings To: wagner@imsd.uni-mainz.de (Markus Wagner) Date: Mon, 19 Mar 2001 06:58:41 -0800 (PST) Cc: pgsql-sql@postgresql.org (pgsql-sql@postgresql.org) In-Reply-To: <3AB5F816.B42DA79E@imsd.uni-mainz.de> from "Markus Wagner" at Mar 19, 2001 01:14:14 PM X-Info: None MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200103/356 X-Sequence-Number: 2020 Markus, Here are comments from a C function which does what you need. You won't have the regex functions available, so the function itself would be useless. You get the idea though. 1. First change backslashed backslashes back to single backslashes. 2. Find backslash single quote combinations (i.e. "\'") and convert them to single quotes (i.e. "'"). Use a while loop to be sure. Now there should be no single quotes preceded by backslashes left. 3. Find all backslashes and convert them to double backslashes. Now all characters preceded by a backslash should be in their original state, while all backslashed single quotes are just single quotes. E.g. "\1ABC'ABC\2\q" 5. Find all single quotes and backslash them. (Note: There are no single quotes preceded by a backslash, so it is not possible to have a backslash which would hide a backslash preceding a single quote.) That's it. Troy > > Hi, > > I need to insert and retrieve strings containing special characters (e. > g. "'") and I want a C function to prepare my strings automatically. Is > it ok to just insert a "\" before each special character? And what range > of characters will need this handling? > > Thanks, > > Markus > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >