Querying With a Prepared Statement

Return Codes

HCERR_OK

HCERR_OOM

HCERR_BAD_REQUEST

HCERR_NULL_SESSION

HCERR_INVALID_SESSION

HCERR_ILLEGAL_ARGUMENT

See Also

“hc_pstmt_create” on page 100

Querying With a Prepared Statement

The following code is an example of querying with a prepared statement. Error handling is omitted. Two metadata fields are used with the definitions from the schema:

<field name="test_date" type="date"> <field name="test_status" type="string">

hcerr_t res; time_t t; struct tm *date;

hc_pstmt_t *pstmt;

hc_query_result_set_t *rset;

hc_string_t selects[] = { "test_status" };

//get todays date time(&t);

date = gmtime(&t);

//list all OIDs with todays date

res = hc_pstmt_create(session, "test_date = ?", &pstmt); res = hc_pstmt_set_date(pstmt, 1, date);

res = hc_pstmt_query_ez(pstmt, NULL, 0, 2000, &rset);

while (1) { hc_oid oid; int finished;

res = hc_qrs_next_ez(rset, &oid, NULL, &finished); if (finished)

break;

printf("todays oid: %s\n", oid);

}

res = hc_qrs_free(rset);

110

Sun StorageTek 5800 System Client API Reference Manual • June 2008

Page 110
Image 110
Sun Microsystems 5800 manual Querying With a Prepared Statement