|
HSQLDB example source code file (TestSelfUserFunction.txt)
The HSQLDB TestSelfUserFunction.txt source code-- -- TestSelfUserFunction.txt -- -- This test checks if the USER() function works correctly when used within -- prepared statements such as VIEW's and constraints in TABLE's -- Setup tables and views DROP TABLE USER_PROFILE IF EXISTS CREATE TABLE USER_PROFILE(NAME VARCHAR(10), PROFILE INT, CHECK(USER() = NAME)) DROP VIEW USER_SECURITY_PROFILE_VIEW IF EXISTS CREATE VIEW USER_SECURITY_PROFILE_VIEW AS SELECT * FROM USER_PROFILE WHERE Name = USER() -- Create user for test CREATE USER MATT PASSWORD MATT ADMIN -- This checks that you are allowed to insert a row as long as your username matches the NAME field /*u1*/ INSERT INTO USER_PROFILE(NAME, PROFILE) VALUES('SA',10) -- This checks that you aren't allowed to insert a row as a different user /*e*/ INSERT INTO USER_PROFILE(NAME, PROFILE) VALUES('MATT',100) -- Connect as MATT CONNECT USER MATT PASSWORD MATT -- Insert a row as the connected user /*u1*/ INSERT INTO USER_PROFILE(NAME, PROFILE) VALUES('MATT',20) -- There are two rows in the table but the select should only return the row -- associated with the connected user i.e. one row /*c1*/ SELECT COUNT(*) FROM USER_SECURITY_PROFILE_VIEW Other HSQLDB examples (source code examples)Here is a short list of links related to this HSQLDB TestSelfUserFunction.txt source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.