Navigation


Changeset 772:c6969f1af9f3 in freeDiameter


Ignore:
Timestamp:
Nov 1, 2011, 6:12:18 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Fix app_acct and associated test

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_acct/acct_db.c

    r771 r772  
    5959#endif /* TEST_DEBUG */
    6060pthread_key_t connk;
     61static char * sql = NULL;   /* The buffer that will contain the SQL query */
     62static int nbrecords = 0;
    6163
    6264
     
    6668        struct acct_record_list emptyrecords;
    6769        struct fd_list * li;
    68         char * sql=NULL;   /* The buffer that will contain the SQL query */
    6970        size_t sql_allocd = 0; /* The malloc'd size of the buffer */
    7071        size_t sql_offset = 0; /* The actual data already written in this buffer */
     
    197198        }
    198199        PQclear(res);
    199        
    200         free(sql);
     200        nbrecords = emptyrecords.nball;
     201       
    201202        acct_rec_empty(&emptyrecords);
    202203       
     
    212213{       
    213214        CHECK_POSIX_DO(pthread_key_delete(connk) , );
     215        free(sql);
    214216}
    215217
     
    225227        struct fd_list *li;
    226228        PGconn *conn;
     229        int new = 0;
    227230       
    228231        TRACE_ENTRY("%p", records);
     
    233236                conn = PQconnectdb(acct_config->conninfo);
    234237                CHECK_POSIX( pthread_setspecific(connk, conn) );
     238               
     239                new = 1;
    235240        }
    236241       
     
    244249                        return ENOTCONN;
    245250                }
     251        }
     252       
     253        if (new) {
     254                /* Create the prepared statement for this ocnnection, it is not shared */
     255                res = PQprepare(conn, stmt, sql, nbrecords, NULL);
     256                if (PQresultStatus(res) != PGRES_COMMAND_OK) {
     257                        TRACE_DEBUG(INFO, "Preparing statement '%s' failed: %s",
     258                                sql, PQerrorMessage(conn));
     259                        PQclear(res);
     260                        return EINVAL;
     261                }
     262                PQclear(res);
    246263        }
    247264       
  • tests/testappacct.c

    r771 r772  
    253253        {
    254254                PGresult * res;
    255                 char * s;
     255                uint8_t * bs;
     256                char * es;
     257                size_t l;
     258                int i;
    256259                res = PQexec(conn, "SELECT \"Session-Id\" from " TABLE ";");
    257260                CHECK( PGRES_TUPLES_OK, PQresultStatus(res) );
    258261               
    259262                /* We also check that the Session-Id we retrieve is the same as what we generated earlier (not trashed in the process) */
    260                 s = PQgetvalue(res, 0, 0);
    261                 CHECK( 0, strcmp(s, (char *)sess_bkp) );
     263                es = PQgetvalue(res, 0, 0);
     264                bs = PQunescapeBytea((uint8_t *)es, &l);
     265               
     266                CHECK( 0, fd_os_cmp(bs, l, sess_bkp, sess_bkp_len) );
    262267               
    263268                PQclear(res);
     269                PQfreemem(bs);
    264270        } 
    265271
Note: See TracChangeset for help on using the changeset viewer.