summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <dlenev@brandersnatch.localdomain>2004-05-04 19:08:19 +0400
committerunknown <dlenev@brandersnatch.localdomain>2004-05-04 19:08:19 +0400
commit5b19a9d065b3428490e2a9303b4f41c07a1b20da (patch)
tree25f19644d618bbfab8cdc286c8fabf3061186256 /sql/item.cc
parent1d36e9ff9a28199da857dd34d3bbcfa8a4db3d18 (diff)
downloadmariadb-git-5b19a9d065b3428490e2a9303b4f41c07a1b20da.tar.gz
Fix for remaining issues described in Bug #1664
"mysql_send_long_data() API call is completely broken". Now we are resetting some members (long_data_supplied/null_value...) of Item_param to its initial state after each execution of prepared statement. We also manipulating Item_param::maybe_null/null_value only via Item_param::set_* setters which makes code a bit more robust. sql/item.cc: Now we are assuming that Item_param may be NULL until we know this fact exactly. Added non-empty implementation of Item_param::reset() method which should be used for restoring Item_param state after each statment execution. (We need to clear long_data_supplied flag, we also clear some other Item_param members here since it makes code simpler.) sql/item.h: Now Item_param::reset() method really does something. sql/sql_prepare.cc: Now we are calling Item_param::reset() for each parameter after execution for resetting Item_param to initial state. So we no longer don't need Prepared_statement::long_data_flag. We also set Item_param::null_value/maybe_null value in Item_param::set_* and reset() methods instead of doing it explicitly in insert_params_* functions (this by the way lowers probability that we will forget to update one of such functions). tests/client_test.c: Added test for Bug#1664 "mysql_send_long_data() API call is broken".
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc34
1 files changed, 33 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 72583ea02bb..44a05c42526 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -605,12 +605,19 @@ Item_param::Item_param(unsigned position) :
set_param_func(default_set_param_func)
{
name= (char*) "?";
+ /*
+ Since we can't say whenever this item can be NULL or cannot be NULL
+ before mysql_stmt_execute(), so we assuming that it can be NULL until
+ value is set.
+ */
+ maybe_null= 1;
}
void Item_param::set_null()
{
DBUG_ENTER("Item_param::set_null");
- maybe_null= null_value= value_is_set= 1;
+ /* These are cleared after each execution by reset() method */
+ null_value= value_is_set= 1;
DBUG_VOID_RETURN;
}
@@ -620,6 +627,7 @@ void Item_param::set_int(longlong i)
int_value= (longlong)i;
item_type= INT_ITEM;
value_is_set= 1;
+ maybe_null= 0;
DBUG_PRINT("info", ("integer: %lld", int_value));
DBUG_VOID_RETURN;
}
@@ -630,6 +638,7 @@ void Item_param::set_double(double value)
real_value=value;
item_type= REAL_ITEM;
value_is_set= 1;
+ maybe_null= 0;
DBUG_PRINT("info", ("double: %lg", real_value));
DBUG_VOID_RETURN;
}
@@ -641,6 +650,7 @@ void Item_param::set_value(const char *str, uint length)
str_value.copy(str,length,default_charset());
item_type= STRING_ITEM;
value_is_set= 1;
+ maybe_null= 0;
DBUG_PRINT("info", ("string: %s", str_value.ptr()));
DBUG_VOID_RETURN;
}
@@ -665,6 +675,7 @@ void Item_param::set_time(TIME *tm, timestamp_type type)
item_is_time= TRUE;
item_type= STRING_ITEM;
value_is_set= 1;
+ maybe_null= 0;
}
@@ -673,6 +684,27 @@ void Item_param::set_longdata(const char *str, ulong length)
str_value.append(str,length);
long_data_supplied= 1;
value_is_set= 1;
+ maybe_null= 0;
+}
+
+
+/*
+ Resets parameter after execution.
+
+ SYNOPSIS
+ Item_param::reset()
+
+ NOTES
+ We clear null_value here instead of setting it in set_* methods,
+ because we want more easily handle case for long data.
+*/
+
+void Item_param::reset()
+{
+ str_value.set("", 0, &my_charset_bin);
+ value_is_set= long_data_supplied= 0;
+ maybe_null= 1;
+ null_value= 0;
}