Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZcZW7-00044N-Gw for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Sep 2015 13:46:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZcZW6-0007Oc-T2 for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Sep 2015 13:46:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZcZW6-0007MH-1N for pgsql-bugs@postgresql.org; Thu, 17 Sep 2015 13:46:26 +0000 Received: from gauss.credativ.com ([93.94.130.89]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZcZW3-0001ND-2H for pgsql-bugs@postgresql.org; Thu, 17 Sep 2015 13:46:24 +0000 Received: from gauss.credativ.com (localhost [127.0.0.1]) by gauss.credativ.com (Postfix) with ESMTP id D7551145001D; Thu, 17 Sep 2015 15:46:19 +0200 (CEST) Received: from feivel (wan1.credativ.com [87.139.82.80]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: mme@gauss.credativ.com) by gauss.credativ.com (Postfix) with ESMTPSA id C2BA21450007; Thu, 17 Sep 2015 15:46:19 +0200 (CEST) Received: by feivel (Postfix, from userid 1000) id 2CB334001C; Thu, 17 Sep 2015 15:46:18 +0200 (CEST) Date: Thu, 17 Sep 2015 15:46:18 +0200 From: Michael Meskes To: yoonghm@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13617: ecpg cannot handle boolean field within a structure Message-ID: <20150917134618.GA27139@feivel.credativ.lan> References: <20150913163251.2680.14819@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150913163251.2680.14819@wrigleys.postgresql.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --J/dobhs11T7y2rNN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Sep 13, 2015 at 04:32:51PM +0000, yoonghm@gmail.com wrote: > The following bug has been logged on the website: > ... Thanks for spotting. The bug was in an area with really old code, that shouldn't be needed anymore. I hope the attached patch fixes it. I also committed this to HEAD. Can you please try and report back? Michael -- Michael Meskes Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) Meskes at (Debian|Postgresql) dot Org Jabber: michael.meskes at gmail dot com VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL --J/dobhs11T7y2rNN Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ecpg.diff" commit 293fd7c77e40cdf06b7a9eb6db95379be8869b04 Author: Michael Meskes Date: Thu Sep 17 15:41:04 2015 +0200 Let compiler handle size calculation of bool types. Back in the day this did not work, but modern compilers should handle it themselves. diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 8d36484..82ab4aa 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -423,27 +423,13 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, case ECPGt_bool: if (pval[0] == 'f' && pval[1] == '\0') { - if (offset == sizeof(char)) - *((char *) (var + offset * act_tuple)) = false; - else if (offset == sizeof(int)) - *((int *) (var + offset * act_tuple)) = false; - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - NULL); + *((bool *) (var + offset * act_tuple)) = false; pval++; break; } else if (pval[0] == 't' && pval[1] == '\0') { - if (offset == sizeof(char)) - *((char *) (var + offset * act_tuple)) = true; - else if (offset == sizeof(int)) - *((int *) (var + offset * act_tuple)) = true; - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - NULL); + *((bool *) (var + offset * act_tuple)) = true; pval++; break; } diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 9e40f41..3b6eedb 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -752,18 +752,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari { strcpy(mallocedval, "{"); - if (var->offset == sizeof(char)) - for (element = 0; element < asize; element++) - sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f'); + for (element = 0; element < asize; element++) + sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f'); - /* - * this is necessary since sizeof(C++'s bool)==sizeof(int) - */ - else if (var->offset == sizeof(int)) - for (element = 0; element < asize; element++) - sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f'); - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); strcpy(mallocedval + strlen(mallocedval) - 1, "}"); } --J/dobhs11T7y2rNN Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --J/dobhs11T7y2rNN--