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

From Harpreet Dhaliwal
Subject Re: [NOVICE] DB insert Error
Date
Msg-id d86a77ef0608161458u508bee9v17a87a4331c2588e@mail.gmail.com
Whole thread Raw
In response to Re: [NOVICE] DB insert Error  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Also, I think you should check the special characters in the text that you
are trying to store.
 
I realize from one of your emails that when u run the same query using the PGAdmin query tool, only a part
of the the varchar gets stores and rest it trimmed.
 
This has something to do with the special characters like single quote or a back slash.
 
Harpreet.

 
On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Move db files from one pgsql instance to another
Next
From: Adrian Klaver
Date:
Subject: Re: Best approach for a "gap-less" sequence