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 Conformance Version Introduced: ODBC 1.0 Standards Compliance: ISO 92 Summary SQLGetData retrieves data for a single column in the result set. It can be called multiple times to retrieve variable-length data in parts. Syntax SQLRETURN SQLGetData( SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValuePtr, SQLINTEGER BufferLength, SQLINTEGER * StrLen_or_IndPtr); The full description can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlgetdata.asp 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, MYSQL_TYPE_MEDIUMINT, MYSQL_TYPE_SHORT and similar columns - 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 Error: - 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. Signature: int mysql_stmt_get_column_length(MYSQL_STMT *stmt /* in */, ulong column_no, ulong *length /* out */); Return values: - 0 - success Error: - the statement handle is invalid
Copyright (c) 2000, 2016, Oracle Corporation and/or its affiliates. All rights reserved.