summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-07-25 01:00:56 +0300
committerunknown <monty@mashka.mysql.fi>2002-07-25 01:00:56 +0300
commita5b1ccda10467c44b650ad307a093e69f44e9a20 (patch)
tree568e82ff70f747c40f1e4c09d11d2c2355da2a20 /sql
parentbde684743a47e3f1f7513371127555f5825f2fa4 (diff)
downloadmariadb-git-a5b1ccda10467c44b650ad307a093e69f44e9a20.tar.gz
INSERT ... VALUES(DEFAULT)
BitKeeper/deleted/.del-insert_set.test~35be5a761a410ac1: Delete: mysql-test/t/insert_set.test BitKeeper/deleted/.del-insert_set.result~fca5025db098c892: Delete: mysql-test/r/insert_set.result Docs/manual.texi: Changelog mysql-test/r/insert.result: Test new insert ... (DEFAULT) mysql-test/t/insert.test: Test new insert ... (DEFAULT) sql/item.cc: Indentation cleanup
Diffstat (limited to 'sql')
-rw-r--r--sql/field.h8
-rw-r--r--sql/item.cc2
-rw-r--r--sql/item.h24
-rw-r--r--sql/sql_insert.cc26
-rw-r--r--sql/sql_yacc.yy30
5 files changed, 63 insertions, 27 deletions
diff --git a/sql/field.h b/sql/field.h
index 69d1fbc826f..656dd9a592d 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -70,6 +70,10 @@ public:
virtual uint32 pack_length() const { return (uint32) field_length; }
virtual void reset(void) { bzero(ptr,pack_length()); }
virtual void reset_fields() {}
+ virtual void set_default()
+ {
+ memcpy(ptr, ptr + table->rec_buff_length, pack_length());
+ }
virtual bool binary() const { return 1; }
virtual bool zero_pack() const { return 1; }
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
@@ -550,6 +554,10 @@ public:
bool store_for_compare() { return 1; }
bool zero_pack() const { return 0; }
void set_time();
+ virtual void set_default()
+ {
+ set_time();
+ }
inline long get_timestamp()
{
#ifdef WORDS_BIGENDIAN
diff --git a/sql/item.cc b/sql/item.cc
index 2b1e3b381c8..bb39a141e9f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -383,12 +383,14 @@ void Item_datetime::make_field(Send_field *tmp_field)
init_make_field(tmp_field,FIELD_TYPE_DATETIME);
}
+
void Item_null::make_field(Send_field *tmp_field)
{
init_make_field(tmp_field,FIELD_TYPE_NULL);
tmp_field->length=4;
}
+
void Item_func::make_field(Send_field *tmp_field)
{
init_make_field(tmp_field, ((result_type() == STRING_RESULT) ?
diff --git a/sql/item.h b/sql/item.h
index a7ea48a45aa..70729afe28e 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -31,7 +31,7 @@ public:
enum Type {FIELD_ITEM,FUNC_ITEM,SUM_FUNC_ITEM,STRING_ITEM,
INT_ITEM,REAL_ITEM,NULL_ITEM,VARBIN_ITEM,
- COPY_STR_ITEM,FIELD_AVG_ITEM,
+ COPY_STR_ITEM,FIELD_AVG_ITEM, DEFAULT_ITEM,
PROC_ITEM,COND_ITEM,REF_ITEM,FIELD_STD_ITEM, CONST_ITEM};
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
@@ -285,6 +285,28 @@ public:
unsigned int size_of() { return sizeof(*this);}
};
+
+/* For INSERT ... VALUES (DEFAULT) */
+
+class Item_default :public Item
+{
+public:
+ Item_default() { name= (char*) "DEFAULT"; }
+ enum Type type() const { return DEFAULT_ITEM; }
+ void make_field(Send_field *field) {}
+ bool save_in_field(Field *field)
+ {
+ field->set_default();
+ return 0;
+ }
+ virtual double val() { return 0.0; }
+ virtual longlong val_int() { return 0; }
+ virtual String *val_str(String *str) { return 0; }
+ bool basic_const_item() const { return 1; }
+ unsigned int size_of() { return sizeof(*this);}
+};
+
+
/* for show tables */
class Item_datetime :public Item_string
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 4cc9dc550c8..053e96c5fdd 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -60,7 +60,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
if (grant_option &&
check_grant_all_columns(thd,INSERT_ACL,table))
return -1;
- table->time_stamp=0; // This should be saved
+ table->time_stamp=0; // This is saved by caller
}
else
{ // Part field list
@@ -178,7 +178,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
}
its.rewind ();
/*
- ** Fill in the given fields and dump it to the table file
+ Fill in the given fields and dump it to the table file
*/
info.records=info.deleted=info.copied=0;
@@ -204,7 +204,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
thd->variables.bulk_insert_buff_size);
}
- while ((values = its++))
+ while ((values= its++))
{
if (fields.elements || !value_count)
{
@@ -367,7 +367,7 @@ static int last_uniq_key(TABLE *table,uint keynr)
/*
-** Write a record to table with optional deleting of conflicting records
+ Write a record to table with optional deleting of conflicting records
*/
@@ -461,9 +461,9 @@ err:
/******************************************************************************
- Check that all fields with arn't null_fields are used
- if DONT_USE_DEFAULT_FIELDS isn't defined use default value for not
- set fields.
+ Check that all fields with arn't null_fields are used
+ If DONT_USE_DEFAULT_FIELDS isn't defined use default value for not set
+ fields.
******************************************************************************/
static int check_null_fields(THD *thd __attribute__((unused)),
@@ -486,10 +486,8 @@ static int check_null_fields(THD *thd __attribute__((unused)),
}
/*****************************************************************************
-** Handling of delayed inserts
-**
-** A thread is created for each table that one uses with the DELAYED
-** attribute.
+ Handling of delayed inserts
+ A thread is created for each table that one uses with the DELAYED attribute.
*****************************************************************************/
class delayed_row :public ilink {
@@ -1272,7 +1270,7 @@ bool delayed_insert::handle_inserts(void)
/***************************************************************************
-** store records in INSERT ... SELECT *
+ Store records in INSERT ... SELECT *
***************************************************************************/
int
@@ -1389,7 +1387,7 @@ bool select_insert::send_eof()
/***************************************************************************
-** CREATE TABLE (SELECT) ...
+ CREATE TABLE (SELECT) ...
***************************************************************************/
int
@@ -1487,7 +1485,7 @@ void select_create::abort()
/*****************************************************************************
-** Instansiate templates
+ Instansiate templates
*****************************************************************************/
#ifdef __GNUC__
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 1288f03155e..d9080332bd6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -519,7 +519,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
literal text_literal insert_ident order_ident
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
- using_list expr_or_default
+ using_list expr_or_default set_expr_or_default
%type <item_list>
expr_list udf_expr_list when_list ident_list ident_list_arg
@@ -2486,7 +2486,7 @@ ident_eq_list:
ident_eq_value;
ident_eq_value:
- simple_ident equal expr
+ simple_ident equal expr_or_default
{
LEX *lex=Lex;
if (lex->field_list.push_back($1) ||
@@ -2521,16 +2521,22 @@ opt_values:
| values;
values:
- values ',' expr
+ values ',' expr_or_default
{
if (Lex->insert_list->push_back($3))
YYABORT;
}
- | expr
- {
- if (Lex->insert_list->push_back($1))
- YYABORT;
- };
+ | expr_or_default
+ {
+ if (Lex->insert_list->push_back($1))
+ YYABORT;
+ }
+ ;
+
+expr_or_default:
+ expr { $$= $1;}
+ | DEFAULT {$$= new Item_default(); }
+ ;
/* Update rows in a table */
@@ -3257,12 +3263,12 @@ option_value:
{
Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
}
- | internal_variable_name equal expr_or_default
+ | internal_variable_name equal set_expr_or_default
{
LEX *lex=Lex;
lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
}
- | '@' '@' opt_var_ident_type internal_variable_name equal expr_or_default
+ | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
{
LEX *lex=Lex;
lex->var_list.push_back(new set_var((enum_var_type) $3, $4, $6));
@@ -3274,7 +3280,7 @@ option_value:
find_sys_var("transaction_isolation_num"),
new Item_int((int) $4)));
}
- | CHAR_SYM SET opt_equal expr_or_default
+ | CHAR_SYM SET opt_equal set_expr_or_default
{
LEX *lex=Lex;
lex->var_list.push_back(new set_var(lex->option_type,
@@ -3327,7 +3333,7 @@ text_or_password:
};
-expr_or_default:
+set_expr_or_default:
expr { $$=$1; }
| DEFAULT { $$=0; }
| ON { $$=new Item_string("ON",2); }