Index: driver/execute.c =================================================================== --- driver/execute.c (revision 1033) +++ driver/execute.c (working copy) @@ -417,6 +417,7 @@ break; } } + switch ( param->SqlType ) { case SQL_DATE: @@ -425,7 +426,7 @@ case SQL_TIMESTAMP: if ( data[0] == '{' ) /* Of type {d date } */ return add_to_buffer(net,to,data,length); - /* else threat as a string */ + /* else treat as a string */ case SQL_CHAR: case SQL_VARCHAR: case SQL_LONGVARCHAR: @@ -435,15 +436,8 @@ case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: - { - to= add_to_buffer(net,to,"'",1); - /* Make sure we have room for a fully-escaped string. */ - if (!(to= extend_buffer(net, to, length * 2))) - return 0; - to+= mysql_real_escape_string(&dbc->mysql, to, data, length); - to= add_to_buffer(net, to, "'", 1); - return to; - } + break; + case SQL_TIME: case SQL_TYPE_TIME: if ( param->CType == SQL_C_TIMESTAMP || @@ -485,11 +479,23 @@ if ( to == buff ) *to++='0'; /* Fix for empty strings */ data= buff; length= (uint) (to-buff); + + convert= 0; + } /* Fall through */ default: + if (!convert) return add_to_buffer(net,to,data,length); } + + to= add_to_buffer(net,to,"'",1); + /* Make sure we have room for a fully-escaped string. */ + if (!(to= extend_buffer(net, to, length * 2))) + return 0; + to+= mysql_real_escape_string(&dbc->mysql, to, data, length); + to= add_to_buffer(net, to, "'", 1); + return to; } Index: driver/cursor.c =================================================================== --- driver/cursor.c (revision 1033) +++ driver/cursor.c (working copy) @@ -424,13 +424,7 @@ /* We have to remove zero bytes or we have problems! */ while ( (*to > orig_to) && (*((*to) - 1) == (SQLCHAR) 0) ) (*to)--; - /* insert "," */ - param.SqlType= SQL_INTEGER; - param.CType= SQL_C_CHAR; - param.buffer= ","; - *param.actual_len= 1; - - if ( !(*to= (SQLCHAR*) insert_param(stmt->dbc,(char*) *to, ¶m)) ) + if (!(*to= (SQLCHAR *)add_to_buffer(*net, (char *)*to, ",", 1))) return set_error(stmt,MYERR_S1001,NULL,4001); return(SQL_SUCCESS); @@ -469,8 +463,6 @@ static SQLRETURN copy_field_data(STMT FAR *stmt, PARAM_BIND *param, NET **net, SQLCHAR **to) { - PARAM_BIND dummy; - SQLLEN dummy_len= 5; /* sizeof(" AND ") */ SQLUINTEGER length= *(param->actual_len)+5; if ( !(*to= (SQLCHAR*) extend_buffer(*net, (char*) *to,length)) ) @@ -480,12 +472,7 @@ return set_error(stmt,MYERR_S1001,NULL,4001); /* Insert " AND ", where clause with multiple search */ - dummy.SqlType= SQL_INTEGER; - dummy.CType= SQL_C_CHAR; - dummy.buffer= " AND "; - dummy.actual_len= &dummy_len; - - if ( !(*to= (SQLCHAR*) insert_param(stmt->dbc, (char*) *to, &dummy)) ) + if (!(*to= (SQLCHAR *)add_to_buffer(*net, (char *)*to, " AND ", 5))) return set_error(stmt,MYERR_S1001,NULL,4001); return SQL_SUCCESS; Index: test/my_result.c =================================================================== --- test/my_result.c (revision 1033) +++ test/my_result.c (working copy) @@ -2003,6 +2003,36 @@ } +/** + Bug #34575: SQL_C_CHAR value type and numeric parameter type causes trouble +*/ +DECLARE_TEST(t_bug34575) +{ + SQLCHAR buff[10]; + SQLLEN len= 0; + SQLSMALLINT namelen, type, digits, nullable; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug34575"); + ok_sql(hstmt, "CREATE TABLE t_bug34575 (a DECIMAL)"); + ok_sql(hstmt, "INSERT INTO t_bug34575 VALUES (1.0),(2.0),(3.0)"); + + ok_stmt(hstmt, SQLPrepare(hstmt, (SQLCHAR *) + "SELECT a FROM t_bug34575 WHERE a = ?", SQL_NTS)); + strcpy((char *)buff, "2.0"); + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, + SQL_DECIMAL, 10, 0, buff, sizeof(buff), + &len)); + + ok_stmt(hstmt, SQLDescribeCol(hstmt, 1, buff, sizeof(buff), &namelen, + &type, &len, &digits, &nullable)); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug34575"); + return OK; +} + + BEGIN_TESTS ADD_TEST(my_resultset) ADD_TEST(t_convert_type) @@ -2030,6 +2060,7 @@ ADD_TEST(t_bug31246) ADD_TEST(t_bug13776) ADD_TEST(t_bug13776_auto) + ADD_TEST(t_bug34575) END_TESTS Index: ChangeLog =================================================================== --- ChangeLog (revision 1034) +++ ChangeLog (working copy) @@ -6,6 +6,8 @@ * ConfigDSN() returned FALSE when the dialog was cancelled by the user. * Static cursor was unable to be used through ADO when dynamic cursors were enabled. (Bug #27351) + * Values bound using the SQL_C_CHAR value type but with numeric + parameter type were not correctly escaped. (Bug #34575) ----