diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-10-30 20:47:39 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-10-30 20:47:39 +0400 |
commit | 835cbbcc7b797188a89671019f2b2844e1a14e0c (patch) | |
tree | 010dd112f16b88bb655c32abb6b93987fe5c6c99 /sql/sql_prepare.cc | |
parent | fe8cf8fdf1c4c0a9ec60690a8d2738fd255c8dd5 (diff) | |
parent | 003cb2f42477772ae43228c0bc0f8492246b9340 (diff) | |
download | mariadb-git-835cbbcc7b797188a89671019f2b2844e1a14e0c.tar.gz |
Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3
TODO: enable MDEV-13049 optimization for 10.3
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7fc6141bcea..775717fe62b 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -725,13 +725,36 @@ void set_param_date(Item_param *param, uchar **pos, ulong len) #endif /*!EMBEDDED_LIBRARY*/ -static void set_param_str(Item_param *param, uchar **pos, ulong len) +static void set_param_str_or_null(Item_param *param, uchar **pos, ulong len, + bool empty_string_is_null) { ulong length= get_param_length(pos, len); - if (length > len) - length= len; - param->set_str((const char *)*pos, length); - *pos+= length; + if (length == 0 && empty_string_is_null) + param->set_null(); + else + { + if (length > len) + length= len; + param->set_str((const char *) *pos, length); + *pos+= length; + } +} + + +static void set_param_str(Item_param *param, uchar **pos, ulong len) +{ + set_param_str_or_null(param, pos, len, false); +} + + +/* + set_param_str_empty_is_null : bind empty string as null value + when sql_mode=MODE_EMPTY_STRING_IS_NULL +*/ +static void set_param_str_empty_is_null(Item_param *param, uchar **pos, + ulong len) +{ + set_param_str_or_null(param, pos, len, true); } @@ -806,7 +829,10 @@ static void setup_one_conversion_function(THD *thd, Item_param *param, param->value.cs_info.final_character_set_of_str_value= String::needs_conversion(0, fromcs, tocs, &dummy_offset) ? tocs : fromcs; - param->set_param_func= set_param_str; + + param->set_param_func= + (thd->variables.sql_mode & MODE_EMPTY_STRING_IS_NULL) ? + set_param_str_empty_is_null : set_param_str; /* Exact value of max_length is not known unless data is converted to charset of connection, so we have to set it later. @@ -1365,7 +1391,8 @@ static bool mysql_test_insert(Prepared_statement *stmt, my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); goto error; } - if (setup_fields(thd, Ref_ptr_array(), *values, MARK_COLUMNS_NONE, 0, 0)) + if (setup_fields(thd, Ref_ptr_array(), + *values, MARK_COLUMNS_NONE, 0, NULL, 0)) goto error; } } @@ -1459,7 +1486,7 @@ static int mysql_test_update(Prepared_statement *stmt, #endif thd->lex->select_lex.no_wrap_view_item= TRUE; res= setup_fields(thd, Ref_ptr_array(), - select->item_list, MARK_COLUMNS_READ, 0, 0); + select->item_list, MARK_COLUMNS_READ, 0, NULL, 0); thd->lex->select_lex.no_wrap_view_item= FALSE; if (res) goto error; @@ -1471,7 +1498,7 @@ static int mysql_test_update(Prepared_statement *stmt, table_list->register_want_access(SELECT_ACL); #endif if (setup_fields(thd, Ref_ptr_array(), - stmt->lex->value_list, MARK_COLUMNS_NONE, 0, 0) || + stmt->lex->value_list, MARK_COLUMNS_NONE, 0, NULL, 0) || check_unique_table(thd, table_list)) goto error; /* TODO: here we should send types of placeholders to the client. */ @@ -1646,7 +1673,7 @@ static bool mysql_test_do_fields(Prepared_statement *stmt, DT_PREPARE | DT_CREATE)) DBUG_RETURN(TRUE); DBUG_RETURN(setup_fields(thd, Ref_ptr_array(), - *values, MARK_COLUMNS_NONE, 0, 0)); + *values, MARK_COLUMNS_NONE, 0, NULL, 0)); } |