Commit 7055fc51 authored by konstantin@mysql.com's avatar konstantin@mysql.com

Truncations patch: a post-review fix.

parent 0d831520
...@@ -145,7 +145,8 @@ enum mysql_option ...@@ -145,7 +145,8 @@ enum mysql_option
MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION
}; };
struct st_mysql_options { struct st_mysql_options {
...@@ -186,6 +187,8 @@ struct st_mysql_options { ...@@ -186,6 +187,8 @@ struct st_mysql_options {
char *client_ip; char *client_ip;
/* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */ /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
my_bool secure_auth; my_bool secure_auth;
/* 0 - never report, 1 - always report (default) */
my_bool report_data_truncation;
/* function pointers for local infile support */ /* function pointers for local infile support */
int (*local_infile_init)(void **, const char *, void *); int (*local_infile_init)(void **, const char *, void *);
......
...@@ -4342,7 +4342,6 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4342,7 +4342,6 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
MYSQL_FIELD *field; MYSQL_FIELD *field;
ulong bind_count= stmt->field_count; ulong bind_count= stmt->field_count;
uint param_count= 0; uint param_count= 0;
uchar report_data_truncation= 0;
DBUG_ENTER("mysql_stmt_bind_result"); DBUG_ENTER("mysql_stmt_bind_result");
DBUG_PRINT("enter",("field_count: %d", bind_count)); DBUG_PRINT("enter",("field_count: %d", bind_count));
...@@ -4380,8 +4379,6 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4380,8 +4379,6 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
if (!param->error) if (!param->error)
param->error= &param->error_value; param->error= &param->error_value;
else
report_data_truncation= REPORT_DATA_TRUNCATION;
param->param_number= param_count++; param->param_number= param_count++;
param->offset= 0; param->offset= 0;
...@@ -4395,7 +4392,10 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4395,7 +4392,10 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
stmt->bind_result_done= BIND_RESULT_DONE | report_data_truncation; stmt->bind_result_done= BIND_RESULT_DONE;
if (stmt->mysql->options.report_data_truncation)
stmt->bind_result_done|= REPORT_DATA_TRUNCATION;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -874,6 +874,7 @@ static const char *default_options[]= ...@@ -874,6 +874,7 @@ static const char *default_options[]=
"replication-probe", "enable-reads-from-master", "repl-parse-query", "replication-probe", "enable-reads-from-master", "repl-parse-query",
"ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name",
"multi-results", "multi-queries", "secure-auth", "multi-results", "multi-queries", "secure-auth",
"report-data-truncation",
NullS NullS
}; };
...@@ -1084,6 +1085,9 @@ void mysql_read_default_options(struct st_mysql_options *options, ...@@ -1084,6 +1085,9 @@ void mysql_read_default_options(struct st_mysql_options *options,
case 32: /* secure-auth */ case 32: /* secure-auth */
options->secure_auth= TRUE; options->secure_auth= TRUE;
break; break;
case 33: /* report-data-truncation */
options->report_data_truncation= opt_arg ? test(atoi(opt_arg)) : 1;
break;
default: default:
DBUG_PRINT("warning",("unknown option: %s",option[0])); DBUG_PRINT("warning",("unknown option: %s",option[0]));
} }
...@@ -1427,6 +1431,7 @@ mysql_init(MYSQL *mysql) ...@@ -1427,6 +1431,7 @@ mysql_init(MYSQL *mysql)
#endif #endif
mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION; mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION;
mysql->options.report_data_truncation= TRUE; /* default */
return mysql; return mysql;
} }
...@@ -2666,6 +2671,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) ...@@ -2666,6 +2671,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg)
case MYSQL_SECURE_AUTH: case MYSQL_SECURE_AUTH:
mysql->options.secure_auth= *(my_bool *) arg; mysql->options.secure_auth= *(my_bool *) arg;
break; break;
case MYSQL_REPORT_DATA_TRUNCATION:
mysql->options.report_data_truncation= test(*(my_bool *) arg);
break;
default: default:
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
...@@ -12302,6 +12302,56 @@ static void test_truncation() ...@@ -12302,6 +12302,56 @@ static void test_truncation()
myquery(rc); myquery(rc);
} }
static void test_truncation_option()
{
MYSQL_STMT *stmt;
const char *stmt_text;
int rc;
uint8 buf;
my_bool option= 0;
my_bool error;
MYSQL_BIND bind;
myheader("test_truncation_option");
/* Prepare the test table */
stmt_text= "select -1";
stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
check_execute(stmt, rc);
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
bzero(&bind, sizeof(MYSQL_BIND));
bind.buffer= (void*) &buf;
bind.buffer_type= MYSQL_TYPE_TINY;
bind.is_unsigned= TRUE;
bind.error= &error;
rc= mysql_stmt_bind_result(stmt, &bind);
check_execute(stmt, rc);
rc= mysql_stmt_fetch(stmt);
DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
DIE_UNLESS(error);
rc= mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (char*) &option);
myquery(rc);
/* need to rebind for the new setting to take effect */
rc= mysql_stmt_bind_result(stmt, &bind);
check_execute(stmt, rc);
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
rc= mysql_stmt_fetch(stmt);
check_execute(stmt, rc);
/* The only change is rc - error pointers are still filled in */
DIE_UNLESS(error == 1);
/* restore back the defaults */
option= 1;
mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (char*) &option);
mysql_stmt_close(stmt);
}
/* /*
Read and parse arguments and MySQL options from my.cnf Read and parse arguments and MySQL options from my.cnf
...@@ -12517,6 +12567,7 @@ static struct my_tests_st my_tests[]= { ...@@ -12517,6 +12567,7 @@ static struct my_tests_st my_tests[]= {
{ "test_basic_cursors", test_basic_cursors }, { "test_basic_cursors", test_basic_cursors },
{ "test_cursors_with_union", test_cursors_with_union }, { "test_cursors_with_union", test_cursors_with_union },
{ "test_truncation", test_truncation }, { "test_truncation", test_truncation },
{ "test_truncation_option", test_truncation_option },
{ 0, 0 } { 0, 0 }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment