summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <serg@serg.mysql.com>2002-01-03 19:47:14 +0000
committerunknown <serg@serg.mysql.com>2002-01-03 19:47:14 +0000
commitc7f9472be8eafbc046156accb43593a2fc60ad04 (patch)
treee44d2aa432e29fb7c07fd866dcfc56d2b9294101
parent0abc68fbeb74832503634a208b21c756b510c392 (diff)
downloadmariadb-git-c7f9472be8eafbc046156accb43593a2fc60ad04.tar.gz
BIT_LENGTH ODBC function
-rw-r--r--Docs/manual.texi18
-rw-r--r--mysql-test/r/func_str.result3
-rw-r--r--mysql-test/t/func_str.test1
-rw-r--r--sql/item_create.cc5
-rw-r--r--sql/item_create.h1
-rw-r--r--sql/item_func.h8
-rw-r--r--sql/lex.h1
7 files changed, 37 insertions, 0 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 9997026afa1..a5a11113761 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -30076,6 +30076,15 @@ mysql> select OCTET_LENGTH('text');
Note that for @code{CHAR_LENGTH()}, multi-byte characters are only counted
once.
+@findex BIT_LENGTH()
+@item BIT_LENGTH(str)
+Returns the length of the string @code{str} in bits:
+
+@example
+mysql> select BIT_LENGTH('text');
+ -> 32
+@end example
+
@findex LOCATE()
@findex POSITION()
@item LOCATE(substr,str)
@@ -47893,10 +47902,19 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@cindex changes, version 4.0
@menu
+* News-4.0.2:: Changes in release 4.0.2
* News-4.0.1:: Changes in release 4.0.1
* News-4.0.0:: Changes in release 4.0.0
@end menu
+@node News-4.0.2, News-4.0.1, News-4.0.x, News-4.0.x
+@appendixsubsec Changes in release 4.0.2
+
+@itemize @bullet
+@item
+ODBC compatibility: added @code{BIT_LENGTH()} function.
+@end itemize
+
@node News-4.0.1, News-4.0.0, News-4.0.x, News-4.0.x
@appendixsubsec Changes in release 4.0.1
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index 5aca1f6b021..a58f3c57169 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -8,6 +8,9 @@ hellomonty
select length('\n\t\r\b\0\_\%\\');
length('\n\t\r\b\0\_\%\\')
10
+select bit_length('\n\t\r\b\0\_\%\\');
+bit_length('\n\t\r\b\0\_\%\\')
+80
select concat('monty',' was here ','again'),length('hello'),char(ascii('h'));
concat('monty',' was here ','again') length('hello') char(ascii('h'))
monty was here again 5 h
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index fd6ff0d70e7..26272fba03f 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -9,6 +9,7 @@ drop table if exists t1;
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
select 'hello' 'monty';
select length('\n\t\r\b\0\_\%\\');
+select bit_length('\n\t\r\b\0\_\%\\');
select concat('monty',' was here ','again'),length('hello'),char(ascii('h'));
select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ;
select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE');
diff --git a/sql/item_create.cc b/sql/item_create.cc
index a9567414b0b..f07632984d9 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -200,6 +200,11 @@ Item *create_func_length(Item* a)
return new Item_func_length(a);
}
+Item *create_func_bit_length(Item* a)
+{
+ return new Item_func_bit_length(a);
+}
+
Item *create_func_char_length(Item* a)
{
return new Item_func_char_length(a);
diff --git a/sql/item_create.h b/sql/item_create.h
index 9318025cae8..580596505da 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -22,6 +22,7 @@ Item *create_func_ascii(Item* a);
Item *create_func_asin(Item* a);
Item *create_func_bin(Item* a);
Item *create_func_bit_count(Item* a);
+Item *create_func_bit_length(Item* a);
Item *create_func_ceiling(Item* a);
Item *create_func_char_length(Item* a);
Item *create_func_connection_id(void);
diff --git a/sql/item_func.h b/sql/item_func.h
index d944ef6bc36..35fe699192f 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -501,6 +501,14 @@ public:
void fix_length_and_dec() { max_length=10; }
};
+class Item_func_bit_length :public Item_func_length
+{
+public:
+ Item_func_bit_length(Item *a) :Item_func_length(a) {}
+ longlong val_int() { return Item_func_length::val_int()*8; }
+ const char *func_name() const { return "bit_length"; }
+};
+
class Item_func_char_length :public Item_int_func
{
String value;
diff --git a/sql/lex.h b/sql/lex.h
index 887fcb78754..704b9a81683 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -397,6 +397,7 @@ static SYMBOL sql_functions[] = {
{ "BIT_OR", SYM(BIT_OR),0,0},
{ "BIT_AND", SYM(BIT_AND),0,0},
{ "CEILING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
+ { "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)},
{ "COALESCE", SYM(COALESCE),0,0},