Skip to content

Commit 9145744

Browse files
A fix of return value of mysql_stmt_bind_result() and cleanup.
1 parent a2a3d82 commit 9145744

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

include/errmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ extern const char *client_errors[]; /* Error messages */
9090
#define CR_SECURE_AUTH 2049
9191
#define CR_FETCH_CANCELED 2050
9292
#define CR_NO_DATA 2051
93+
#define CR_NO_STMT_METADATA 2052

libmysql/errmsg.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ const char *client_errors[]=
7878
"Invalid connection handle",
7979
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
8080
"Row retrieval was canceled by mysql_stmt_close() call",
81-
"Attempt to read column without prior row fetch"
81+
"Attempt to read column without prior row fetch",
82+
"Prepared statement contains no metadata",
83+
""
8284
};
8385

8486
/* Start of code added by Roberto M. Serqueira - [email protected] - 05.24.2001 */
@@ -137,7 +139,9 @@ const char *client_errors[]=
137139
"Invalid connection handle",
138140
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
139141
"Row retrieval was canceled by mysql_stmt_close() call",
140-
"Attempt to read column without prior row fetch"
142+
"Attempt to read column without prior row fetch",
143+
"Prepared statement contains no metadata",
144+
""
141145
};
142146

143147
#else /* ENGLISH */
@@ -194,7 +198,9 @@ const char *client_errors[]=
194198
"Invalid connection handle",
195199
"Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
196200
"Row retrieval was canceled by mysql_stmt_close() call",
197-
"Attempt to read column without prior row fetch"
201+
"Attempt to read column without prior row fetch",
202+
"Prepared statement contains no metadata",
203+
""
198204
};
199205
#endif
200206

libmysql/libmysql.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,12 +2139,12 @@ static void update_stmt_fields(MYSQL_STMT *stmt)
21392139
DESCRIPTION
21402140
This function should be used after mysql_stmt_execute().
21412141
You can safely check that prepared statement has a result set by calling
2142-
mysql_stmt_num_fields(): if number of fields is not zero, you can call
2142+
mysql_stmt_field_count(): if number of fields is not zero, you can call
21432143
this function to get fields metadata.
21442144
Next steps you may want to make:
21452145
- find out number of columns in result set by calling
21462146
mysql_num_fields(res) (the same value is returned by
2147-
mysql_stmt_num_fields)
2147+
mysql_stmt_field_count())
21482148
- fetch metadata for any column with mysql_fetch_field,
21492149
mysql_fetch_field_direct, mysql_fetch_fields, mysql_field_seek.
21502150
- 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)
38823882

38833883
if (!bind_count)
38843884
{
3885-
if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE)
3886-
{
3887-
set_stmt_error(stmt, CR_NO_PREPARE_STMT, unknown_sqlstate);
3888-
}
3889-
DBUG_RETURN(0);
3885+
int errorcode= (int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE ?
3886+
CR_NO_PREPARE_STMT : CR_NO_STMT_METADATA;
3887+
set_stmt_error(stmt, errorcode, unknown_sqlstate);
3888+
DBUG_RETURN(1);
38903889
}
38913890

38923891
/*
@@ -4278,7 +4277,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data)
42784277
row+= (stmt->field_count+9)/8; /* skip null bits */
42794278
bit= 4; /* first 2 bits are reserved */
42804279

4281-
/* Go throw all fields and calculate metadata */
4280+
/* Go through all fields and calculate metadata */
42824281
for (bind= stmt->bind, end= bind + stmt->field_count, field= stmt->fields ;
42834282
bind < end ;
42844283
bind++, field++)

tests/client_test.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,9 +5636,6 @@ static void test_subselect()
56365636
rc= mysql_stmt_bind_param(stmt, bind);
56375637
check_execute(stmt, rc);
56385638

5639-
rc= mysql_stmt_bind_result(stmt, bind);
5640-
check_execute(stmt, rc);
5641-
56425639
id= 2;
56435640
rc= mysql_stmt_execute(stmt);
56445641
check_execute(stmt, rc);
@@ -5982,7 +5979,7 @@ static void test_pure_coverage()
59825979
check_execute(stmt, rc);
59835980

59845981
rc= mysql_stmt_bind_result(stmt, (MYSQL_BIND*)0);
5985-
check_execute(stmt, rc);
5982+
DIE_UNLESS(rc == 1);
59865983

59875984
mysql_stmt_close(stmt);
59885985

0 commit comments

Comments
 (0)