summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-05-17 12:59:07 +0400
committerAlexander Barkov <bar@mariadb.org>2017-05-17 12:59:07 +0400
commit896c2c73a02c7e82299b00e66ee3ff5f85aa3adc (patch)
treeb51a6b87f0d2488845144be585275c8cac19a1ed /sql/item_func.cc
parent6378c95ee07cccc2f2187b2caddc4496e14827d9 (diff)
parentfba7fbbc5c7bb1d05488108a29b854ee8ef0066a (diff)
downloadmariadb-git-896c2c73a02c7e82299b00e66ee3ff5f85aa3adc.tar.gz
Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.310.3-MDEV-10953
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc81
1 files changed, 78 insertions, 3 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 0fddc65a66b..1f1523e738a 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -546,7 +546,9 @@ my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
bool Item_hybrid_func::fix_attributes(Item **items, uint nitems)
{
bool rc= Item_hybrid_func::type_handler()->
- Item_hybrid_func_fix_attributes(current_thd, this, items, nitems);
+ Item_hybrid_func_fix_attributes(current_thd,
+ func_name(), this, this,
+ items, nitems);
DBUG_ASSERT(!rc || current_thd->is_error());
return rc;
}
@@ -2771,7 +2773,7 @@ my_decimal *Item_func_min_max::val_decimal_native(my_decimal *dec)
}
-longlong Item_func_length::val_int()
+longlong Item_func_octet_length::val_int()
{
DBUG_ASSERT(fixed == 1);
String *res=args[0]->val_str(&value);
@@ -6787,7 +6789,7 @@ longlong Item_func_nextval::val_int()
}
}
entry->null_value= null_value= 0;
- value= table->s->sequence->next_value(table,0, &error);
+ value= table->s->sequence->next_value(table, 0, &error);
entry->value= value;
entry->set_version(table);
@@ -6879,3 +6881,76 @@ longlong Item_func_lastval::val_int()
null_value= entry->null_value;
DBUG_RETURN(entry->value);
}
+
+
+/*
+ Sets next value to be returned from sequences
+
+ SELECT setval('foo', 42, 0); Next nextval will return 43
+ SELECT setval('foo', 42, 0, true); Same as above
+ SELECT setval('foo', 42, 0, false); Next nextval will return 42
+*/
+
+longlong Item_func_setval::val_int()
+{
+ longlong value;
+ int error;
+ TABLE *table= table_list->table;
+ DBUG_ASSERT(table && table->s->sequence);
+ DBUG_ENTER("Item_func_setval::val_int");
+
+ value= nextval;
+ error= table->s->sequence->set_value(table, nextval, round, is_used);
+ if (error)
+ {
+ null_value= 1;
+ value= 0;
+ }
+ DBUG_RETURN(value);
+}
+
+
+/* Print for setval */
+
+void Item_func_setval::print(String *str, enum_query_type query_type)
+{
+ char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
+ const char *d_name= table_list->db, *t_name= table_list->table_name;
+ bool use_db_name= d_name && d_name[0];
+ THD *thd= table_list->table->in_use;
+
+ str->append(func_name());
+ str->append('(');
+
+ /*
+ for next_val we assume that table_list has been updated to contain
+ the current db.
+ */
+
+ if (lower_case_table_names > 0)
+ {
+ strmake(t_name_buff, t_name, MAX_ALIAS_NAME-1);
+ my_casedn_str(files_charset_info, t_name_buff);
+ t_name= t_name_buff;
+ if (use_db_name)
+ {
+ strmake(d_name_buff, d_name, MAX_ALIAS_NAME-1);
+ my_casedn_str(files_charset_info, d_name_buff);
+ d_name= d_name_buff;
+ }
+ }
+
+ if (use_db_name)
+ {
+ append_identifier(thd, str, d_name, (uint)strlen(d_name));
+ str->append('.');
+ }
+ append_identifier(thd, str, t_name, (uint) strlen(t_name));
+ str->append(',');
+ str->append_longlong(nextval);
+ str->append(',');
+ str->append_longlong(is_used);
+ str->append(',');
+ str->append_ulonglong(round);
+ str->append(')');
+}