Re: [NOVICE] DB insert Error

From: "Harpreet Dhaliwal" <harpreet(dot)dhaliwal01(at)gmail(dot)com>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: "Jasbinder Bali" <jsbali(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] DB insert Error
Date: 2006-08-16 21:58:58
Message-ID: d86a77ef0608161458u508bee9v17a87a4331c2588e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

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(at)fuhr(dot)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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2006-08-16 21:59:25 Re: Triggers invoking a stored procedure or a C function
Previous Message Jeff Davis 2006-08-16 21:25:34 Re: Move db files from one pgsql instance to another

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Meskes 2006-08-17 07:18:37 Re: [NOVICE] DB insert Error
Previous Message Michael Fuhr 2006-08-16 20:42:27 Re: [NOVICE] DB insert Error