Re: BUG #13617: ecpg cannot handle boolean field within a structure

Lists: Postg토토 캔SQL : Postg토토 캔SQL 메일 링리스트 : 2015-09-17 이후 PGSQL-BUGS 13:46
From: yoonghm(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13617: ecpg cannot handle boolean field within a structure
Date: 2015-09-13 16:32:51
Message-ID: 20150913163251.2680.14819@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13617
Logged by: Yoong Hor Meng
Email address: yoonghm(at)gmail(dot)com
PostgreSQL version: 9.4.4
Operating system: Linux
Description:

// Compile the source code

#include <stdio.h>
#include <stdlib.h>
#include <ecpglib.h>

/*
psql << "EOF"
#
# Create database 'todo' and table 'items'. Fill the table.
#
CREATE DATABASE todo;

\c todo

CREATE TABLE items
(
id serial PRIMARY KEY,
task VARCHAR(40) NOT NULL,
complete boolean
);

INSERT INTO items (id, task, complete) VALUES (1, 'task1', true);
INSERT INTO items (id, task, complete) VALUES (2, 'task2', true);
INSERT INTO items (id, task, complete) VALUES (3, 'task3', true);
INSERT INTO items (id, task, complete) VALUES (4, 'task4', true);
INSERT INTO items (id, task, complete) VALUES (5, 'task5', false);
INSERT INTO items (id, task, complete) VALUES (6, 'task6', false);

EOF
*/

int
main(void)
{
#if ENABLE_DEBUG
ECPGdebug(1, stderr);
#endif
EXEC SQL WHENEVER SQLERROR sqlprint;

EXEC SQL BEGIN DECLARE SECTION;
/* Use structure as host variable */
typedef struct {
int id;
char task[40];
bool complete;
} item_t;
item_t item;

/* Use individual variables as host variables */
int id;
char task[40];
bool complete;

EXEC SQL END DECLARE SECTION;

memset(&item, 0, sizeof(item_t));

EXEC SQL CONNECT TO todo;

/*
* Use structure as host variable
*/
EXEC SQL DECLARE cur1 CURSOR FOR
SELECT id, task, complete
FROM items;
EXEC SQL OPEN cur1;

printf("sizeof(item_t) = %ld\n", sizeof(item));
printf(" sizeof(item.int) = %ld\n", sizeof(item.id));
printf(" sizeof(item.task) = %ld\n", sizeof(item.task));
printf(" sizeof(item.complete) = %ld\n", sizeof(item.complete));

printf("\n"
"Using structure variable\n"
"------------------------\n");

EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (1)
{
EXEC SQL FETCH FROM cur1 INTO :item;

printf("id=%d, task=%s, complete=%d\n\n",
item.id, item.task, item.complete);
}
EXEC SQL CLOSE cur1;

/*
* Use individual variables as host variables
*/
EXEC SQL DECLARE cur2 CURSOR FOR
SELECT id, task, complete
FROM items;
EXEC SQL OPEN cur2;

printf("sizeof(int) = %ld\n", sizeof(id));
printf("sizeof(task) = %ld\n", sizeof(task));
printf("sizeof(complete) = %ld\n", sizeof(complete));

printf("\n"
"Using individual variables\n"
"--------------------------\n");

EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (1)
{
EXEC SQL FETCH FROM cur2 INTO :id, :task, :complete;

printf("id=%d, task=%s, complete=%d\n",
id, task, complete);
}

EXEC SQL CLOSE cur2;

EXEC SQL DISCONNECT ALL;
return 0;
}

/* Create the database todo and table items as in the source code. Insert
records too.
*/

/*
sizeof(item_t) = 48
sizeof(item.int) = 4
sizeof(item.task) = 40
sizeof(item.complete) = 1

Using structure variable
------------------------
SQL error: could not convert boolean value: size mismatch, on line 80
id=1, task=task1, complete=0

SQL error: could not convert boolean value: size mismatch, on line 80
id=2, task=task2, complete=0

SQL error: could not convert boolean value: size mismatch, on line 80
id=3, task=task3, complete=0

SQL error: could not convert boolean value: size mismatch, on line 80
id=4, task=task4, complete=0

SQL error: could not convert boolean value: size mismatch, on line 80
id=5, task=task5, complete=0

SQL error: could not convert boolean value: size mismatch, on line 80
id=6, task=task6, complete=0

sizeof(int) = 4
sizeof(task) = 40
sizeof(complete) = 1

Using individual variables
--------------------------
id=1, task=task1, complete=1
id=2, task=task2, complete=1
id=3, task=task3, complete=1
id=4, task=task4, complete=1
id=5, task=task5, complete=0
id=6, task=task6, complete=0

*/


From: Michael Meskes <meskes(at)postgresql(dot)org>
To: yoonghm(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13617: ecpg cannot handle boolean field within a structure
Date: 2015-09-17 13:46:18
Message-ID: 20150917134618.GA27139@feivel.credativ.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 캔SQL : Postg토토 캔SQL 메일 링리스트 : 2015-09-17 이후 PGSQL-BUGS 13:46

On Sun, Sep 13, 2015 at 04:32:51PM +0000, yoonghm(at)gmail(dot)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

Attachment Content-Type Size
ecpg.diff text/x-diff 2.7 KB

From: Hor Meng Yoong <yoonghm(at)gmail(dot)com>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13617: ecpg cannot handle boolean field within a structure
Date: 2015-09-17 17:52:29
Message-ID: CAEKCi__VwV43rPWbNuokPkiF1eomY4FM+-ZNwZhGe=488ePa0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Dear Michael:

It is working now. Thank.

On Thu, Sep 17, 2015 at 9:46 PM, Michael Meskes <meskes(at)postgresql(dot)org>
wrote:

> On Sun, Sep 13, 2015 at 04:32:51PM +0000, yoonghm(at)gmail(dot)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
>