Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZbADJ-000307-QO for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Sep 2015 16:33:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZbADH-0006w1-OQ for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Sep 2015 16:33:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZbADG-0006vs-9Q for pgsql-bugs@postgresql.org; Sun, 13 Sep 2015 16:33:10 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZbAD9-0000OA-6Q for pgsql-bugs@postgresql.org; Sun, 13 Sep 2015 16:33:09 +0000 MIME-Version: 1.0 Subject: BUG #13617: ecpg cannot handle boolean field within a structure To: pgsql-bugs@postgresql.org From: yoonghm@gmail.com Date: Sun, 13 Sep 2015 16:32:51 +0000 Message-ID: <20150913163251.2680.14819@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13617 Logged by: Yoong Hor Meng Email address: yoonghm@gmail.com PostgreSQL version: 9.4.4 Operating system: Linux Description: // Compile the source code #include #include #include /* 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 */ -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs