~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/insert_notembedded.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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