Unix Technical Forum

ECPG usage

This is a discussion on ECPG usage within the Pgsql General forums, part of the PostgreSQL category; --> Hi, I have the follwing ECPG code. ------------------------------------------------------------------------- #include <stdio.h> EXEC SQL INCLUDE sqlca; int main () { EXEC ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 10:41 AM
Jasbinder Bali
 
Posts: n/a
Default ECPG usage

Hi,
I have the follwing ECPG code.

-------------------------------------------------------------------------

#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;

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

sprintf(query_string,"SELECT title FROM films WHERE kind =
'%s'",movie_type);

printf("query string is : '%s'\n",query_string);

EXEC SQL PREPARE s_movie FROM :query_string;
EXEC SQL DECLARE c_movie CURSOR FOR s_movie;

EXEC SQL OPEN c_movie;

EXEC SQL WHENEVER NOT FOUND DO BREAK;

while(1)
{
EXEC SQL FETCH IN c_movie INTO :movie_title;
printf("%s\n",movie_title);
movie_title = NULL;
}

free (movie_title);

EXEC SQL CLOSE c_movie;

EXEC SQL COMMIT;

EXEC SQL DISCONNECT;

return 0;
}

----------------------------------------------------------

At while loop, it keeps on looping forever and my table has 2 records for
the query that is eventually build.
Does that mean EXEC SQL WHENEVER NOT FOUND DO BREAK; is not
working.

Any kind of help would be appreciated.

Thanks,
~Jas

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:43 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com