Home » Developer & Programmer » Precompilers, OCI & OCCI » PRO C
icon9.gif  PRO C [message #128027] Thu, 14 July 2005 13:03 Go to next message
mql80
Messages: 4
Registered: April 2005
Junior Member
Hi,

I am stuck in a infinite loop and don't know why... please help.. here's my code... the infinite loop is always the last value in the table..

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>

/* Define constants for VARCHAR lengths. */
#define     UNAME_LEN      20
#define     PWD_LEN        40

VARCHAR     username[UNAME_LEN];  /* VARCHAR is an Oracle-supplied struct */
varchar     password[PWD_LEN];    /* varchar can be in lower case also. */

/* Define a host structure for the output values of
   a SELECT statement.  */
struct record
{
    VARCHAR   virtual_number[12];
    VARCHAR   network_ior_ln[12];
    VARCHAR   actv_ln[4];
    VARCHAR   serial[10];
    int       t_date;
} ;

/* Define an indicator struct to correspond
   to the host output struct. */
struct
{
    short     v_number_ind;
    short     network_ind;
    short     actv_ind;
    short     serial_ind;
    short     t_date_ind;
} emp_rec_ptr_ind;

/*  Input host variable. */
int         emp_number;

#include <sqlca.h>

/* Declare error handling function. */
void sql_error(msg)
    char *msg;
{
    char err_msg[128];
    size_t buf_len, msg_len;

    printf("\n%s\n", msg);
    buf_len = sizeof (err_msg);
    sqlglm(err_msg, &buf_len, &msg_len);
    printf("%.*s\n", msg_len, err_msg);
 /*   EXEC SQL WHENEVER SQLERROR CONTINUE; */ <-- already tried
    EXEC SQL ROLLBACK RELEASE; 
    exit(EXIT_FAILURE);
}

void main()
{
    struct record *emp_rec_ptr;

    if((emp_rec_ptr = (struct record *) malloc(sizeof(struct record))) == 0)
    {
    exit(EXIT_FAILURE);
    }
    char temp_char[32];

    strncpy((char *) username.arr, "JOB", UNAME_LEN);

    username.len =
      (unsigned short) strlen((char *) username.arr);

    strncpy((char *) password.arr, "JOB", PWD_LEN);
    password.len =
      (unsigned short) strlen((char *) password.arr);

    EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");

   EXEC SQL CONNECT :username IDENTIFIED BY :password;

    printf("\nConnected to ORACLE as user: %s\n", username.arr);

     EXEC SQL DECLARE info CURSOR FOR
        SELECT virtual_number, nvl(network_ior_ln,'0'), nvl(actv_ln,'0'), nvl(serial,'0'), nvl(transaction_date_ln,'20050101')
         FROM HOLDER_ALLOCATION  order by virtual_number ;

 EXEC SQL OPEN info;
 /*EXEC SQL WHENVER SQLERROR CONTINUE */ <-- already tried
 /*EXEC SQL WHENEVER NOT FOUND DO BREAK */ <-- already tried
 EXEC SQL WHENEVER NOT FOUND DO break;// <--WHY DOESN"T THIS WORK
sqlca.sqlcode = 0;

while (sqlca.sqlcode != 1403)  // Tried this before for(;;)
{
 EXEC SQL FETCH info INTO :emp_rec_ptr;
         emp_rec_ptr->virtual_number.arr[emp_rec_ptr->virtual_number.len] = '\0';
         emp_rec_ptr->network_ior_ln.arr[emp_rec_ptr->network_ior_ln.len] = '\0';
         emp_rec_ptr->actv_ln.arr[emp_rec_ptr->actv_ln.len] = '\0';
         emp_rec_ptr->serial.arr[emp_rec_ptr->serial.len] = '\0';
 printf("\n%s  %s %s %s %d      ",
             emp_rec_ptr->virtual_number.arr, emp_rec_ptr->network_ior_ln.arr, emp_rec_ptr->actv_ln.arr, emp_rec_ptr->serial.arr, emp_rec_ptr->t_date);
}


EXEC SQL CLOSE info;


notfound:

    EXEC SQL ROLLBACK WORK RELEASE;
    exit(EXIT_SUCCESS);
}
Re: PRO C [message #128262 is a reply to message #128027] Sat, 16 July 2005 08:15 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Try to print the sqlca.sqlcode after each fetch to see if it changes after fetching the last row.

Best regards.

Frank
Re: PRO C [message #128268 is a reply to message #128262] Sat, 16 July 2005 11:59 Go to previous messageGo to next message
mql80
Messages: 4
Registered: April 2005
Junior Member
Hi,

It always return a 0. Therefore the exit condition is never met... Thanks for trying... any other ideas? I'm willing to try anything... Thanks..
Re: PRO C [message #128286 is a reply to message #128268] Sun, 17 July 2005 01:37 Go to previous message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
NOT FOUND is set when sqlca.sqlcode is 100 or 1403, thus, a better test would be:

if (sqlca.sqlcode == 100 || sqlca.sqlcode == 1403)


If you actually tested it and the return code doesn't change, I suggest you immediately log an iTAR with Oracle Support and raise a bug request.

Best regards.

Frank
Previous Topic: C Compiler
Next Topic: problem in preprocessor directive
Goto Forum:
  


Current Time: Thu Mar 28 14:27:04 CDT 2024