-- source include/not_embedded.inc
-- source have_odbc_sqlite3.inc

#
# For the instructions on how to setup SQLite3 ODBC  DSN,
# please see odbc_sqlite3.test
#

SET NAMES utf8;

let $MYSQLD_DATADIR= `select @@datadir`;


GRANT ALL PRIVILEGES ON *.* TO user@localhost;
REVOKE FILE ON *.* FROM user@localhost;
--connect(user,localhost,user,,)
--connection user
SELECT user();
--error ER_ACCESS_DENIED_ERROR
CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC;
--error ER_ACCESS_DENIED_ERROR
CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers;
--error ER_ACCESS_DENIED_ERROR
CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Sources;
--connection default
SELECT user();


#
# For some reasons Windows does not allow to remove the data base
# file after "DROP TABLE t1". So unlike in odbc_xls.test we won't copy
# the data file, we'll use directly the file in std_data.
# As we do not do any modifications in the database, this should be OK.
#
let $Database=$MTR_SUITE_DIR/std_data/test.sqlite3;
--replace_result $MTR_SUITE_DIR MTR_SUITE_DIR
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=SQLite3 ODBC Driver;Database=$Database;NoWCHAR=yes' CHARSET=utf8 DATA_CHARSET=utf8;
--replace_result $MTR_SUITE_DIR MTR_SUITE_DIR
SHOW CREATE TABLE t1;
SELECT * FROM t1;
--connection user
SELECT user();
--error ER_ACCESS_DENIED_ERROR
SELECT * FROM t1;
--error ER_ACCESS_DENIED_ERROR
INSERT INTO t1 VALUES ('xxx');
--error ER_ACCESS_DENIED_ERROR
DELETE FROM t1 WHERE a='xxx';
--error ER_ACCESS_DENIED_ERROR
UPDATE t1 SET a='yyy' WHERE a='xxx';
--error ER_ACCESS_DENIED_ERROR
TRUNCATE TABLE t1;
--error ER_ACCESS_DENIED_ERROR
ALTER TABLE t1 READONLY=1;
--error ER_ACCESS_DENIED_ERROR
CREATE VIEW v1 AS SELECT * FROM t1;

--echo # Testing a VIEW created with FILE privileges but accessed with no FILE
--echo # using SQL SECIRITY INVOKER
--connection default
SELECT user();
CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT * FROM t1;
--connection user
SELECT user();
--error ER_ACCESS_DENIED_ERROR
SELECT * FROM v1;
--error ER_ACCESS_DENIED_ERROR
INSERT INTO v1 VALUES (2);
--error ER_ACCESS_DENIED_ERROR
UPDATE v1 SET a=123;
--error ER_ACCESS_DENIED_ERROR
DELETE FROM v1;

--echo # Testing a VIEW created with FILE privileges but accessed with no FILE
--echo # using SQL SECIRITY DEFINER
--connection default
DROP VIEW v1;
SELECT user();
CREATE SQL SECURITY DEFINER VIEW v1 AS SELECT * FROM t1;
--connection user
SELECT user();
SELECT * FROM v1 WHERE a='test1';


--disconnect user
--connection default
SELECT user();
DROP VIEW v1;
DROP TABLE t1;

DROP USER user@localhost;
