From: Michael Meskes <meskes@postgresql.org>
To: yoonghm@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13617: ecpg cannot handle boolean field within a structure
Date: Thu, 17 Sep 2015 15:46:18 +0200
Message-ID: <20150917134618.GA27139@feivel.credativ.lan> (raw)
In-Reply-To: <20150913163251.2680.14819@wrigleys.postgresql.org>
References: <20150913163251.2680.14819@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:ecpg.diff (text/x-diff, 2.7K) download
commit 293fd7c77e40cdf06b7a9eb6db95379be8869b04
Author: Michael Meskes <meskes@postgresql.org>
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.cindex 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.cindex 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, "}");
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: meskes@postgresql.org, yoonghm@gmail.com
Subject: Re: BUG #13617: ecpg cannot handle boolean field within a structure
In-Reply-To: <20150917134618.GA27139@feivel.credativ.lan>
References: <20150913163251.2680.14819@wrigleys.postgresql.org> <20150917134618.GA27139@feivel.credativ.lan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox