pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ECPG and NULL indicators
3+ messages / 3 participants
[nested] [flat]

* ECPG and NULL indicators
@ 2003-10-23 21:05 Edmund Bacon <ebacon@onesystem.com>
  2003-10-26 05:19 ` Re: [BUGS] ECPG and NULL indicators Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Edmund Bacon @ 2003-10-23 21:05 UTC (permalink / raw)
  To: pgsql-bugs@postgresql.org


============================================================================
                        POSTGRESQL BUG REPORT
============================================================================


Your name		:	Edmund Bacon
Your email address	:	ebacon (at) onesystem (dot) com


System Configuration
---------------------
  Architecture       :   Intel Pentium

  Operating System   :   Linux 2.4.20

  PostgreSQL version :   PostgreSQL-7.3.3

  Compiler used      :	 gcc-3.2.2


Please enter a FULL description of your problem:
------------------------------------------------

ecpg does not correctly set null indicators when storage for the
string is dynamically allocated


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible: 
----------------------------------------------------------------------

CREATE TABLE strings (string text);

insert into strings values('able');
insert into strings values(null);
insert into strings values('baker');
insert into strings values(null);


Source for foo.pgc:

============================================================

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

EXEC SQL WHENEVER SQLERROR sqlprint;

EXEC SQL INCLUDE sqlca;

int main()
{
    int i;
    EXEC SQL BEGIN DECLARE SECTION;
    char **a_str;
    int *a_str_ind;

    char str[5][20];
    int  str_ind[5];
    EXEC SQL END DECLARE SECTION;


    EXEC SQL CONNECT TO test;


    printf("Test one: alloced string, allocated indicator:\n");

    a_str = NULL;
    a_str_ind = NULL;

    EXEC SQL SELECT string INTO :a_str :a_str_ind FROM strings;

    printf("indicator      string\n");
    for(i = 0; i < sqlca.sqlerrd[2]; i++)
	printf("%8d       \"%s\"\n", a_str_ind[i], a_str[i]);
    
    free(a_str);
    free(a_str_ind);


    printf("\nTest two: alloced string, unalloced indicator:\n");
    a_str = NULL;
    for(i = 0; i < 5; i++) str_ind[i] = 99;

    EXEC SQL SELECT string INTO :a_str :str_ind FROM strings;

    printf("indicator      string\n");
    for(i = 0; i < sqlca.sqlerrd[2]; i++)
	printf("%8d       \"%s\"\n", str_ind[i], a_str[i]);

    free(a_str);


    printf("\nTest three: unalloced string, alloced indicator:\n");
    a_str_ind = NULL;
    bzero(str, sizeof(str));

    EXEC SQL SELECT string INTO :str :a_str_ind FROM strings;
    printf("indicator      string\n");
    for(i = 0; i < sqlca.sqlerrd[2]; i++)
	printf("%8d       \"%s\"\n", a_str_ind[i], str[i]);

    free(a_str_ind);


    printf("\nTest four: unalloced string, unalloced indicator:\n");
    bzero(str, sizeof(str));
    for(i = 0; i < 5; i++) str_ind[i] = 99;

    EXEC SQL SELECT string INTO :str :str_ind FROM strings;
    printf("indicator      string\n");
    for(i = 0; i < sqlca.sqlerrd[2]; i++)
	printf("%8d       \"%s\"\n", str_ind[i], str[i]);


    return 0;
}

==================================================================

Output for foo:
==================================================================
Test one: alloced string, allocated indicator:
indicator      string
      -1       "able"
       0       ""
       0       "baker"
       0       ""

Test two: alloced string, unalloced indicator:
indicator      string
      -1       "able"
      99       ""
      99       "baker"
      99       ""

Test three: unalloced string, alloced indicator:
indicator      string
       0       "able"
      -1       ""
       0       "baker"
      -1       ""

Test four: unalloced string, unalloced indicator:
indicator      string
       0       "able"
      -1       ""
       0       "baker"
      -1       ""

==================================================================

Note that when the storage for the string is allocated, only the first 
element of the indicator array is set.  This value is the value of
the indicator for the last string in the string array, which can be
confirmed by using the appropriate ORDER BY clause.

This problem does not arise with allocated integer or float values.
This problem occurs if string is any multi-char type (e.g. TEXT, CHAR(),
or VARCHAR())





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [BUGS] ECPG and NULL indicators
  2003-10-23 21:05 ECPG and NULL indicators Edmund Bacon <ebacon@onesystem.com>
@ 2003-10-26 05:19 ` Bruce Momjian <pgman@candle.pha.pa.us>
  2003-10-26 09:51   ` Re: [BUGS] ECPG and NULL indicators Michael Meskes <meskes@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Bruce Momjian @ 2003-10-26 05:19 UTC (permalink / raw)
  To: Edmund Bacon <ebacon@onesystem.com>; +Cc: pgsql-interfaces; Michael Meskes <Michael.Meskes@credativ.de>


I can confirm this ecpg bug exists in current CVS.  Let me see if the
ecpg guy can look at it soon.

---------------------------------------------------------------------------

Edmund Bacon wrote:
> 
> ============================================================================
>                         POSTGRESQL BUG REPORT
> ============================================================================
> 
> 
> Your name		:	Edmund Bacon
> Your email address	:	ebacon (at) onesystem (dot) com
> 
> 
> System Configuration
> ---------------------
>   Architecture       :   Intel Pentium
> 
>   Operating System   :   Linux 2.4.20
> 
>   PostgreSQL version :   PostgreSQL-7.3.3
> 
>   Compiler used      :	 gcc-3.2.2
> 
> 
> Please enter a FULL description of your problem:
> ------------------------------------------------
> 
> ecpg does not correctly set null indicators when storage for the
> string is dynamically allocated
> 
> 
> Please describe a way to repeat the problem.   Please try to provide a
> concise reproducible example, if at all possible: 
> ----------------------------------------------------------------------
> 
> CREATE TABLE strings (string text);
> 
> insert into strings values('able');
> insert into strings values(null);
> insert into strings values('baker');
> insert into strings values(null);
> 
> 
> Source for foo.pgc:
> 
> ============================================================
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> EXEC SQL WHENEVER SQLERROR sqlprint;
> 
> EXEC SQL INCLUDE sqlca;
> 
> int main()
> {
>     int i;
>     EXEC SQL BEGIN DECLARE SECTION;
>     char **a_str;
>     int *a_str_ind;
> 
>     char str[5][20];
>     int  str_ind[5];
>     EXEC SQL END DECLARE SECTION;
> 
> 
>     EXEC SQL CONNECT TO test;
> 
> 
>     printf("Test one: alloced string, allocated indicator:\n");
> 
>     a_str = NULL;
>     a_str_ind = NULL;
> 
>     EXEC SQL SELECT string INTO :a_str :a_str_ind FROM strings;
> 
>     printf("indicator      string\n");
>     for(i = 0; i < sqlca.sqlerrd[2]; i++)
> 	printf("%8d       \"%s\"\n", a_str_ind[i], a_str[i]);
>     
>     free(a_str);
>     free(a_str_ind);
> 
> 
>     printf("\nTest two: alloced string, unalloced indicator:\n");
>     a_str = NULL;
>     for(i = 0; i < 5; i++) str_ind[i] = 99;
> 
>     EXEC SQL SELECT string INTO :a_str :str_ind FROM strings;
> 
>     printf("indicator      string\n");
>     for(i = 0; i < sqlca.sqlerrd[2]; i++)
> 	printf("%8d       \"%s\"\n", str_ind[i], a_str[i]);
> 
>     free(a_str);
> 
> 
>     printf("\nTest three: unalloced string, alloced indicator:\n");
>     a_str_ind = NULL;
>     bzero(str, sizeof(str));
> 
>     EXEC SQL SELECT string INTO :str :a_str_ind FROM strings;
>     printf("indicator      string\n");
>     for(i = 0; i < sqlca.sqlerrd[2]; i++)
> 	printf("%8d       \"%s\"\n", a_str_ind[i], str[i]);
> 
>     free(a_str_ind);
> 
> 
>     printf("\nTest four: unalloced string, unalloced indicator:\n");
>     bzero(str, sizeof(str));
>     for(i = 0; i < 5; i++) str_ind[i] = 99;
> 
>     EXEC SQL SELECT string INTO :str :str_ind FROM strings;
>     printf("indicator      string\n");
>     for(i = 0; i < sqlca.sqlerrd[2]; i++)
> 	printf("%8d       \"%s\"\n", str_ind[i], str[i]);
> 
> 
>     return 0;
> }
> 
> ==================================================================
> 
> Output for foo:
> ==================================================================
> Test one: alloced string, allocated indicator:
> indicator      string
>       -1       "able"
>        0       ""
>        0       "baker"
>        0       ""
> 
> Test two: alloced string, unalloced indicator:
> indicator      string
>       -1       "able"
>       99       ""
>       99       "baker"
>       99       ""
> 
> Test three: unalloced string, alloced indicator:
> indicator      string
>        0       "able"
>       -1       ""
>        0       "baker"
>       -1       ""
> 
> Test four: unalloced string, unalloced indicator:
> indicator      string
>        0       "able"
>       -1       ""
>        0       "baker"
>       -1       ""
> 
> ==================================================================
> 
> Note that when the storage for the string is allocated, only the first 
> element of the indicator array is set.  This value is the value of
> the indicator for the last string in the string array, which can be
> confirmed by using the appropriate ORDER BY clause.
> 
> This problem does not arise with allocated integer or float values.
> This problem occurs if string is any multi-char type (e.g. TEXT, CHAR(),
> or VARCHAR())
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [BUGS] ECPG and NULL indicators
  2003-10-23 21:05 ECPG and NULL indicators Edmund Bacon <ebacon@onesystem.com>
  2003-10-26 05:19 ` Re: [BUGS] ECPG and NULL indicators Bruce Momjian <pgman@candle.pha.pa.us>
@ 2003-10-26 09:51   ` Michael Meskes <meskes@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Meskes @ 2003-10-26 09:51 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Edmund Bacon <ebacon@onesystem.com>; pgsql-interfaces

On Sun, Oct 26, 2003 at 01:19:57AM -0400, Bruce Momjian wrote:
> 
> I can confirm this ecpg bug exists in current CVS.  Let me see if the
> ecpg guy can look at it soon.

Fix just committed to CVS. Thanks for the report.

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2003-10-26 09:51 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-23 21:05 ECPG and NULL indicators Edmund Bacon <ebacon@onesystem.com>
2003-10-26 05:19 ` Bruce Momjian <pgman@candle.pha.pa.us>
2003-10-26 09:51   ` Michael Meskes <meskes@postgresql.org>

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