Commit 83fce55a authored by unknown's avatar unknown

A fix of return value of mysql_stmt_bind_result() and cleanup.


include/errmsg.h:
  New libmysql error status code CR_NO_STMT_METADATA
libmysql/errmsg.c:
  Error message for CR_STMT_NO_METADATA.
  Adding an empty line to shorten further diffs when new error
  messages are added (as suggested by Monty).
libmysql/libmysql.c:
  Return error from mysql_stmt_bind_result() if the statement contains
  no metadata.
  A few comments fixed.
tests/client_test.c:
  Tests fixed: mysql_stmt_bind_result now returns error if there is no
  metadata.
parent d9b62f82
...@@ -90,3 +90,4 @@ extern const char *client_errors[]; /* Error messages */ ...@@ -90,3 +90,4 @@ extern const char *client_errors[]; /* Error messages */
#define CR_SECURE_AUTH 2049 #define CR_SECURE_AUTH 2049
#define CR_FETCH_CANCELED 2050 #define CR_FETCH_CANCELED 2050
#define CR_NO_DATA 2051 #define CR_NO_DATA 2051
#define CR_NO_STMT_METADATA 2052
...@@ -78,7 +78,9 @@ const char *client_errors[]= ...@@ -78,7 +78,9 @@ const char *client_errors[]=
"Invalid connection handle", "Invalid connection handle",
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
"Row retrieval was canceled by mysql_stmt_close() call", "Row retrieval was canceled by mysql_stmt_close() call",
"Attempt to read column without prior row fetch" "Attempt to read column without prior row fetch",
"Prepared statement contains no metadata",
""
}; };
/* Start of code added by Roberto M. Serqueira - martinsc@uol.com.br - 05.24.2001 */ /* Start of code added by Roberto M. Serqueira - martinsc@uol.com.br - 05.24.2001 */
...@@ -137,7 +139,9 @@ const char *client_errors[]= ...@@ -137,7 +139,9 @@ const char *client_errors[]=
"Invalid connection handle", "Invalid connection handle",
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
"Row retrieval was canceled by mysql_stmt_close() call", "Row retrieval was canceled by mysql_stmt_close() call",
"Attempt to read column without prior row fetch" "Attempt to read column without prior row fetch",
"Prepared statement contains no metadata",
""
}; };
#else /* ENGLISH */ #else /* ENGLISH */
...@@ -194,7 +198,9 @@ const char *client_errors[]= ...@@ -194,7 +198,9 @@ const char *client_errors[]=
"Invalid connection handle", "Invalid connection handle",
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
"Row retrieval was canceled by mysql_stmt_close() call", "Row retrieval was canceled by mysql_stmt_close() call",
"Attempt to read column without prior row fetch" "Attempt to read column without prior row fetch",
"Prepared statement contains no metadata",
""
}; };
#endif #endif
......
...@@ -2139,12 +2139,12 @@ static void update_stmt_fields(MYSQL_STMT *stmt) ...@@ -2139,12 +2139,12 @@ static void update_stmt_fields(MYSQL_STMT *stmt)
DESCRIPTION DESCRIPTION
This function should be used after mysql_stmt_execute(). This function should be used after mysql_stmt_execute().
You can safely check that prepared statement has a result set by calling You can safely check that prepared statement has a result set by calling
mysql_stmt_num_fields(): if number of fields is not zero, you can call mysql_stmt_field_count(): if number of fields is not zero, you can call
this function to get fields metadata. this function to get fields metadata.
Next steps you may want to make: Next steps you may want to make:
- find out number of columns in result set by calling - find out number of columns in result set by calling
mysql_num_fields(res) (the same value is returned by mysql_num_fields(res) (the same value is returned by
mysql_stmt_num_fields) mysql_stmt_field_count())
- fetch metadata for any column with mysql_fetch_field, - fetch metadata for any column with mysql_fetch_field,
mysql_fetch_field_direct, mysql_fetch_fields, mysql_field_seek. mysql_fetch_field_direct, mysql_fetch_fields, mysql_field_seek.
- free returned MYSQL_RES structure with mysql_free_result. - free returned MYSQL_RES structure with mysql_free_result.
...@@ -3882,11 +3882,10 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -3882,11 +3882,10 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
if (!bind_count) if (!bind_count)
{ {
if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE) int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ?
{ CR_NO_PREPARE_STMT : CR_NO_STMT_METADATA;
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate); set_stmt_error(stmt, errorcode, unknown_sqlstate);
} DBUG_RETURN(1);
DBUG_RETURN(0);
} }
/* /*
...@@ -4278,7 +4277,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data) ...@@ -4278,7 +4277,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
row+= (stmt->field_count+9)/8; /* skip null bits */ row+= (stmt->field_count+9)/8; /* skip null bits */
bit= 4; /* first 2 bits are reserved */ bit= 4; /* first 2 bits are reserved */
/* Go throw all fields and calculate metadata */ /* Go through all fields and calculate metadata */
for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields ; for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields ;
bind < end ; bind < end ;
bind++, field++) bind++, field++)
......
...@@ -5636,9 +5636,6 @@ static void test_subselect() ...@@ -5636,9 +5636,6 @@ static void test_subselect()
rc= mysql_stmt_bind_param(stmt, bind); rc= mysql_stmt_bind_param(stmt, bind);
check_execute(stmt, rc); check_execute(stmt, rc);
rc= mysql_stmt_bind_result(stmt, bind);
check_execute(stmt, rc);
id= 2; id= 2;
rc= mysql_stmt_execute(stmt); rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc); check_execute(stmt, rc);
...@@ -5982,7 +5979,7 @@ static void test_pure_coverage() ...@@ -5982,7 +5979,7 @@ static void test_pure_coverage()
check_execute(stmt, rc); check_execute(stmt, rc);
rc= mysql_stmt_bind_result(stmt, (MYSQL_BIND*)0); rc= mysql_stmt_bind_result(stmt, (MYSQL_BIND*)0);
check_execute(stmt, rc); DIE_UNLESS(rc == 1);
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment