Fetching a Row of Data
Exactly how SQLFetch is implemented is driver-specific, but the general pattern is for the driver
to retrieve the data for any bound columns from the data source, convert it
according to the types of the bound variables, and place the converted data in
those variables. If the driver cannot convert any data, SQLFetch returns an error. The application can continue fetching rows, but the data
for the current row is lost. What happens to the data for unbound columns depends
on the driver, but most drivers either retrieve and discard it or never
retrieve it at all.
The driver also sets the values of any length/indicator buffers that have been
bound. If the data value for a column is NULL, the driver sets the
corresponding length/indicator buffer to SQL_NULL_DATA. If the data value is not NULL, the
driver sets the length/indicator buffer to the byte length of the data after
conversion. If this length cannot be determined, as is sometimes the case with
long data that is retrieved by more than one function call, the driver sets the
length/indicator buffer to SQL_NO_TOTAL. Note that for fixed-length data types,
such as integers and date structures, the byte length is the size of the data
type.
For variable-length data, such as character and binary data, the driver checks
the byte length of the converted data against the byte length of the buffer
bound to the column; the buffer
Fixed-length data is never truncated, as the driver assumes that the size of
the bound buffer is the size of the data type. Data truncation tends to be rare,
as the application usually binds a buffer large enough to hold the entire data
value; it determines the necessary size from the metadata. However, the
application might explicitly bind a buffer it knows to be too small. For example, it
might retrieve and display the first 20 characters of a part description or the
first 100 characters of a long text column.
Character data must be null-terminated by the driver before it is returned to
the application, even if it has been truncated. The null-termination character
is not included in the returned byte length, but does require space in the
bound buffer. For example, suppose an application uses strings composed of
character data in the ASCII character set, a driver has 50 characters of data to
return, and the application
The application can restrict the number of rows in the result set by setting
the SQL_ATTR_MAX_ROWS statement attribute before executing the statement that
creates the result set. For example, the preview mode in an application used to
format reports only needs enough data to display the first page of the report.
By restricting the size of the result set, such a feature would run faster. This
statement attribute is intended to reduce network traffic and might not be
supported by all drivers.