When using column-wise binding, an application binds one, two, or in some cases three, vectors to each column for which data is to be returned. The first vector holds the data values and the second vector holds length/indicator buffers. Indicators and length values can be stored in separate buffers by setting the SQL_DESC_INDICATOR_PTR and SQL_DESC_OCTET_LENGTH_PTR descriptor fields to different values. If this is done, a third vector is bound. Each array contains as many elements as there are rows in the rowset.
The application declares that it is using column-wise binding with the SQL_ATTR_ROW_BIND_TYPE statement attribute, which determines the bind type for rowset buffers, as opposed to parameter set buffers. The driver returns the data for each row in successive entries of each vector. Figure 5.3 shows how column-wise binding works.
Figure 5.3. Column-wise binding

Example 5.5 shows how to perform a column-wise binding. We query the table Titles in the BookSales database to retrieve book title, year it was published, price, and the timestamp of the record (i.e. the date the record was entered in the database). Note that for this last item we use a special structure called TIMESTAMP_STRUCT, which is defined in module f90SQLStructures.
In the example, we define four vectors that contain the data (Title, Year, Price and EntryDate); four vectors that contain the length/indicator values (TitleLen, YearInd, PriceInd and EntryDateInd); a vector that contains a fetching status for each row in the rowset (RowStatusArray), and an integer variable that contains the number of rows in the rowset after each fetch statement (NumRowsFetched). This last variable is necessary because in some cases, although the rowset size is set to a given value, the real number of rows returned in the rowset can be smaller. One example is if we reached the end of a resultset. The size of these vectors is the size of the rowset we want to use (set to 10 in parameter RowsetSize). Note that after allocating a statement handle, we call subroutine f90SQLSetStmtAttr to specify:
Also note that when calling f90SQLBindCol, we do not pass the name of the vectors that will contain the data. Instead we pass their address (using the Fortran function loc()).
|