Bug #12002 mysql_stmt_fetch() returns wrong data from query from view
Submitted: 18 Jul 2005 9:37 Modified: 5 Aug 2005 14:21
Reporter: Sergey Nikitin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.9/5.0.10 OS:Windows (Windows XP/Linux)
Assigned to: MySQL Verification Team CPU Architecture:Any

[18 Jul 2005 9:37] Sergey Nikitin
Description:
I have to duplicate last message from report #11683 since i have no reply to it

mysql_stmt_fetch() returns wrong data from query from view in some cases

How to repeat:
-Create tables, views and insert data with attached test.sql

Check query result
mysql> SELECT BANRD, ADKAT, STR FROM V_ADR_FULL ORDER BY UPPER(FNAME), L_ORD;
+-------+-------+----------+
| BANRD | ADKAT | STR      |
+-------+-------+----------+
|     1 |     4 | P.O. Box |
|     2 |     4 | B        |
+-------+-------+----------+
2 rows in set (0.00 sec)

- Check code result
//...
MYSQL session;
mysql_init(&session);
mysql_real_connect(&session, "dbserver", "root", "123456",
"test",MYSQL_PORT, NULL, 0);
MYSQL_STMT* stmt = mysql_stmt_init(&session);
const char* pszQuery = "SELECT BANRD, ADKAT, STR FROM V_ADR_FULL ORDER BY
UPPER(FNAME), L_ORD";
mysql_stmt_prepare(stmt, pszQuery, strlen(pszQuery));
int nBANRD, nADKAT;
char sStr[31];
MYSQL_BIND binds[3];
memset(binds, 0, sizeof binds);
binds[0].buffer_type = MYSQL_TYPE_LONG;
binds[0].buffer = &nBANRD;
binds[0].buffer_length = sizeof nBANRD;
binds[1].buffer_type = MYSQL_TYPE_LONG;
binds[1].buffer = &nADKAT;
binds[1].buffer_length = sizeof nADKAT;
binds[2].buffer_type = MYSQL_TYPE_STRING;
binds[2].buffer = sStr;
binds[2].buffer_length = sizeof sStr;
mysql_stmt_bind_result(stmt, binds);
mysql_stmt_execute(stmt);
mysql_stmt_fetch(stmt); 

/*Results:

nBANRD 1
nADKAT 0
sStr ""
*/
[18 Jul 2005 9:38] Sergey Nikitin
test case

Attachment: test.sql (application/octet-stream, text), 4.41 KiB.

[18 Jul 2005 15:14] MySQL Verification Team
On Windows:

C:\temp>bug12002
Connected to Server: 5.0.10-beta-nt
nBANRD: 2
nADKAT 0
sStr

On Linux:

miguel@hegel:~/dbs/5.0> ./bug12002
Connected to Server: 5.0.10-beta-debug
nBANRD: 0
nADKAT 0
sStr ôo@tñÿ¿É*
[5 Aug 2005 10:18] Andrey Hristov
Miguel, could you try again to verify? I cannot repeat this one with 5.0.12-beta of today.
[5 Aug 2005 14:21] MySQL Verification Team
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Tested with 5.0.12 BK source.