The system generates a unique ID (either an application-side or a database-tutorial uuid) in some way, and then attempts to associate it with this ID.
Code:
drop table if exists test;
CREATE TABLE Test (
ID int NOT NULL,
Name varchar NOT NULL
);
INSERT into test values (1, ' test1 ');
INSERT into test values (1, ' test11 ');
INSERT into test values (1, ' test111 ');
INSERT into test values (2, ' test2 ');
INSERT into test values (2, ' test22 ');
Drop function if exists getspid;
Delimiter |
CREATE function Getspid ()
RETURNS int
return @spid;
|
delimiter;
Drop view if exists v_test;
CREATE View V_test as
SELECT * FROM Test where id=getspid ();
--Test code
--Open Session 1
Set @spid = 1;
SELECT * from V_test;
--Open Session 2
Set @spid = 2;
SELECT * from V_test;
Description
Keep the generated ID inside the session variable
Then create a custom function that returns this variable
Finally call this function in the view