Re: ECPG. Badly stuck

From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: "John Smith" <john(at)roundel(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ECPG. Badly stuck
Date: 2006-07-25 18:46:02
Message-ID: a47902760607251146k3baaee98t8a82e0e4c00bde1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi ,

Forget about cursors. Singleton queries are also not working.

Tried writing the follwoing code but doesn't give me any result.
Don't know if i have to do somethin else apart from what i've already done.

include <stdio.h>
EXEC SQL INCLUDE sqlca;

int main ()
{
EXEC SQL BEGIN DECLARE SECTION;
char movie_type[20];
char *movie_title=NULL;
char query_string[256];
EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT TO postgres;

EXEC SQL INSERT INTO films VALUES
(13,'',4,'2002-2-3','AA','01:01:01');

EXEC SQL SELECT title INTO :movie_type FROM films;

printf("enter the type of movie %s",movie_type);

EXEC SQL COMMIT;

}

Please let me know whats going wrong.

I'm compiling my code as follows:

[root(at)localhost ~]# ecpg ecpg_test.pgc
[root(at)localhost ~]# gcc -o jas ecpg_test.c -lecpg -L/usr/lib/pgsql

Regards,
Jas
On 7/23/06, John Smith <john(at)roundel(dot)net> wrote:
>
> Simple:
>
> EXEC SQL select foo from bar into :foo;
>
> printf("foo is %s", foo);
>
>
> If the select statement will return more than one row, then yes, you need
> to define a cursor to access it one row at a time.
>
> John.
>
> ------------------------------
> *From:* pgsql-general-owner(at)postgresql(dot)org [mailto:
> pgsql-general-owner(at)postgresql(dot)org] *On Behalf Of *Jasbinder Bali
> *Sent:* 22 July 2006 18:47
> *To:* pgsql-general(at)postgresql(dot)org
> *Subject:* [GENERAL] ECPG. Badly stuck
>
> Hi,
> I had posted this question a few days back.
> Sending the same question again.
>
> I have a C program and have some ECPG code in it.
>
> How do i display the data that i retrieve from the postgres database using
> a simple select statment or calling a stored procedure.
>
> Is it mandatory to use cursor or there's any other way to print the
> retrieved data..
>
> Any kind of help would be highly appreciated.
> Thanks,
> ~Jas
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brad Nicholson 2006-07-25 18:50:36 Re: Using currval() in an insert statement...
Previous Message Philippe Lang 2006-07-25 18:36:53 Re: Plperl return_next and bytea binary data?