Skip site navigation (1) Skip section navigation (2)

Re: Using host variables -- segmentation fault

From: Yadnyesh Joshi <yadnyesh_joshi(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Using host variables -- segmentation fault
Date: 2006-10-16 15:45:59
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

----- Original Message ----
From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Yadnyesh Joshi <yadnyesh_joshi(at)yahoo(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Sent: Monday, 16 October, 2006 7:11:24 PM
Subject: Re: [NOVICE] Using host variables -- segmentation fault

On Mon, Oct 16, 2006 at 05:16:06AM -0700, Yadnyesh Joshi wrote:
> The first EXEC SQL INSERT INTO simple values (6); executes fine. The
> value is added in the database as I am doing a COMMIT.
> However, segmentation fault occurs at EXEC SQL INSERT INTO simple values (:i);
> What can be the problem?

The program you posted doesn't initialize i but I'd expect that to
result in a garbage value being inserted instead of a segmentation
fault.  Do you still get a segmentation fault if you initialize i?
What about if you comment out the line that inserts i?

Initializing i doesn't make any difference. I still get a segmentation fault.
If I comment the line that inserts i, program executes fine. It runs to the comepletion.

Your program doesn't return a value from main().  I haven't worked
on any platforms where that would cause a segmentation fault but it
should be fixed in any case.

Return value is not a problem. If I add return 1; at the end, the problem persists.

What platform are you on?  What version of PostgreSQL? 
PostgreSQL version - 8.1.5
I am working on Fedora Core 4 - 64 bit version.
Did you get a core dump?  If so, what does a stack trace show? 
I didn't get core dump.

What do you see if you add "ECPGdebug(1, stderr);" at the beginning of the program?
[12328]: ECPGdebug: set to 1
[12328]: ECPGconnect: opening database mydb on localhost port <DEFAULT> 
[12328]: got TSD connection
[12328]: ECPGexecute line 16: QUERY: insert into simple values( 6 ) on connection mydb
[12328]: ECPGexecute line 16 Ok: INSERT 0 1
[12328]: got TSD connection
[12328]: ECPGtrans line 17 action = commit connection = mydb
Before inserting i
[12328]: got TSD connection
Segmentation fault

I added a printf statement just before inserting into i.
For your refernce, here is first.pgc file again..

int main()
        char *target="mydb(at)localhost";
        int i;
        char msg[10];

        ECPGdebug(1, stderr);

        EXEC SQL CONNECT TO :target;

        EXEC SQL INSERT INTO simple values (6);
        printf("Before inserting i\n");
        EXEC SQL INSERT INTO simple values (:i);

        //EXEC SQL INSERT INTO fromprg values (:i,:msg);
        //EXEC SQL COMMIT;

        return 1;


Michael Fuhr

Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now!

pgsql-novice by date

Next:From: meDate: 2006-10-16 15:57:32
Subject: bad planner pick... but why?
Previous:From: Ray StellDate: 2006-10-16 14:34:14
Subject: cksums?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group