Regarding PL/SQL with C

Поиск
Список
Период
Сортировка
От Krishnaprasad
Тема Regarding PL/SQL with C
Дата
Msg-id 4400166F.7000309@hcl.in
обсуждение исходный текст
Ответы Re: Regarding PL/SQL with C  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-novice
Dear All,

          Iam a newbiw to PL/SQL. So iam having a query regarding
accessing PL/SQL through C program.

I have written code for connecting to a database and select one row and
just print it out.. Iam able to make a connection with the databse. But
after connection it is showing that select query failed.... but if iam
directly selecting through PL/SQL prompt iam able to do the same.......

I have attached the source file also.........

thanks & regards
krishnaprasd

-

#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>

        int
        main()
        {
            char        state_code[3];
            char        query_string[256];
            PGconn     *conn;
            PGresult   *res;
            int         i;

        conn = PQconnectStart("user=postgres,dbname=krishna");

        switch(PQstatus(conn))
        {
            case CONNECTION_MADE:
                printf("Connection established\n");
                break;
            case CONNECTION_BAD:
                printf("Connection error\n");
                break;
            default:
                printf("No choice\n");
        }

            sprintf(query_string,"SELECT * from prasad");

           res = PQexec (conn,query_string);


            if (PQresultStatus(res) != PGRES_TUPLES_OK)
            {
                fprintf(stderr, "SELECT query failed.\n");
                PQclear(res);
                PQfinish(conn);
                exit(1);
            }

            for (i = 0; i < PQntuples(res); i++)
                printf("%s\n", PQgetvalue(res, i, 0));

            PQclear(res);

            PQfinish(conn);

            return 0;
        }

В списке pgsql-novice по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Regarding PL/SQL with C
Следующее
От: "Juan Ravera"
Дата:
Сообщение: UNSUSCRIBE