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 |
Thread: | |
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 | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2015-09-13 22:57:11 | Re: PQexec() hangs on OOM |
Previous Message | Amit Kapila | 2015-09-12 09:11:06 | Re: PQexec() hangs on OOM |