Re: Problem in opening an cursor in a C program embedded SQL statements

From: Marek Pytlik <pytlik_at_ra.cs.umb.edu>
Date: 31 Oct 92 03:04:15 GMT
Message-ID: <1992Oct31.030415.3601_at_cs.umb.edu>


In article <manhhoa.720463872_at_tdsb-s> manhhoa_at_mais.hydro.qc.ca (Manh-Hoa Le) writes:
>
> S.O.S. - S.O.S. - S.O.S. - S.O.S. - S.O.S. - S.O.S. - S.O.S. - S.O.S.
>
> My application written in C and embedded SQL statements has been suspended
>for a long long time in opening an cursor (after my traces). It is really obscur
>because my other application runs very well in the same syntax. How could I fix
>the problem?
>
> N.B. : The table in query has 100 rows.
>
>/***************************** P R O G R A M ****************************
>
>#include <stdio.h>
>#include <ctype.h>
>#include <string.h>
>#include <math.h>
>
>/* Variables globales utilisees par des procedures */
>
>#define TRUE 1
>#define FALSE !TRUE
>
>#define PRECISION 0.000000555
>#define PI 3.141592653589793238462643
>#define MIN_FLOAT 1.00e-24
>
>typedef int BOOLEAN;
>
>double azimut_prec,
> azimut,
> diff_chainage,
> distance,
> angle,
> long_courb_totale,
> long_courb_partielle,
> delta;
>
>int signe;
>
>EXEC SQL BEGIN DECLARE SECTION;
>
> VARCHAR code_ouvr [11];
>
> double chainage_debut,
> chainage_fin,
> azimut_base,
> rayon_section,
> coord_est, /* Coordonnies Est et Nord ` mettre ` jour */
> coord_nord;
>
> int seq_geometrie;
>
>EXEC SQL END DECLARE SECTION;
>
>EXEC SQL INCLUDE SQLCA;
>
>BOOLEAN chainage_ecart_axe_E_N ();
>
>main ()
>{
> double coord_x_est, coord_y_nord;
> BOOLEAN exist_geo_base, chainage_ok;
>
> chainage_ecart_axe_E_N ("QA-08", "TR-03", 1446.990000, 1.190000,
> &coord_x_est, &coord_y_nord,
> &exist_geo_base, &chainage_ok);
>
> printf ("%f %f\n", coord_x_est, coord_y_nord);
>}
>
>BOOLEAN chainage_ecart_axe_E_N (code_ouv, no_instrument, chainage, ecart_axe,
> coord_x_est, coord_y_nord,
> exist_geo_base, chainage_ok)
>char *code_ouv, *no_instrument;
>double chainage, ecart_axe, *coord_x_est, *coord_y_nord;
>BOOLEAN *exist_geo_base, *chainage_ok;
>{
>
> /*---- Initialisation ----*/
>
> strcpy (code_ouvr.arr, code_ouv);
> code_ouvr.len = strlen (code_ouvr.arr);
>
> *exist_geo_base = 0;
> *chainage_ok = 0;
>
> /*---- Traitement ----*/
>
> EXEC SQL WHENEVER SQLERROR GOTO err_s;
>
> EXEC SQL DECLARE geo_base CURSOR FOR
> SELECT geo.seq_geometrie, geo.azimut,
> geo.coordonnee_nord, geo.coordonnee_est,
> geo.chainage_debut, geo.chainage_fin,
> geo.rayon_section
> FROM gdat.geometrie_base geo
> WHERE geo.code_ouvrage = :code_ouvr
> ORDER BY geo.seq_geometrie;
>
>*************************************************************************
>*************************************************************************
> EXEC SQL OPEN geo_base; <<==== THE PROGRAM HAS BEEB STOPPED HERE
> FOR A LONG PERIOD OF TIME
>*************************************************************************
>*************************************************************************
>
> EXEC SQL WHENEVER NOT FOUND GOTO err_s;
>
> while (1) /* Recherche des instruments */
> {
> EXEC SQL FETCH geo_base INTO :seq_geometrie, :azimut_base,
> :coord_nord, :coord_est,
> :chainage_debut, :chainage_fin,
> :rayon_section;
>
> if ((chainage_debut <= chainage) && (chainage <= chainage_fin))
> {
> calcul (chainage, ecart_axe, coord_x_est, coord_y_nord);
>
> azimut_prec = azimut_base;
> *chainage_ok = 1;
> }
>
> *exist_geo_base = 1;
> }
>
> err_s:
>
> EXEC SQL CLOSE geo_base;
>
> if ((sqlca.sqlcode != 1403) && (sqlca.sqlcode != 0))
> {
> printf ("** Erreur geo_base > %s.\n Contacter support technique\n",
> sqlca.sqlerrm.sqlerrmc);
> exit(1);
> }
>
> /*---- Data not found (sqlca.sqlcode = 1403) ----*/
>
> if (*exist_geo_base && !*chainage_ok)
> {
> printf ("Point: %s, %s, %f, %f %s\n",
> no_instrument, code_ouv, chainage, ecart_axe,
> "` l'intirieur d'aucune siquence giomitrique");
>
> return TRUE;
> }
>
> return FALSE;
>}
>
>BOOLEAN calcul (chainage, ecart_axe, coord_x_est, coord_y_nord)
>double chainage, ecart_axe, *coord_x_est, *coord_y_nord;
>{
> if ((diff_chainage = chainage - chainage_debut) == 0)
> diff_chainage = MIN_FLOAT;
>
> if (rayon_section == 0)
> {
> /*---- Calcul de la distance ----*/
>
> distance = sqrt(diff_chainage*diff_chainage + ecart_axe*ecart_axe);
>
> /*---- Calcul de l'angle ----*/
>
> if (ecart_axe > 0)
> azimut = 90 - atan (diff_chainage / ecart_axe);
> else
> azimut = -90 - atan (diff_chainage / ecart_axe);
>
> angle = azimut + azimut_base;
> }
> else
> {
> /*---- Calcul de la distance ----*/
>
> long_courb_totale = chainage_fin - chainage_debut;
> long_courb_partielle = chainage - chainage_debut;
>
> delta = (long_courb_totale * 360) / (2*PI*rayon_section);
>
> signe = 1;
> azimut_prec += 90;
> if ((azimut_base-PRECISION <= azimut_prec) &&
> (azimut_prec <= azimut_base+PRECISION))
> signe = -1;
>
> distance = rayon_section - (ecart_axe*signe);
>
> /*---- Calcul de l'angle ----*/
>
> angle = (delta * (long_courb_partielle / long_courb_totale)) * signe
> + azimut_base;
> }
>
> *coord_y_nord = coord_nord + (cos(angle) * distance);
> *coord_x_est = coord_est + (sin(angle) * distance);
>}

Your problem is that after your declare cursor statement fails, it goes to your error label and having sqlca.sqlcode < 0, you try to close that cursor, (that was not even open), it goes back to the error label and so on..

Hope it helps.

Mark Received on Sat Oct 31 1992 - 04:04:15 CET

Original text of this message