Search Postgresql Archives

Re: [NOVICE] DB insert Error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux