Sun StorageTek 5800 System Client API Reference Manual

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 today’s date
     time(&t);
     date = gmtime(&t);

     // list all OIDs with today’s 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("today’s oid: %s\n", oid);
     }
     res = hc_qrs_free(rset);

     // list all OIDs from yesterday with test_status
     t = 86400; // 86400 sec/day
     date = gmtime(&t);

     res = hc_pstmt_set_date(pstmt, 1, date);
     res = hc_pstmt_query_ez(pstmt, selects, 1, 2000, &rset);

     while (1) {
         hc_oid oid;
         hc_nvr_t *nvr         int finished;
         hc_string_t test_status;

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

         res = hc_nvr_get_string(nvr, "test_status", &test_status);
         printf("yesterday’s oid & test_status: %s %s\n", oid, test_status);
         hc_nvr_free(nvr);
     }
     res = hc_qrs_free(rset);

Deleting Records

The following function is defined to delete records: hc_delete_ez.

hc_delete_ez

Deletes the metadata record for specified OID.

Synopsis

     hcerr_t hc_delete_ez(hc_session_t *session,
          hc_oid *oid);

Description

This function deletes the metadata record for the specified OID. When the last metadata record associated with a data object is deleted, the underlying data object is also deleted.

Parameters

session

IN: Pointer to the session.

oid

IN: The specified OID.

Return Codes

     HCERR_OK
     HCERR_BAD_REQUEST
     HCERR_OOM
     HCERR_NULL_SESSION
     HCERR_INVALID_SESSION
     HCERR_INVALID_OID

Translating Error and Type Codes

The following functions are defined for translating error codes and type codes into strings:

hc_decode_hcerr

Translates an error code into a string.

Synopsis

     char *hc_decode_hcerr(hcerr_t res);

Description

Translates an error code into a string.

Parameter

res

IN: The error code returned by a function.

hc_decode_hc_type

Translates a type code into a string.

Synopsis

     char *hc_decode_hc_type(hc_type_t type);

Description

Translates a type code into a string.

Parameters

type

IN: The type code to translate.