From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Jasbinder Bali <jsbali(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: [NOVICE] DB insert Error |
Date: | 2006-08-16 20:42:27 |
Message-ID: | 20060816204227.GA74237@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Dawid Kuroczko | 2006-08-16 20:47:36 | Re: Best approach for a "gap-less" sequence |
Previous Message | Kevin Murphy | 2006-08-16 20:32:34 | Re: COLLATE |
From | Date | Subject | |
---|---|---|---|
Next Message | Harpreet Dhaliwal | 2006-08-16 21:58:58 | Re: [NOVICE] DB insert Error |
Previous Message | Jasbinder Bali | 2006-08-16 20:12:45 | Re: [NOVICE] DB insert Error |