pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gianluigi Roveda <roveda@omega.it>
To: pgsql-interfaces@postgresql.org
Subject: PGresult and for-cycle
Date: Tue, 26 Jun 2001 16:23:09 +0200
Message-ID: <3B389ACD.C0824543@omega.it> (raw)

I develop this code:

 PQclear(sol);
 psqlDisconnettiDB(DB);

 ris=(abbonamenti_t **) calloc(nabb,sizeof(abbonamenti_t *));
 sol2=(PGresult **) calloc(nabb,sizeof(PGresult *));

 for (i=0;i<nabb;i++)
 {
    ris[i]=(abbonamenti_t *) calloc(1,sizeof(abbonamenti_t));

    st1=astrcpy("SELECT rivabbval.PrezzoLit, rivabbval.PrezzoEur,
rivabbval.DataInizioValidita, rivabbval.DataFineValidita,
rivtipabb.Descrizione FROM rivabbval, rivtipabb WHERE
rivabbval.IDrav=");
    st2=astrcat(st1,key[i]);
    free(st1);
    st1=astrcat(st2," and rivtipabb.IDrta=rivabbval.IDrta;");
    free(st2);

    DB=(PGconn *) psqlConnettiDB0("mulino_db");
    psqlBeginTransaction(DB);
    psqlLockTable(DB,"rivvalarr","ACCESS EXCLUSIVE MODE");
{FILE *E; E=fopen("problem.txt","a");fprintf(E,"BOOM 2-1 SQL abb
-%s-\n",st1);fclose(E);}

    sol2[i]=PQexec(DB,st1);

    free(st1);
/***/
    ris[i]->lire_abb=atof(PQgetvalue(sol2[i],i,0));
    ris[i]->euro_abb=atof(PQgetvalue(sol2[i],i,1));
    ris[i]->inizio_abb=astrcpy(PQgetvalue(sol2[i],i,2));
    ris[i]->fine_abb=astrcpy(PQgetvalue(sol2[i],i,3));
    ris[i]->abbo=astrcpy(PQgetvalue(sol2[i],i,4));

    PQclear(sol2[i]);
    psqlDisconnettiDB(DB);
 }

the 1st loop is OK, the 2nd produces a core and stops at /***/.
Why ?

Could you help me ?
-----------------------------------
Gianluigi  Roveda
E-mail: roveda@omega.it

Omega Generation S.R.L.
Via Montebello, 2  40121  Bologna
TEL   051/4210311
FAX  051/4211039





Message-ID: <3B389ACD.C0824543@omega.it>
Permalink:  ../3B389ACD.C0824543@omega.it/
Also on:    postgresql.org/message-id/3B389ACD.C0824543@omega.it

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: roveda@omega.it
  Subject: Re: PGresult and for-cycle
  In-Reply-To: <3B389ACD.C0824543@omega.it>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox