~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
--disable_warnings
2
drop table if exists t1;
3
--enable_warnings
4
5
# Test for INSERT DELAYED INTO a <view>
6
# BUG#13683: INSERT DELAYED into a view creates an infinite loop
7
#
8
9
create table t1 (n int);
10
create view  v1 as select * from t1;
11
--error 1347
12
insert delayed into v1 values (1);
13
drop table t1;
14
drop view  v1;
15
16
#
17
# Bug #20989: View '(null).(null)' references invalid table(s)... on
18
#             SQL SECURITY INVOKER
19
#
20
# this is really the fact that REPLACE ... SELECT required additional
21
# INSERT privs (on tables that are part of a view) over the related
22
# REPLACE, SELECT
23
#
24
25
CREATE DATABASE meow;
26
27
connect (root,localhost,root,,meow);
28
connection root;
29
30
CREATE TABLE table_target   ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id));
31
CREATE TABLE table_target2  ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id));
32
CREATE TABLE table_target3  ( mexs_id CHAR(8), messzeit TIMESTAMP, PRIMARY KEY (mexs_id));
33
CREATE VIEW view_target2 AS SELECT mexs_id,messzeit FROM table_target2;
34
CREATE SQL SECURITY INVOKER VIEW view_target3 AS SELECT mexs_id,messzeit FROM table_target3;
35
36
CREATE TABLE table_stations ( mexs_id VARCHAR(8), icao VARCHAR(4), country CHAR(2), PRIMARY KEY (mexs_id), UNIQUE KEY icao (icao), KEY country (country), CONSTRAINT stations_ibfk_8 FOREIGN KEY (country) REFERENCES countries (country) ON UPDATE CASCADE);
37
INSERT INTO table_stations VALUES ('87654321','XXXX','YY');
38
39
CREATE TABLE table_countries ( country CHAR(2), iso_short_en VARCHAR(64), PRIMARY KEY (country));
40
INSERT INTO table_countries VALUES ('YY','Entenhausen');
41
42
CREATE ALGORITHM=MERGE SQL SECURITY INVOKER VIEW view_stations AS select table_stations.mexs_id AS mexs_id, table_stations.icao AS icao, table_stations.country AS landescode from (table_stations join table_countries on((table_stations.country = table_countries.country)));
43
44
CREATE TABLE table_source ( id varchar(4), datetime TIMESTAMP, PRIMARY KEY (id));
45
INSERT INTO  table_source VALUES ('XXXX','2006-07-12 07:50:00');
46
47
GRANT  SELECT                ON table_source    TO   user20989@localhost;
48
GRANT  SELECT                ON table_countries TO   user20989@localhost;
49
GRANT  SELECT                ON table_stations  TO   user20989@localhost;
50
GRANT  SELECT                ON view_stations   TO   user20989@localhost;
51
GRANT  SELECT                ON table_target    TO   user20989@localhost;
52
GRANT  SELECT                ON table_target2   TO   user20989@localhost;
53
GRANT  INSERT,DELETE,SELECT  ON view_target3    TO   user20989@localhost;
54
55
connect (user20989,localhost,user20989,,meow);
56
connection user20989;
57
58
--error 1142
59
REPLACE INTO    table_target
60
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
61
FROM            table_source
62
INNER JOIN      view_stations AS stations
63
ON              table_source.id = stations.icao
64
LEFT JOIN       table_target AS old
65
USING           (mexs_id);
66
67
--error 1142
68
REPLACE INTO    view_target2
69
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
70
FROM            table_source
71
INNER JOIN      view_stations AS stations
72
ON              table_source.id = stations.icao
73
LEFT JOIN       view_target2 AS old
74
USING           (mexs_id);
75
76
--error 1356
77
REPLACE INTO    view_target3
78
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
79
FROM            table_source
80
INNER JOIN      view_stations AS stations
81
ON              table_source.id = stations.icao
82
LEFT JOIN       view_target3 AS old
83
USING           (mexs_id);
84
85
connection root;
86
disconnect user20989;
87
88
GRANT  INSERT,DELETE         ON table_target    TO   user20989@localhost;
89
GRANT  INSERT,DELETE,SELECT  ON view_target2    TO   user20989@localhost;
90
GRANT  INSERT,DELETE,SELECT  ON table_target3   TO   user20989@localhost;
91
92
connect (user20989,localhost,user20989,,meow);
93
connection user20989;
94
95
REPLACE INTO    table_target
96
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
97
FROM            table_source
98
INNER JOIN      view_stations AS stations
99
ON              table_source.id = stations.icao
100
LEFT JOIN       table_target AS old
101
USING           (mexs_id);
102
103
--error 1142
104
REPLACE INTO    table_target2 VALUES ('00X45Y78','2006-07-12 07:50:00');
105
REPLACE INTO    view_target2  VALUES ('12X45Y78','2006-07-12 07:50:00');
106
107
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
108
FROM            table_source
109
INNER JOIN      view_stations AS stations
110
ON              table_source.id = stations.icao
111
LEFT JOIN       view_target2 AS old
112
USING           (mexs_id);
113
114
REPLACE INTO    view_target2
115
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
116
FROM            table_source
117
INNER JOIN      view_stations AS stations
118
ON              table_source.id = stations.icao
119
LEFT JOIN       view_target2 AS old
120
USING           (mexs_id);
121
122
REPLACE INTO    view_target3
123
SELECT          stations.mexs_id AS mexs_id, datetime AS messzeit
124
FROM            table_source
125
INNER JOIN      view_stations AS stations
126
ON              table_source.id = stations.icao
127
LEFT JOIN       view_target3 AS old
128
USING           (mexs_id);
129
130
connection root;
131
disconnect user20989;
132
133
SELECT * FROM table_target;
134
SELECT * FROM view_target2;
135
SELECT * FROM view_target3;
136
137
DROP VIEW  view_stations;
138
DROP TABLE table_source;
139
DROP TABLE table_countries;
140
DROP TABLE table_stations;
141
DROP TABLE table_target;
142
DROP TABLE table_target2;
143
DROP TABLE table_target3;
144
DROP VIEW  view_target2;
145
DROP VIEW  view_target3;
146
DROP USER  user20989@localhost;
147
148
disconnect root;
149
150
connection default;
151
152
DROP DATABASE meow;
153
154
#
155
# Bug#28587 SELECT is blocked by INSERT waiting on read lock, even with low_priority_updates
156
#
157
--echo connection: default
158
set low_priority_updates=1;
159
--disable_warnings
160
drop table if exists t1;
161
--enable_warnings
162
create table t1 (a int, b int, unique key t1$a (a));
163
lock table t1 read;
164
connect (update,localhost,root,,);
165
connection update;
166
--echo connection: update
167
set low_priority_updates=1;
168
show variables like 'low_priority_updates';
169
let $ID= `select connection_id()`;
170
--send insert into t1 values (1, 2) ON DUPLICATE KEY UPDATE b = 2;
171
connection default;
172
# we must wait till the insert opens and locks the table
173
let $wait_condition=
174
  select count(*) = 1 from information_schema.processlist
175
  where state = "Table lock" and id = $ID;
176
--source include/wait_condition.inc
177
connect (select,localhost,root,,);
178
--echo connection: select
179
select * from t1;
180
connection default;
181
--echo connection: default
182
select * from t1;
183
connection default;
184
disconnect update;
185
disconnect select;
186
unlock tables;
187
drop table t1;
188
set low_priority_updates=default;