Обсуждение: ECPG. Badly stuck

Поиск
Список
Период
Сортировка

ECPG. Badly stuck

От
"Jasbinder Bali"
Дата:
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

Re: ECPG. Badly stuck

От
"Joachim Wieland"
Дата:
On July 22, 7:46 pm "Jasbinder Bali" <jsbali@gmail.com> wrote:
> 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..

There is no copy to stdout if this is what you want. Normally you retrieve
the data with SELECT INTO and then you print the variables in the usual
way. And yes, if there are several rows in your result set you can
iterate over them by means of a cursor.

If you're developing a console based program, of course you (sometimes)
just write the values to stdout but other programs might not be console
based but might use some widget set. Displaying values in those contexts
has nothing to do with ecpg.


Joachim

Re: ECPG. Badly stuck

От
"Jasbinder Bali"
Дата:

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@localhost ~]# ecpg ecpg_test.pgc
[root@localhost ~]# gcc  -o jas ecpg_test.c -lecpg -L/usr/lib/pgsql


Regards,
Jas
On 7/23/06, John Smith < john@roundel.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@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Jasbinder Bali
Sent: 22 July 2006 18:47
To: pgsql-general@postgresql.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

Re: ECPG. Badly stuck

От
Joachim Wieland
Дата:
On Tue, Jul 25, 2006 at 02:46:02PM -0400, Jasbinder Bali wrote:
> 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.

There are many ways your program can fail before actually reaching the
select line but you won't notice because your program fails to check for
errors. Do at least insert a

exec sql whenever sqlerror do sqlprint();

before connecting to the server. For more information on error handling,
see

http://www.postgresql.org/docs/8.1/interactive/ecpg-errors.html


While developing you can also switch on debug output with the ECPGdebug
function described here:

http://www.postgresql.org/docs/8.1/interactive/ecpg-library.html


Joachim

Re: ECPG. Badly stuck

От
Michael Meskes
Дата:
On Tue, Jul 25, 2006 at 02:46:02PM -0400, Jasbinder Bali wrote:
> Forget about cursors. Singleton queries are also not working.

Great statement.

> 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.

How about giving us at least the table definition and the system
information? Yes, I know I asked for those in my last email too. And
please tell us what makes you sure it doesn't work? Just no output?
Or empty output?

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!