File: session_user.result

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (56 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download | duplicates (2)
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
# Create a stored procedure which calls the different functions to retrieve the user
CREATE FUNCTION test.func_session_user() RETURNS CHAR(80) SQL SECURITY DEFINER RETURN CONCAT(USER(), '; ', CURRENT_USER(), '; ', SESSION_USER());
# Create a view which calls the different functions to retrieve the user
CREATE SQL SECURITY DEFINER VIEW test.view_session_user AS SELECT USER(), CURRENT_USER(), SESSION_USER();
# Create test_user
CREATE USER 'test_user'@'%';
GRANT EXECUTE, CREATE, DROP, SELECT ON test.* TO 'test_user'@'%';
# Connect as test_user
connect  test_user_con,localhost,test_user,,;
# Check the function called directly
SELECT USER(), CURRENT_USER(), SESSION_USER();
USER()	CURRENT_USER()	SESSION_USER()
test_user@localhost	test_user@%	test_user@%
# Check the function inside of a stored procedure
SELECT test.func_session_user();
test.func_session_user()
test_user@localhost; root@localhost; test_user@%
# Check the function inside of a view
SELECT * FROM test.view_session_user;
USER()	CURRENT_USER()	SESSION_USER()
test_user@localhost	root@localhost	test_user@%
# Check SESSION_USER is allowed in virtual columns
CREATE OR REPLACE TABLE t1 (a int, b varchar(100) GENERATED ALWAYS AS (SESSION_USER()));
# Check SESSION_USER is not allowed for indexed virtual columns
CREATE OR REPLACE TABLE t1 (a int, b varchar(100) GENERATED ALWAYS AS (SESSION_USER()), INDEX idx (b));
ERROR HY000: Function or expression 'session_user()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# Check SESSION_USER is not allowed in virtual columns when CHECK constrains are provided
CREATE OR REPLACE TABLE t1 (a int, b varchar(100) GENERATED ALWAYS AS (SESSION_USER()) CHECK (b <> ''));
ERROR HY000: Function or expression 'b' cannot be used in the CHECK clause of `b`
# Check SESSION_USER is not allowed for stored virtual columns
CREATE OR REPLACE TABLE t1 (a int, b varchar(100) GENERATED ALWAYS AS (SESSION_USER()) STORED);
ERROR HY000: Function or expression 'session_user()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# Check SESSION_USER is allowed as default
CREATE OR REPLACE TABLE t1 (a int, b varchar(100) DEFAULT (SESSION_USER()));
# Test old mode SESSION_USER_IS_USER behaves properly
SELECT @@OLD_MODE, @@GLOBAL.OLD_MODE;
@@OLD_MODE	@@GLOBAL.OLD_MODE
UTF8_IS_UTF8MB3	UTF8_IS_UTF8MB3
SELECT USER(), SESSION_USER();
USER()	SESSION_USER()
test_user@localhost	test_user@%
SET @@OLD_MODE = CONCAT(@@OLD_MODE, ',SESSION_USER_IS_USER');
Warnings:
Warning	1287	'SESSION_USER_IS_USER' is deprecated and will be removed in a future release
SELECT @@OLD_MODE, @@GLOBAL.OLD_MODE;
@@OLD_MODE	@@GLOBAL.OLD_MODE
UTF8_IS_UTF8MB3,SESSION_USER_IS_USER	UTF8_IS_UTF8MB3
SELECT USER(), SESSION_USER();
USER()	SESSION_USER()
test_user@localhost	test_user@localhost
# Cleanup
connection default;
DROP USER 'test_user'@'%';
DROP FUNCTION test.func_session_user;
DROP VIEW test.view_session_user;
DROP TABLE test.t1;