summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc70
1 files changed, 66 insertions, 4 deletions
diff --git a/sql/item.cc b/sql/item.cc
index ad209817d8a..cabae46ed71 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -255,7 +255,7 @@ bool Item::get_time(TIME *ltime)
return 0;
}
-CHARSET_INFO * Item::default_charset()
+CHARSET_INFO *Item::default_charset()
{
return current_thd->variables.collation_connection;
}
@@ -736,6 +736,70 @@ bool Item_param::set_longdata(const char *str, ulong length)
/*
+ Set parameter value from user variable value.
+
+ SYNOPSIS
+ set_from_user_var
+ thd Current thread
+ entry User variable structure (NULL means use NULL value)
+
+ RETURN
+ 0 OK
+ 1 Out of memort
+*/
+
+bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
+{
+ DBUG_ENTER("Item_param::set_from_user_var");
+ if (entry && entry->value)
+ {
+ item_result_type= entry->type;
+ switch (entry->type)
+ {
+ case REAL_RESULT:
+ set_double(*(double*)entry->value);
+ break;
+ case INT_RESULT:
+ set_int(*(longlong*)entry->value, 21);
+ break;
+ case STRING_RESULT:
+ {
+ CHARSET_INFO *fromcs= entry->collation.collation;
+ CHARSET_INFO *tocs= thd->variables.collation_connection;
+ uint32 dummy_offset;
+
+ value.cs_info.character_set_client= fromcs;
+ /*
+ Setup source and destination character sets so that they
+ are different only if conversion is necessary: this will
+ make later checks easier.
+ */
+ value.cs_info.final_character_set_of_str_value=
+ String::needs_conversion(0, fromcs, tocs, &dummy_offset) ?
+ tocs : fromcs;
+ /*
+ Exact value of max_length is not known unless data is converted to
+ charset of connection, so we have to set it later.
+ */
+ item_type= Item::STRING_ITEM;
+ item_result_type= STRING_RESULT;
+
+ if (set_str((const char *)entry->value, entry->length))
+ DBUG_RETURN(1);
+ }
+ break;
+ default:
+ DBUG_ASSERT(0);
+ set_null();
+ }
+ }
+ else
+ set_null();
+
+ DBUG_RETURN(0);
+}
+
+/*
Resets parameter after execution.
SYNOPSIS
@@ -767,8 +831,6 @@ void Item_param::reset()
int Item_param::save_in_field(Field *field, bool no_conversions)
{
- DBUG_ASSERT(current_thd->command == COM_EXECUTE);
-
field->set_notnull();
switch (state) {
@@ -1666,7 +1728,7 @@ bool Item::send(Protocol *protocol, String *buffer)
}
case MYSQL_TYPE_TINY:
{
- longlong nr;
+ longlong nr;
nr= val_int();
if (!null_value)
result= protocol->store_tiny(nr);