Re: Bug #640: ECPG: inserting float numbers

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>, edx(at)astercity(dot)net, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org, meskes(at)postgresql(dot)org
Subject: Re: Bug #640: ECPG: inserting float numbers
Date: 2002-06-11 11:40:14
Message-ID: 15621.57758.130976.116610@kelvin.csl.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Bruce, after checking the libecpg source i'm fairly sure the problem
is due to the malloc buffer that the float is being sprintf'd into
being too small... It is always allocated 20 bytes but with a %.14g
printf specifier -6e-06 results in 20 characters:

-6.0000000000000e-06

and the NULL goes... bang! I guess the '-' wasn't factored in and 21
bytes would be enough. Patch against current CVS (but untested):

Index: src/interfaces/ecpg/lib/execute.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/lib/execute.c,v
retrieving revision 1.36
diff -r1.36 execute.c
703c703
< if (!(mallocedval = ECPGalloc(var->arrsize * 20, stmt->lineno)))
---
> if (!(mallocedval = ECPGalloc(var->arrsize * 21, stmt->lineno)))
723c723
< if (!(mallocedval = ECPGalloc(var->arrsize * 20, stmt->lineno)))
---
> if (!(mallocedval = ECPGalloc(var->arrsize * 21, stmt->lineno)))

Lee.

Bruce Momjian writes:
>
> OK, I have reproduced the problem on my machine:
>
> #$ ./a.out floattest
> col1: -0.000006
> *!*!* Error -220: No such connection NULL in line 21.
>
> Wow, how did that "A" get into the query string:
>
> insert into tab1 ( col1 ) values ( -6.0000002122251e-06A )
>
> Quite strange. Michael, any ideas?
>
> Lee Kindness wrote:
> Content-Description: message body text
>
> > Bruce, the attached source reproduces this on 7.2, I don't have a
> > later version at hand to test if it's been fixed:
> >
> > createdb floattest
> > echo "CREATE TABLE tab1(col1 FLOAT);" | psql floattest
> > ecpg insert-float.pgc
> > gcc insert-float.c -lecpg -lpq
> > ./a.out floattest
> >
> > results in:
> >
> > col1: -0.000006
> > *!*!* Error -400: 'ERROR: parser: parse error at or near "a"' in line 21.
> >
> > and in epcgdebug:
> >
> > [29189]: ECPGexecute line 21: QUERY: insert into tab1 ( col1 ) values ( -6.0000002122251e-06A ) on connection floattest
> > [29189]: ECPGexecute line 21: Error: ERROR: parser: parse error at or near "a"
> > [29189]: raising sqlcode -400 in line 21, ''ERROR: parser: parse error at or near "a"' in line 21.'.
> >
> > Regards, Lee Kindness.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2002-06-11 16:33:31 Bug #689: Bug at moving cursor on joined tables
Previous Message Matej Hollý 2002-06-11 11:12:43 referential integrity error

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2002-06-11 11:47:13 Re: Timestamp/Interval proposals: Part 2
Previous Message Bruce Momjian 2002-06-11 10:58:54 Re: Bug #640: ECPG: inserting float numbers