Received: from pop-c.netway.at (pop-c.netway.at [195.96.0.132]) by hub.org (8.9.3/8.9.3) with ESMTP id FAA64546 for ; Tue, 14 Sep 1999 05:13:16 -0400 (EDT) (envelope-from theofilu@eunet.at) Received: from pop-a.netway.at (pop-a.netway.at [195.96.10.226]) by pop-c.netway.at (8.9.1/8.9.1) with ESMTP id LAA05956; Tue, 14 Sep 1999 11:13:07 +0200 Received: from theofilu ([195.96.30.177]) by pop-a.netway.at (8.9.1/8.9.1) with SMTP id LAA15686; Tue, 14 Sep 1999 11:13:07 +0200 From: Andreas Theofilu Organization: Raiffeisen Landesbank Steiermark To: pgsql-interfaces@postgreSQL.org Subject: Found error with apostrophes in ecpg Date: Tue, 14 Sep 1999 10:34:38 +0200 X-Mailer: KMail [version 1.0.21] Content-Type: text/plain Cc: meskes@debian.org MIME-Version: 1.0 Message-Id: <99091411152301.01383@theofilu> Content-Transfer-Encoding: 8bit Hi, After playing around, I've found now the error in 'libecpg.so' that ignored a quoted apostrophe. Detailed description with correction follows: Symptom: You've written source with embedded SQL comands and you've translated the source with 'ecpg' first and then compiled it with your C compiler. Then you've started the final program and now you wan't to insert a string into a table that contains an apostrophe. The insert command returns with the runtime error "Too many arguments in line xxx", allthough there's no syntax error in your code. Problem: 'libecpg.so' contains an internal function quote_postgres() (in ecpglib.c line 217) that quotes every apostrophe with a backslash. So far so well. The error occures in function next_insert() (in ecpglib.c line 362). This function looks for an apostrophe and if it finds one, it interpretes it as 'end of string'. But it does not care about a backslash in front of the apostrophe. Solution: 361: static char * 362: next_insert(char *text) 363: { 364: char *ptr = text; 365: bool string = false; 366: 367: for (; *ptr != '\0' && (*ptr != '?' || string); ptr++) 368: if (*ptr == '\'' && *(ptr-1) != '\\') 369: string = string ? false : true; 370: 371: return (*ptr == '\0') ? NULL : ptr; 372: } Line 368 was altered by me. The original line looks like: 368: if (*ptr == '\'') As you can see, the backslash is honored now. -- Theofilu Andreas http://members.eunet.at/theofilu ------------------------------------------------- Enjoy the science of Linux! Genieße die Wissenschaft von Linux! -------------------------------------------------