WL#3191: Prepared Statements: implement C API functions mysql_stmt_get_data(), mysql_stmt_get_column_length()

Affects: Server-7.1   —   Status: Un-Assigned   —   Priority: Medium

Implement a MySQL C API counterpart of ODBC and SQL/CLI function SQLGetData.
Right now it's not possible to find out the length of a column without calling
mysql_stmt_fetch(), which in turn requires mysql_stmt_bind_result() to be done.
In order to avoid that, we should implement two additional convenience calls:
mysql_stmt_get_data(), mysql_stmt_get_column_length().
mysql_stmt_get_data() returns a pointer to the internally allocated buffer for
the column and the length of the buffer. With this method, it won't be necessary
to issue extra mysql_stmt_fetch() calls in order to get the length.
ODBC documentation specifies:

SQLGetData Function

    Version Introduced: ODBC 1.0
    Standards Compliance: ISO 92
    SQLGetData retrieves data for a single column in the result set. It can be
called multiple times to retrieve variable-length data in parts.


     SQLHSTMT     StatementHandle,
     SQLUSMALLINT     ColumnNumber,
     SQLSMALLINT     TargetType,
     SQLPOINTER     TargetValuePtr,
     SQLINTEGER     BufferLength,
     SQLINTEGER *     StrLen_or_IndPtr);
The full description can be found at:


The proposed signature for MySQL C API is

 int mysql_stmt_get_data(MYSQL_STMT *stmt /* in */, ulong column_no /* in */,
void **data /* out */, ulong *data_length /* out */);

This function returns a pointer to the internally allocated buffer that contains
the column. The format of the buffer is the same as if it was bound to the
to the most suitable host language type buffer, in other words:
 - a pointer to an char, unsigned char, short, unsigned short, int, unsigned int,
   long, unsigned long, long long, unsigned long long for MYSQL_TYPE_INT,
 - a pointer to a buffer that contains the string in character_set_client
  for textual columns and in the binary character set for blobs.
 - a pointer to MYSQL_DATA for date/time/datetime columns

Side effects:
 - mysql_stmt_get_data cancels the effect of mysql_stmt_bind_result if it
   was made.

Return value:
  - 0 - success
  - column is out of range
  - the statement handle is invalid
  - there is no result set associated with the statement

Additional call is necessary: mysql_stmt_get_column_length, which returns
the length of the column.


 int mysql_stmt_get_column_length(MYSQL_STMT *stmt /* in */, ulong column_no,
ulong *length /* out */);

Return values:
 - 0 - success
 - the statement handle is invalid