Bug #74598 bind parameter with multi_statement option
Submitted: 28 Oct 2014 4:00 Modified: 23 Dec 2015 12:14
Reporter: helllo ke Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.1.13 OS:Linux (redhat6 64bit)
Assigned to: CPU Architecture:Any
Tags: bind parameter multi_statement

[28 Oct 2014 4:00] helllo ke
Description:
i want to execute multiple statements in one sql strint, so i add OPTION=67108864 when i connenct mysql server, and in my insert sql string ,i use SQLBindParameter bind 3 rows, but when the sql execute, it only insert 1 row.

How to repeat:
mysql version:5.5.21
code:

#include <sql.h> 
#include <sqltypes.h> 
#include <sqlext.h>
#include <stdlib.h>
#include <stdio.h>

typedef struct test test_t;
struct test
{
	int		i;
	int		j;
	SQLINTEGER		len1;
	SQLINTEGER		len2;
};

int main()
{
	char*		conn_str= "SERVER=127.0.0.1;DRIVER={MySQL ODBC 5.1 Driver};PORT=3306;DATABASE=test;USER=utest;PASSWORD=qwe123;OPTION=67108864";

	HENV		hevn;
	HDBC		hdbc;
	SQLRETURN	rc = SQL_SUCCESS;
	char		out_conn_str[1024];
	SQLSMALLINT	out_len;
	HSTMT		hstmt;
	test_t		data[3];
	int			len1[3];
	int			len2[3];
	int			i;
	
	SQLCHAR*		sql = (SQLCHAR*)"insert into test values(?,?);commit;";
	SQLLEN		rowcount = 0;

	data[0].i = 1;
	data[0].j = 1;
	data[1].i = 2;
	data[1].j = 2;
	data[2].i = 3;
	data[2].j = 3;

	for (i = 0 ; i < 3; i++)
	{
		data[i].len1 = 4;
		data[i].len2 = 4;
	}
	SQLAllocHandle(SQL_HANDLE_ENV, NULL, &hevn);
	SQLSetEnvAttr(hevn, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
	SQLAllocHandle(SQL_HANDLE_DBC, hevn, &hdbc);	

	rc |= SQLDriverConnect(hdbc, NULL, (SQLCHAR*)conn_str, strlen(conn_str),  (SQLCHAR*)out_conn_str,
		sizeof(out_conn_str), &out_len, SQL_DRIVER_NOPROMPT);
	if (rc != SQL_SUCCESS)
	{
		sql_get_error_info(SQL_HANDLE_DBC, hdbc, rc, __LINE__, __FILE__);
		printf("error\n");
		return -1;
	}
	rc |= SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0);
	if (rc != SQL_SUCCESS)
	{
		sql_get_error_info(SQL_HANDLE_DBC, hdbc, rc, __LINE__, __FILE__);
		printf("error\n");
		return -1;
	}
	SQLAllocHandle(SQL_HANDLE_STMT, hdbc,  &hstmt);

	rc |= SQLSetStmtAttr(hstmt,  SQL_ATTR_PARAM_BIND_TYPE, (SQLPOINTER)sizeof(test_t), 0);
	rc |= SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SHORT, SQL_INTEGER, 0, 0, &data[0].i, 0, &data[0].len1);
	rc |= SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SHORT, SQL_INTEGER, 0, 0, &data[0].j, 0, &data[0].len2);

	rc |= SQLSetStmtAttr(hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)3, 0);
	rc |= SQLPrepare(hstmt, sql, strlen(sql));
	if (rc != SQL_SUCCESS)
	{
		printf("error\n");
		return -1;
	}
	rc |= SQLExecute(hstmt);
	rc |= SQLRowCount(hstmt, &rowcount);
	printf("%d\n", rowcount);
	
	SQLFreeStmt(hstmt, SQL_CLOSE);
	SQLFreeConnect(hdbc);
	SQLFreeEnv(hevn);
	return 0;
}
[30 Sep 2015 9:50] S ZHANG
It works in my code, the DSN settings are as following.

Driver=/usr/lib/libmyodbc5w.so
Description=MySQL ODBC 5.x Driver
SERVER=
PORT=
USER=
Password=
DATABASE=
OPTION=2
SOCKET=
DriverUnicodeType=1
[23 Dec 2015 12:14] Chiranjeevi Battula
Hello helllo ke,

Thank you for the bug report.
I tried to reproduce the issue at my end using  MySQL Connector/ODBC 5.3.4 but couldn't trace out any issue in multiple statements in one sql statement.

Thanks,
Chiranjeevi.