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: 20061016154559.89909.qmail@web53204.mail.yahoo.com (view raw or flat)
Thread:
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..

#include<stdio.h>
int main()
{
        EXEC SQL BEGIN DECLARE SECTION;
        char *target="mydb(at)localhost";
        int i;
        char msg[10];
        EXEC SQL END DECLARE SECTION;

        ECPGdebug(1, stderr);
        //strcpy(msg,"\'AAAA\'");
        i=9;

        EXEC SQL CONNECT TO :target;

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

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

        EXEC SQL DISCONNECT;
        return 1;
}


Thanks,
Yadnyesh.




-- 
Michael Fuhr






Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php

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: pgfoundry.org cksums?

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