NULL values in C Structures [message #456583] |
Tue, 18 May 2010 10:09  |
mjm22
Messages: 54 Registered: January 2010 Location: Singapore
|
Member |
|
|
Hi
I use a cursor to select records from a database table into a C structure as follows...
{
int iLoop = 0;
int iResult = 0;
int iZeroRowCheck = 0;
int iTotalRowsFetched = 0;
int iTotalRowsProcessed = 0;
EXEC SQL BEGIN DECLARE SECTION;
int dbBatchSize = 500;
typedef struct itemdatadb_t
{ int dbServiceTypeId;
char dbServiceId[MAX_ATTRIBUTE_LEN];
char dbCustRefExt[MAX_ATTRIBUTE_LEN];
char dbFrom[MAX_DATE_LEN];
char dbTo[MAX_DATE_LEN];
float dbMultiplier;
} itemDataDb_t;
itemDataDb_t *pitemDataDb;
typedef struct ind_itemdatadb_t
{ short ind_dbServiceTypeId;
short ind_dbServiceId;
short ind_dbCustRefExt;
short ind_dbFrom;
short ind_dbTo;
short ind_dbMultiplier;
} ind_itemDataDb_t;
ind_itemDataDb_t *pind_itemDataDb;
EXEC SQL END DECLARE SECTION;
MALLOC(pitemDataDb, itemDataDb_t, gFetchBatchSize);
MALLOC(pind_itemDataDb, ind_itemDataDb_t, gFetchBatchSize);
EXEC SQL DECLARE curGetItems CURSOR FOR
SELECT service_type_id,
service_code_id,
rsp_cust_ref_id,
from_date,
to_date,
otc_multiplier
FROM custdetails
ORDER BY service_code_id;
EXEC SQL OPEN curGetItems;
for (;;)
{
EXEC SQL FOR :dbBatchSize
FETCH curGetItems
INTO :pitemDataDb:pind_itemDataDb;
iZeroRowCheck = sqlca.sqlcode;
iTotalRowsFetched = NUM_ROWS_FOUND;
for (iLoop = 0; iLoop < (iTotalRowsFetched - iTotalRowsProcessed); iLoop++)
{
// function call here to populate an array with record retrieved
}
iTotalRowsProcessed = iTotalRowsFetched;
if (iZeroRowCheck == 1403)
{
break;
}
}
EXEC SQL CLOSE curGetItems;
FREE(pitemDataDb);
FREE(pind_itemDataDb);
}
The otc_multiplier field is NULL. As is the to_date sometimes. However, when I output the records later, the entries where the to_date is NULL come out fine (no value). But the otc_multiplier is getting output as 0.0 using...
// this is output later in another fuction using the following..
sprintf(newRecord, "%.1f",daServiceRecs->itemMultiplier);
If using c structures in this manner, what is the method for ensuring that numeric values are set to NULL when required?
|
|
|
|
|