Bug #1430 mysql_bind_param/mysql_execute doesn't work (embedded)
Submitted: 29 Sep 2003 8:17 Modified: 1 Oct 2003 6:10
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S3 (Non-critical)
Version:4.1.1 OS:
Assigned to: Alexey Botchkov CPU Architecture:Any

[29 Sep 2003 8:17] Georg Richter
Description:
mysql_prepare/mysql_bind_param/mysql_execute doesn't work correctly. 
 
Looks like string and bind array start at offset 1 instead of 0 
 
Output: 
 
Paramcount: 2 
Col A: ar  Col B: óÿ¿õ` 
 

How to repeat:
#include <mysql.h> 
#include <stdio.h> 
 
 
int main() { 
	int		rc; 
	int i; 
	MYSQL 		*mysql; 
	MYSQL_BIND	bind[2];	 
	MYSQL_STMT	*stmt; 
	MYSQL_RES	*res; 
	MYSQL_ROW	row; 
	char		str1[100], str2[100]; 
	ulong		len[2]; 
	char		is_null[2]; 
 
	mysql_server_init(0, NULL, NULL); 
 
	mysql = mysql_init(NULL); 
	if (mysql_real_connect(mysql, NULL, NULL, NULL, "", 0, NULL, 0) == NULL) { 
		printf("error\n"); 
	} 
 
	mysql_query(mysql, "USE test"); 
 
	mysql_query(mysql, "CREATE TABLE bug_17 (a varchar(10), b varchar(10))"); 
 
	stmt = mysql_prepare(mysql, "INSERT INTO bug_17 VALUES (?,?)", 100); 
 
	printf ("Paramcount: %d\n", mysql_param_count(stmt)); 
 
	memset(&bind, '\0', sizeof(MYSQL_BIND) * 2); 
 
	bind[0].buffer_type=FIELD_TYPE_STRING; 
	bind[0].buffer= (char *)str1; 
	bind[0].buffer_length= 10;	 
	bind[1].buffer_type=FIELD_TYPE_STRING; 
	bind[1].buffer= (char *)str2; 
	bind[1].buffer_length= 10;	 
 
	for (i= 0; i < 2; i++) 
	{ 
		bind[i].length= &len[i]; 
		bind[i].is_null= &is_null[i]; 
		is_null[i]= 0; 
		len[i] = 3; 
	} 
 
	mysql_bind_param(stmt, bind); 
 
	strcpy(str1, "foo"); 
	strcpy(str2, "bar"); 
 
	mysql_execute(stmt); 
 
	mysql_stmt_close(stmt); 
 
	mysql_query(mysql, "SELECT a,b FROM bug_17"); 
	res = mysql_store_result(mysql); 
	row = mysql_fetch_row(res); 
	printf("Col A: %s  Col B: %s\n", row[0], row[1]); 
	mysql_free_result(res); 
 
	mysql_close(mysql); 
	mysql_server_end(); 
}
[1 Oct 2003 6:10] Alexey Botchkov
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

changeset 1.1602