summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <Sinisa@sinisa.nasamreza.org>2002-06-29 16:25:09 +0300
committerunknown <Sinisa@sinisa.nasamreza.org>2002-06-29 16:25:09 +0300
commitb936b25d79b1b98ecb9528048dc4bb431f1d9c58 (patch)
tree5267b84a9907913f772241f1b990102e711bf9f3
parentd7a84c7af0e1eb166c48ce7a7c3e3dca83f43baf (diff)
downloadmariadb-git-b936b25d79b1b98ecb9528048dc4bb431f1d9c58.tar.gz
Added functions :
* binary XOR * logical XOR * CHECK_LOCK("lock_name")
-rw-r--r--Docs/manual.texi33
-rw-r--r--mysql-test/r/func_test.result6
-rw-r--r--mysql-test/r/rpl_get_lock.result3
-rw-r--r--mysql-test/t/func_test.test3
-rw-r--r--mysql-test/t/rpl_get_lock.test1
-rw-r--r--sql/item_cmpfunc.cc15
-rw-r--r--sql/item_cmpfunc.h10
-rw-r--r--sql/item_create.cc7
-rw-r--r--sql/item_create.h1
-rw-r--r--sql/item_func.cc55
-rw-r--r--sql/item_func.h22
-rw-r--r--sql/lex.h2
-rw-r--r--sql/sql_yacc.yy9
13 files changed, 165 insertions, 2 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index b707c7d426d..7db919fbf99 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -49578,6 +49578,39 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet
@item
+Added binary XOR.
+
+The one that with a query like :
+
+select 11 ^ 3;
+
+returns 8.
+
+Based on the code originated by Hartmut Holzgraefe <hartmut@six.de>.
+@item
+
+Added logical XOR.
+
+The one that with a query like:
+
+select 1 XOR 1;
+
+returns 0;
+
+Based on the code originated by Hartmut Holzgraefe <hartmut@six.de>.
+@item
+Add function CHEDK_LOCK("lock_name").
+This function checks if the lock of the certain name is available or not.
+This function does not attempt to take a look.
+It is used like this:
+
+ SELECT CHECK_LOCK("some_lock");
+
+it will return 1 if the lock is held by a process (including by
+itself), 0 if it is currently not held by anyone and NULL on
+errors.
+Based on the code originated by Hartmut Holzgraefe <hartmut@six.de>.
+@item
Removed @code{mysql_ssl_clear()}, as this was not needed.
@item
@code{DECIMAL} and @code{NUMERIC} types can now read exponential numbers.
diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result
index deea5b8bb8b..7d0ef3cff89 100644
--- a/mysql-test/r/func_test.result
+++ b/mysql-test/r/func_test.result
@@ -40,6 +40,12 @@ select 2 in (3,2,5,9,5,1),"monty" in ("david","monty","allan"), 1.2 in (1.4,1.2,
select -1.49 or -1.49,0.6 or 0.6;
-1.49 or -1.49 0.6 or 0.6
1 1
+select 3 ^ 11;
+3 ^ 11
+8
+select 1 XOR 0;
+1 XOR 0
+1
select 5 between 0 and 10 between 0 and 1,(5 between 0 and 10) between 0 and 1;
5 between 0 and 10 between 0 and 1 (5 between 0 and 10) between 0 and 1
0 1
diff --git a/mysql-test/r/rpl_get_lock.result b/mysql-test/r/rpl_get_lock.result
index c86b8f830a5..6201a751961 100644
--- a/mysql-test/r/rpl_get_lock.result
+++ b/mysql-test/r/rpl_get_lock.result
@@ -17,4 +17,7 @@ get_lock("lock",3)
select * from t1;
n
1
+select check_lock("lock");
+check_lock("lock")
+1
drop table t1;
diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test
index ec44009b1a6..844db1a0214 100644
--- a/mysql-test/t/func_test.test
+++ b/mysql-test/t/func_test.test
@@ -15,7 +15,8 @@ select 2 between 1 and 3, "monty" between "max" and "my",2=2 and "monty" between
select 'b' between 'a' and 'c', 'B' between 'a' and 'c';
select 2 in (3,2,5,9,5,1),"monty" in ("david","monty","allan"), 1.2 in (1.4,1.2,1.0);
select -1.49 or -1.49,0.6 or 0.6;
-
+select 3 ^ 11;
+select 1 XOR 0;
#
# Wrong usage of functions
#
diff --git a/mysql-test/t/rpl_get_lock.test b/mysql-test/t/rpl_get_lock.test
index 3fe45eecf46..e197b9911bb 100644
--- a/mysql-test/t/rpl_get_lock.test
+++ b/mysql-test/t/rpl_get_lock.test
@@ -22,6 +22,7 @@ sync_with_master;
select get_lock("lock",3);
select * from t1;
connection master1;
+select check_lock("lock");
drop table t1;
save_master_pos;
connection slave;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index fd6e767d620..ca0044b371a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1624,3 +1624,18 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
return false;
}
}
+
+longlong Item_cond_xor::val_int()
+{
+ List_iterator<Item> li(list);
+ Item *item;
+ int result=0;
+ null_value=1;
+ while ((item=li++))
+ {
+ result ^= (item->val_int() != 0);
+ if (!item->null_value)
+ null_value=0;
+ }
+ return result;
+}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 3f674198856..25d0c239647 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -596,3 +596,13 @@ inline Item *and_conds(Item *a,Item *b)
cond->update_used_tables();
return cond;
}
+
+class Item_cond_xor :public Item_cond
+{
+public:
+ Item_cond_xor() :Item_cond() {}
+ Item_cond_xor(Item *i1,Item *i2) :Item_cond(i1,i2) {}
+ enum Functype functype() const { return COND_XOR_FUNC; }
+ longlong val_int();
+ const char *func_name() const { return "xor"; }
+};
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 61e82b664ff..f268550d115 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -428,3 +428,10 @@ Item *create_func_cast(Item *a, Item_cast cast_type)
}
return res;
}
+
+Item *create_func_check_lock(Item* a)
+{
+ current_thd->safe_to_cache_query=0;
+ return new Item_func_check_lock(a);
+}
+
diff --git a/sql/item_create.h b/sql/item_create.h
index 323e053c261..09d72f9fbb3 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -91,3 +91,4 @@ Item *create_func_version(void);
Item *create_func_weekday(Item* a);
Item *create_load_file(Item* a);
Item *create_wait_for_master_pos(Item* a, Item* b);
+Item *create_func_check_lock(Item* a);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 2d800cddb0d..4dfd9e3585f 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2257,6 +2257,24 @@ double Item_func_match::val()
return ft_handler->please->find_relevance(ft_handler, record, 0);
}
+longlong Item_func_bit_xor::val_int()
+{
+ ulonglong arg1= (ulonglong) args[0]->val_int();
+ if (args[0]->null_value)
+ {
+ null_value=1;
+ return 0;
+ }
+ ulonglong arg2= (ulonglong) args[1]->val_int();
+ if (args[1]->null_value)
+ {
+ null_value=1;
+ return 0;
+ }
+ null_value=0;
+ return (longlong) (arg1 ^ arg2);
+}
+
/***************************************************************************
System variables
@@ -2274,3 +2292,40 @@ Item *get_system_var(LEX_STRING name)
net_printf(&current_thd->net, ER_UNKNOWN_SYSTEM_VARIABLE, name.str);
return 0;
}
+
+/*
+ Check a user level lock.
+ Returns 1: available
+ Returns 0: already taken
+ Returns NULL: Error
+*/
+
+longlong Item_func_check_lock::val_int()
+{
+ String *res=args[0]->val_str(&value);
+ struct timespec abstime;
+ THD *thd=current_thd;
+ ULL *ull;
+ int error=0;
+
+ null_value=0;
+
+ if (/* check_global_access(thd,SUPER_ACL) ||*/ !res || !res->length())
+ {
+ null_value=1;
+ return 0;
+ }
+
+ pthread_mutex_lock(&LOCK_user_locks);
+
+
+ ull= (ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(),
+ res->length());
+
+ pthread_mutex_unlock(&LOCK_user_locks);
+
+ if (!ull || !ull->locked)
+ return 1;
+
+ return 0;
+}
diff --git a/sql/item_func.h b/sql/item_func.h
index 57147b6336f..0e1b5b7c9e0 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -39,7 +39,7 @@ public:
enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
GE_FUNC,GT_FUNC,FT_FUNC,
LIKE_FUNC,NOTLIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
- COND_AND_FUNC,COND_OR_FUNC,BETWEEN,IN_FUNC,INTERVAL_FUNC};
+ COND_AND_FUNC,COND_OR_FUNC,COND_XOR_FUNC,BETWEEN,IN_FUNC,INTERVAL_FUNC};
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL };
enum Type type() const { return FUNC_ITEM; }
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
@@ -989,3 +989,23 @@ enum Item_cast
};
Item *create_func_cast(Item *a, Item_cast cast_type);
+
+
+class Item_func_bit_xor : public Item_int_func
+{
+public:
+ Item_func_bit_xor(Item *a,Item *b) :Item_int_func(a,b) {}
+ longlong val_int();
+ const char *func_name() const { return "^"; }
+ void fix_length_xor_dec() { unsigned_flag=1; }
+};
+
+class Item_func_check_lock :public Item_int_func
+{
+ String value;
+public:
+ Item_func_check_lock(Item *a) :Item_int_func(a) {}
+ longlong val_int();
+ const char *func_name() const { return "check_lock"; }
+ void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
+};
diff --git a/sql/lex.h b/sql/lex.h
index df32f84ae43..8b9d2f3a9e0 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -384,6 +384,7 @@ static SYMBOL symbols[] = {
{ "WRITE", SYM(WRITE_SYM),0,0},
{ "WHEN", SYM(WHEN_SYM),0,0},
{ "WHERE", SYM(WHERE),0,0},
+ { "XOR", SYM(XOR),0,0},
{ "X509", SYM(X509_SYM),0,0},
{ "YEAR", SYM(YEAR_SYM),0,0},
{ "YEAR_MONTH", SYM(YEAR_MONTH_SYM),0,0},
@@ -412,6 +413,7 @@ static SYMBOL sql_functions[] = {
{ "BIT_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)},
{ "CHAR_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
+ { "CHECK_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_check_lock)},
{ "COALESCE", SYM(COALESCE),0,0},
{ "CONCAT", SYM(CONCAT),0,0},
{ "CONCAT_WS", SYM(CONCAT_WS),0,0},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 7b3dc7db52e..635896c2ab2 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -339,6 +339,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token WITH
%token WRITE_SYM
%token X509_SYM
+%token XOR
%token COMPRESSED_SYM
%token BIGINT
@@ -496,6 +497,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%left '-' '+'
%left '*' '/' '%'
%left NEG '~'
+%left XOR
+%left '^'
%right NOT
%right BINARY
@@ -1524,6 +1527,7 @@ expr_expr:
{ $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
| expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
| expr OR expr { $$= new Item_cond_or($1,$3); }
+ | expr XOR expr { $$= new Item_cond_xor($1,$3); }
| expr AND expr { $$= new Item_cond_and($1,$3); }
| expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
| expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5));}
@@ -1545,6 +1549,7 @@ expr_expr:
| expr '*' expr { $$= new Item_func_mul($1,$3); }
| expr '/' expr { $$= new Item_func_div($1,$3); }
| expr '|' expr { $$= new Item_func_bit_or($1,$3); }
+ | expr '^' expr { $$= new Item_func_bit_xor($1,$3); }
| expr '&' expr { $$= new Item_func_bit_and($1,$3); }
| expr '%' expr { $$= new Item_func_mod($1,$3); }
| expr '+' INTERVAL_SYM expr interval
@@ -1560,6 +1565,7 @@ no_in_expr:
{ $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
| no_in_expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
| no_in_expr OR expr { $$= new Item_cond_or($1,$3); }
+ | no_in_expr XOR expr { $$= new Item_cond_xor($1,$3); }
| no_in_expr AND expr { $$= new Item_cond_and($1,$3); }
| no_in_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
| no_in_expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
@@ -1581,6 +1587,7 @@ no_in_expr:
| no_in_expr '*' expr { $$= new Item_func_mul($1,$3); }
| no_in_expr '/' expr { $$= new Item_func_div($1,$3); }
| no_in_expr '|' expr { $$= new Item_func_bit_or($1,$3); }
+ | no_in_expr '^' expr { $$= new Item_func_bit_xor($1,$3); }
| no_in_expr '&' expr { $$= new Item_func_bit_and($1,$3); }
| no_in_expr '%' expr { $$= new Item_func_mod($1,$3); }
| no_in_expr '+' INTERVAL_SYM expr interval
@@ -1601,6 +1608,7 @@ no_and_expr:
{ $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
| no_and_expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
| no_and_expr OR expr { $$= new Item_cond_or($1,$3); }
+ | no_and_expr XOR expr { $$= new Item_cond_xor($1,$3); }
| no_and_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
| no_and_expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
@@ -1621,6 +1629,7 @@ no_and_expr:
| no_and_expr '*' expr { $$= new Item_func_mul($1,$3); }
| no_and_expr '/' expr { $$= new Item_func_div($1,$3); }
| no_and_expr '|' expr { $$= new Item_func_bit_or($1,$3); }
+ | no_and_expr '^' expr { $$= new Item_func_bit_xor($1,$3); }
| no_and_expr '&' expr { $$= new Item_func_bit_and($1,$3); }
| no_and_expr '%' expr { $$= new Item_func_mod($1,$3); }
| no_and_expr '+' INTERVAL_SYM expr interval