summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2004-06-07 12:09:10 +0400
committerunknown <sergefp@mysql.com>2004-06-07 12:09:10 +0400
commit1d4ee7f81c1fff2579c3aab8690f977e99a4840e (patch)
treed9e21b580f2c05293aaca3cb0c7ad13a850f0bad /sql/item.cc
parente9c4cea9dea039c79c99940007833d7dde2c59dc (diff)
downloadmariadb-git-1d4ee7f81c1fff2579c3aab8690f977e99a4840e.tar.gz
Post review fixes for "SQL Syntax for Prepared Statements".
mysql-test/r/ps.result: Better error message mysys/my_error.c: Comments added sql/item.cc: Moved a chunk of code from sql_prepare.cc to Item_param::set_from_user_var sql/item.h: Moved a chunk of code from sql_prepare.cc to Item_param::set_from_user_var sql/item_func.cc: Code cleanup sql/mysql_priv.h: Code cleanup sql/sql_class.cc: Code cleanup sql/sql_parse.cc: use user_var_entry::val_str in PREPARE stmt FROM @var. sql/sql_prepare.cc: Post-review fixes and code cleanup. sql/sql_yacc.yy: Coding style fixes
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);