ECPG usage - Mailing list pgsql-general

From Jasbinder Bali
Subject ECPG usage
Date
Msg-id a47902760607201256x57bb49bw8fc2301aaf2befc9@mail.gmail.com
Whole thread Raw
Responses Re: ECPG usage  (Michael Meskes <meskes@postgresql.org>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Pavel Golub
Date:
Subject: pg_dump & pg_restore suggestion
Next
From: Eric Faulhaber
Date:
Subject: Re: UTF8 conversion differences from v8.1.3 to v8.1.4