Reading and Processing the Array Data

From InterBase

Go Up to Reading Data from an Array


To read and process the array or array slice data:

  1. Create a buffer for holding the array data to be read. Make it large enough to hold all the elements in the slice to be read (which could be the entire array). For example, the following declares an array buffer large enough to hold four long elements:
    long hcnt[4];
    
  2. Declare a short variable for specifying the size of the array buffer:
    short len;
    
  3. Set the variable to the buffer length:
    len = sizeof(hcnt);
    
  4. Read the array or array slice data into the buffer by calling ­isc_array_get_slice2(). Process the data read. In the following example, the array is read into the hcnt array buffer, and “processing” consists of printing the data:
    isc_array_get_slice2( status_vector,
    &db_handle, /* set by isc_attach_database()*/
    &trans, /* set by isc_start_transaction() */
    &array_id, /* array ID put into out_sqlda by isc_dsql_fetch()*/
    &desc, /* array descriptor specifying slice to be read */
    (void *) hcnt, /* buffer into which data will be read */
    (long *) &len); /* length of buffer */
    if (status_vector[0] == 1 && status_vector[1]) {
    isc_print_status(status_vector);
    return(1);
    }
    /* Make dept_no a null-terminated string */
    dept_no[out_sqlda->sqlvar[0].sqllen] = '\0';
    printf("Department #: %s\n\n", dept_no);
    printf("\tCurrent head counts: %ld %ld %ld %ld\n",
    hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
    

Advance To: