Re: [NOVICE] DB insert Error - Mailing list pgsql-general

From Michael Fuhr
Subject Re: [NOVICE] DB insert Error
Date
Msg-id 20060816204227.GA74237@winnie.fuhr.org
Whole thread Raw
In response to Re: [NOVICE] DB insert Error  ("Jasbinder Bali" <jsbali@gmail.com>)
Responses Re: [NOVICE] DB insert Error  ("Harpreet Dhaliwal" <harpreet.dhaliwal01@gmail.com>)
List pgsql-general
On Wed, Aug 16, 2006 at 04:11:23PM -0400, Jasbinder Bali wrote:
> I'm sending u the main() function that has the ECPG Insert statement and
> commit in it.

The program you posted isn't a simplified example as I requested.
The idea is that anybody should be able to compile the code and run
it; that's not possible with the code you posted because it's
incomplete.  It also contains many lines that aren't relevant to
the problem, which makes it harder to focus on what is relevant.

While stripping down the code I noticed a problem: it never initializes
the i variable before doing this:

>    while(!feof(fp))
>      {ch[i]=fgetc(fp);
>       if(ch[i]=='\n') lines++;
>       i++;
>      }
>    ch[i-1]='\0';

On my system that results in a segmentation fault and core dump
because i contains garbage, causing ch[i] to point somewhere illegal.
It's possible that on your system i contains garbage but that ch[i]
points to valid memory, just not to where it should.  As a result,
the ch you insert into the database doesn't contain the data it's
supposed to.  See if initializing i = 0 fixes the problem.  Most
compilers have options to warn about uninitialized variables; I'd
recommend using them.

If that doesn't help then please post a small (10-20 line), complete
program that anybody could compile and run.

--
Michael Fuhr

pgsql-general by date:

Previous
From: Kevin Murphy
Date:
Subject: Re: COLLATE
Next
From: "Dawid Kuroczko"
Date:
Subject: Re: Best approach for a "gap-less" sequence