Jump to content

need help to execute pgsql querries in C code

- - - - -

  • Please log in to reply
1 reply to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, i've posted the same problem in C forum, but no one answers me. Perhaps in database forum i will get help. I've written a C code for working with pgsql database. I used <sqlca.h> library. In the top of my code i declare cursor for one of the tables in database:
EXEC SQL DECLARE curs1 CURSOR FOR
SELECT Id, Patirtis
FROM lira8851.Instruktoriai
ORDER BY Id;
Then i use function to print that table and i always get error with SQLCODE -220. The function always fails to print step2 mesage so there might be something wrong with opening the cursor. Here's the code of function:

void printInsructorsList()

{[INDENT]     EXEC SQL WHENEVER SQLERROR GOTO error1;

    EXEC SQL WHENEVER NOT FOUND GOTO error2;


    printf("step1\n");

    printf("Instruktoriu sarasas:");

    EXEC SQL OPEN curs1;

    while (1)

    {

[LEFT][INDENT]     printf("step2\n");

        EXEC SQL FETCH curs1 INTO :instructor_id, :experience;

    printf("step3\n");

        printf("ID: %s; Patirtis: %d;\n", instructor_id, experience);

[/INDENT]}

    EXEC SQL CLOSE curs1;


    return;


    error1:[INDENT]     printf("code: %d\n", SQLCODE);

        printf("Ivyko klaida darbo su duomenu baze metu\n");

        return;

[/INDENT]error2:[INDENT]     printf("code: %d\n", SQLCODE);

        printf("Nerasta duomenu\n");

        return;

[/INDENT][/LEFT]

[/INDENT]}

any help?

Edited by Orjan, 10 December 2010 - 10:17 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I suspect most of us are not familiar with the library in question.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users