summaryrefslogtreecommitdiff
path: root/mysql-test/main/default_session.test
blob: 5e582bd5ca1f99290f1dc4ba0cd3e13b3702e17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# DEFAULT clause with functions that depend on the current session state
#

source include/not_embedded.inc;

create database mysqltest1;

create user ''@localhost;
create user foo@localhost;
create role bar;
grant select on *.* to ''@localhost;
grant select,insert on *.* to foo@localhost;
grant select,insert on *.* to bar;
grant bar to ''@localhost;

create table t1 (n varchar(100),
                 u varchar(100) default user(),
                 cu varchar(100) default current_user(),
                 cr varchar(100) default current_role(),
                 d  varchar(100) default database());

create definer=foo@localhost view mysqltest1.v1 as select * from t1;
create definer=bar           view            v2 as select * from t1;
create                       view            v3 as select * from v2;

create definer=foo@localhost view mysqltest1.v4 as select default(n),default(u),default(cu),default(cr), default(d) from t1;
create definer=bar           view            v5 as select default(n),default(u),default(cu),default(cr), default(d) from t1;
create                       view            v6 as select * from v5;

insert t1 (n)  values ('t1');
insert mysqltest1.v1 (n)  values ('v1');
insert v2 (n)  values ('v2');
insert v3 (n)  values ('v3');

select default(n),default(u),default(cu),default(cr), default(d) from t1 limit 1;
select * from mysqltest1.v4 limit 1;
select * from v5 limit 1;
select * from v6 limit 1;

connect (conn,localhost,conn,,mysqltest1);
set role bar;
insert test.t1 (n)  values ('t1');
insert v1 (n)  values ('v1');
insert test.v2 (n)  values ('v2');
insert test.v3 (n)  values ('v3');

select default(n),default(u),default(cu),default(cr), default(d) from test.t1 limit 1;
select * from v4 limit 1;
select * from test.v5 limit 1;
select * from test.v6 limit 1;
connection default;
disconnect conn;

select * from t1;
drop database mysqltest1;
drop view v2, v3, v5, v6;
drop table t1;
drop user ''@localhost;
drop user foo@localhost;
drop role bar;

create table t1 (a date,
                 mn varchar(100) default monthname(a),
                 dn varchar(100) default dayname(a),
                 df varchar(100) default date_format(a, "%a, %b"));

insert t1 (a) values ('2010-12-2');
set lc_time_names=de_DE;
insert t1 (a) values ('2010-12-2');
set lc_time_names=default;

select * from t1;
drop table t1;

create table t1 (a varchar(100) default @@sql_mode);
insert t1 () values ();
set sql_mode=ansi;
insert t1 () values ();
set sql_mode=default;
select * from t1;
drop table t1;

#
# MDEV-21249 MariaDB 10.3.10 When referring to bigint to generate timestamp data in the virtual generated column, the value of the generated column does not change when the time zone changes
#
set time_zone='+00:00';
create table t1 (a int, b datetime default from_unixtime(a), c datetime);
insert t1 (a, c) values (1569495327, from_unixtime(1569495327));
set time_zone='+01:00';
insert t1 (a, c) values (1569495327, from_unixtime(1569495327));
flush tables;
insert t1 (a, c) values (1569495327, from_unixtime(1569495327));
select * from t1;
drop table t1;

# same with vcols
set time_zone = "+00:00";
create table t1 (a int, b timestamp as (from_unixtime(a)) virtual);
insert into t1 (a) value (1569495327);
select a, b, from_unixtime(a) from t1;
set time_zone = "+01:00";
select a, b, from_unixtime(a) from t1;
flush tables;
select a, b, from_unixtime(a) from t1;
drop table t1;