summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2003-03-02 19:17:41 +0100
committerunknown <pem@mysql.com>2003-03-02 19:17:41 +0100
commit8a9422bd2af6ea39676171b9ec16897c64104dc8 (patch)
treef607e9e9c2756612d8e622c239e1781b56f51e63 /mysql-test
parent1ff79b61a056e5b50fc0402680f6f74ca1eb2a57 (diff)
downloadmariadb-git-8a9422bd2af6ea39676171b9ec16897c64104dc8.tar.gz
Made FUNCTIONs work in insert and select queries, as well as nested function invocations.
Had to add a cahing mechanism which is in parts an ugly kludge, but it will be reworked once the real SP caching is implemented. mysql-test/r/sp.result: New function tests. mysql-test/t/sp.test: New function tests. sql/sp.cc: Big rehack of mysql.proc table usage strategy and adding a function cache mechanism, since we need to read used functions from the db before doing anything else when executing a query. (This cache is temporary and will probably be replaced by the real thing later.) sql/sp.h: New (temporary) FUNCTION caching functions. sql/sp_head.cc: Fixed some bugs in the function and procedure execution. Disabled some data collections that's not used at the moment. sql/sp_head.h: Fixed some bugs in the function and procedure execution. Disabled some data collections that's not used at the moment. sql/sql_class.h: Added SP function cache list to thd. sql/sql_lex.cc: Added SP function name list to lex. sql/sql_lex.h: Added SP function name list to lex. sql/sql_parse.cc: Read used FUNCTIONs from db and cache them in thd before doing anything else in a query execution. (This is necessary since we can't open mysql.proc during query execution.) sql/sql_yacc.yy: Collect used function names in lex.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/sp.result30
-rw-r--r--mysql-test/t/sp.test27
2 files changed, 57 insertions, 0 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index ab445e44a5a..13983fbd69e 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -1,9 +1,15 @@
use test;
drop table if exists t1;
+drop table if exists t2;
create table t1 (
id char(16) not null,
data int not null
);
+create table t2 (
+s char(16) not null,
+i int not null,
+d double not null
+);
create procedure foo42()
insert into test.t1 values ("foo", 42);
call foo42();
@@ -409,9 +415,33 @@ end;
select fac(1), fac(2), fac(5), fac(10);
fac(1) fac(2) fac(5) fac(10)
1 2 120 3628800
+create function fun(d double, i int, u int unsigned) returns double
+return mul(inc(i), fac(u)) / e();
+select fun(2.3, 3, 5);
+fun(2.3, 3, 5)
+176.58213176229
+insert into t2 values (append("xxx", "yyy"), mul(4,3), e());
+insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6));
+select * from t2 where s = append("a", "b");
+s i d
+ab 24 1324.36598821719
+select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2);
+s i d
+xxxyyy 12 2.71828182845905
+ab 24 1324.36598821719
+select * from t2 where d = e();
+s i d
+xxxyyy 12 2.71828182845905
+select * from t2;
+s i d
+xxxyyy 12 2.71828182845905
+ab 24 1324.36598821719
+delete from t2;
drop function e;
drop function inc;
drop function mul;
drop function append;
drop function fac;
+drop function fun;
drop table t1;
+drop table t2;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 17b21f612d6..a5efee28446 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -7,12 +7,18 @@ use test;
--disable_warnings
drop table if exists t1;
+drop table if exists t2;
--enable_warnings
create table t1 (
id char(16) not null,
data int not null
);
+create table t2 (
+ s char(16) not null,
+ i int not null,
+ d double not null
+);
# Single statement, no params.
@@ -481,11 +487,32 @@ end|
select fac(1), fac(2), fac(5), fac(10)|
+# Nested calls
+create function fun(d double, i int, u int unsigned) returns double
+ return mul(inc(i), fac(u)) / e()|
+
+select fun(2.3, 3, 5)|
+
+
+# Various function calls in differen statements
+
+insert into t2 values (append("xxx", "yyy"), mul(4,3), e())|
+insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))|
+
+# These don't work yet.
+select * from t2 where s = append("a", "b")|
+select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)|
+select * from t2 where d = e()|
+select * from t2|
+delete from t2|
+
drop function e|
drop function inc|
drop function mul|
drop function append|
drop function fac|
+drop function fun|
delimiter ;|
drop table t1;
+drop table t2;