Bug #2812 wrong value for stmt->field_count
Submitted: 15 Feb 2004 12:18 Modified: 25 Sep 2007 11:14
Reporter: Georg Richter Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S3 (Non-critical)
Version:5.x OS:Linux (Linux/Windows)
Assigned to: CPU Architecture:Any

[15 Feb 2004 12:18] Georg Richter
Description:
When executing SHOW VARIABLES in a prepeared statement stmt->field_count is 0 instead of 2.

How to repeat:
#include <mysql.h>
#include <stdio.h>

void main() {
	MYSQL		*mysql;
	MYSQL_STMT	*stmt;
	char		query[512];

	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

	strcpy(query, "SELECT 1,2");
	stmt = mysql_prepare(mysql, query, strlen(query));

	/* stmt->field_count should be 2 */
	printf("Fields: %d\n", stmt->field_count);

	mysql_stmt_close(stmt);

	strcpy(query, "SHOW VARIABLES");
	stmt = mysql_prepare(mysql, query, strlen(query));

	/* stmt->field_count should be 2, but is 0 */
	printf("Fields: %d\n", stmt->field_count);

	mysql_stmt_close(stmt);

	mysql_close(mysql);
}
[17 Feb 2004 20:23] MySQL Verification Team
Tested against a server from BK tree 2 days older:

C:\Temp>myTest.exe
Fields: 0
Fields: 0
[18 Mar 2004 3:57] Konstantin Osipov
The reason of this bug is that we don't send types of columns in result set for SHOW and EXPLAIN commands.
However you should not use stmt members directly to obtain metadata information.
Statement is a black box and all work should be performed through API calls.
[18 Mar 2004 5:01] Alexey Botchkov
To solve this properly we should:
1. Separate parts of the mysql_show_***() forming field's lists.
2. Call these in send_prepare_results()
3. Since we are going to modify all the show's it worth to make
     them handling 'WHERE'.

<hf> monty, serg: I checked 2812. This one would be an decent WL item. We need to completely change the way we handle 'SHOW' commands. And it's close to the WL#173, and 'WHERE for SHOW' task. I'd propose put this bug to 'deferred' and fix along with that tasks.
<monty> hf: ok
[22 Mar 2004 10:22] Konstantin Osipov
Alexey, I just want to easily track all existing bugs in prepared statements.
[8 Aug 2007 11:39] Konstantin Osipov
Bug #29901 result of prepared statement changes between 2 executions was tagged a duplicate of this bug.
[28 Aug 9:08] henry wang
在选择作业代写 https://www.12y.org/ 服务时,学生们需要确保选择的是一家信誉良好的服务提供商。信誉好的作业代写服务通常会有一支专业的写作团队,严格遵守学术诚信,提供完全原创的作业。此外,这些服务还会注重与客户的沟通,确保每一份作业都能按照客户的具体要求进行修改和完善。通过选择合适的作业代写服务,学生可以放心地委托他们的学术任务,从而获得优异的成绩。