~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blitzdb/tests/t/basic.test

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Basic Test Routine for unindexed BlitzDB Tables
 
2
 
 
3
--disable_warnings
 
4
drop table if exists t1, t2;
 
5
--enable_warnings
 
6
 
 
7
# CREATE TABLE
 
8
create table t1 (a int, b double, c float) engine = blitzdb;
 
9
create table t2 (a int, b text, c blob) engine = blitzdb;
 
10
 
 
11
--error ER_TABLE_EXISTS_ERROR
 
12
create table t1 (a int, b double, c float) engine = blitzdb;
 
13
--error ER_TABLE_EXISTS_ERROR
 
14
create table t2 (a int, b text, c blob) engine = blitzdb;
 
15
--error ER_TABLE_EXISTS_ERROR
 
16
create table t1 (a int) engine = blitzdb;
 
17
--error ER_TABLE_EXISTS_ERROR
 
18
create table t2 (a int) engine = blitzdb;
 
19
 
 
20
show tables;
 
21
drop table t1, t2;
 
22
 
 
23
# INSERT SYNTAX
 
24
create table t1 (a int, b int, c varchar(255)) engine = blitzdb;
 
25
 
 
26
insert into t1 values (1, 8, "one");
 
27
select * from t1;
 
28
insert into t1 values (2, 7, "two");
 
29
insert into t1 values (3, 6, "three");
 
30
insert into t1 values (4, 5, "four");
 
31
insert into t1 values (5, 4, "five");
 
32
insert into t1 values (6, 3, "six");
 
33
insert into t1 values (7, 2, "seven");
 
34
insert into t1 values (8, 1, "eight");
 
35
select count(*) from t1;
 
36
 
 
37
# TABLE SCAN
 
38
select c from t1 where a = 4;
 
39
select c from t1 where a > 5;
 
40
select * from t1;
 
41
select * from t1 where a = 1 or b = 1;
 
42
select substring(c, 1, 3) from t1;
 
43
select substring(c, 1, 2) from t1;
 
44
select substring(c, 1, 1) from t1;
 
45
 
 
46
# UPDATE SYNTAX
 
47
update t1 set c = "first half" where a <= 4;
 
48
update t1 set c = "second half" where a > 4;
 
49
select * from t1;
 
50
 
 
51
# Delete Rows. Backup t1 to t2 first.
 
52
create table t2 (a int, b int, c varchar(255))
 
53
  engine = blitzdb (select * from t1);
 
54
 
 
55
show create table t2;
 
56
select count(*) from t2;
 
57
 
 
58
delete from t1 where c = "first half";
 
59
delete from t1 where c = "second half";
 
60
select count(*) from t1;
 
61
drop table t1;
 
62
 
 
63
rename table t2 to t1;
 
64
select * from t1;
 
65
drop table t1;
 
66
 
 
67
# UPDATE followed by ORDER BY on a keyless table.
 
68
create table t1 (id int) engine = blitzdb;
 
69
insert into t1 values (100), (100);
 
70
update t1 set id = id+1 ORDER BY id LIMIT 2;
 
71
update t1 set id = id+1 ORDER BY id LIMIT 2;
 
72
update t1 set id = id+1 ORDER BY id LIMIT 2;
 
73
update t1 set id = id+1 ORDER BY id LIMIT 2;
 
74
select * from t1;
 
75
drop table t1;
 
76
 
 
77
# Add and Drop columns with ALTER TABLE.
 
78
create table t1 (a int) engine = blitzdb;
 
79
insert into t1 values (1), (2), (3), (4);
 
80
alter table t1 add b int;
 
81
select * from t1;
 
82
update t1 set b = 1 where a = 1;
 
83
update t1 set b = 2 where a = 2;
 
84
update t1 set b = 3 where a = 3;
 
85
update t1 set b = 4 where a = 4;
 
86
select * from t1;
 
87
alter table t1 add c text;
 
88
update t1 set c = "added column" where a = 1;
 
89
update t1 set c = "added column" where a = 2;
 
90
update t1 set c = "added column" where a = 3;
 
91
update t1 set c = "added column" where a = 4;
 
92
select * from t1;
 
93
#alter table t1 drop a;
 
94
#alter table t1 drop b;
 
95
#select * from t1;
 
96
drop table t1;
 
97
 
 
98
# GROUP BY syntax.
 
99
create table t1 (name varchar(32), point int) engine = blitzdb;
 
100
insert into t1 values ('aaa', 10);
 
101
insert into t1 values ('bbb', 20);
 
102
insert into t1 values ('ccc', 30);
 
103
insert into t1 values ('aaa', 10);
 
104
insert into t1 values ('bbb', 20);
 
105
insert into t1 values ('ccc', 30);
 
106
insert into t1 values ('aaa', 10);
 
107
insert into t1 values ('bbb', 20);
 
108
insert into t1 values ('ccc', 30);
 
109
select * from t1;
 
110
select name, sum(point) from t1 group by name;
 
111
drop table t1;
 
112
 
 
113
# Test(9): Pattern Matching with LIKE syntax.
 
114
create table t1 (string varchar(255)) engine = blitzdb;
 
115
insert into t1 values('accompany'), ('balcony'), ('bunny'), ('company');
 
116
insert into t1 values('accompanied'), ('amazed'), ('busted'), ('decreased');
 
117
insert into t1 values('achiever'), ('blender'), ('ether'), ('launcher');
 
118
insert into t1 values('ampersand'), ('compound'), ('comprehend'), ('wand');
 
119
 
 
120
select * from t1 where string like '%ny';
 
121
select * from t1 where string like '%ed';
 
122
select * from t1 where string like '%er';
 
123
select * from t1 where string like '%nd';
 
124
 
 
125
select * from t1 where string like 'a%';
 
126
select * from t1 where string like 'ac%';
 
127
select * from t1 where string like 'acc%';
 
128
 
 
129
select * from t1 where string like '____';
 
130
select * from t1 where string like '_____';
 
131
select * from t1 where string like '___________';
 
132
drop table t1;
 
133
 
 
134
# NULL values
 
135
create table t1 (a int not null, b int) engine = blitzdb;
 
136
insert into t1 values (1, NULL), (2, NULL), (3, NULL), (4, NULL);
 
137
insert into t1 values (5, NULL), (6, NULL), (7, NULL), (8, NULL);
 
138
 
 
139
--error ER_BAD_NULL_ERROR # NOT NULL Violation
 
140
insert into t1 values (NULL, 1);
 
141
 
 
142
select * from t1;
 
143
select * from t1 where a is null;
 
144
select * from t1 where b is null;
 
145
drop table t1;
 
146
 
 
147
# Test (11): DATE type
 
148
create table t1 (name varchar(64), dob date) engine = blitzdb;
 
149
insert into t1 values ('Bernstein', '1971-10-29');
 
150
insert into t1 values ('Codd', '1923-08-23');
 
151
insert into t1 values ('Lovelace', '1815-12-10');
 
152
insert into t1 values ('Tower', '1949-06-17');
 
153
insert into t1 values ('Turing', '1912-06-23');
 
154
insert into t1 values ('Thompson', '1943-02-04');
 
155
select * from t1;
 
156
select name from t1 order by dob;
 
157
select name from t1 order by dob desc;
 
158
select name from t1 where dob < '1900-01-01';
 
159
select name from t1 where dob > '1950-01-01';
 
160
select name from t1 where dob = '1943-02-04';
 
161
drop table t1;
 
162
 
 
163
# Test(12): Boundary Check
 
164
create table t1 (a int) engine = blitzdb;
 
165
--error ER_WARN_DATA_OUT_OF_RANGE
 
166
insert into t1 values(2147483649);
 
167
--error ER_WARN_DATA_OUT_OF_RANGE
 
168
insert into t1 values(-2147483649);
 
169
insert into t1 values(2147483647);
 
170
select * from t1;
 
171
drop table t1;
 
172
 
 
173
# ASCII boundary 
 
174
create table t1 (a varchar(32)) engine = blitzdb; 
 
175
insert into t1 select repeat('x', 4);
 
176
insert into t1 select repeat('x', 6);
 
177
insert into t1 select repeat('x', 8);
 
178
insert into t1 select repeat('x', 16);
 
179
insert into t1 select repeat('x', 32);
 
180
--error ER_DATA_TOO_LONG
 
181
insert into t1 select repeat('x', 33);
 
182
select * from t1;
 
183
 
 
184
create table t2 (a varchar(16383)) engine = blitzdb; # Theoretical Max
 
185
insert into t2 select repeat('x', 16383);
 
186
--error ER_DATA_TOO_LONG
 
187
insert into t2 select repeat('x', 16384);
 
188
select count(*) from t2;
 
189
drop table t1, t2;
 
190
 
 
191
# Multibyte
 
192
create table t1 (a varchar(32)) engine = blitzdb; 
 
193
insert into t1 select repeat('あ', 8);
 
194
insert into t1 select repeat('あ', 32);
 
195
--error ER_DATA_TOO_LONG
 
196
insert into t1 select repeat('あ', 33);
 
197
select * from t1;
 
198
 
 
199
create table t2 (a varchar(16383)) engine = blitzdb;
 
200
insert into t2 select repeat('値', 16383);
 
201
--error ER_DATA_TOO_LONG
 
202
insert into t2 select repeat('値', 16384);
 
203
select count(*) from t2;
 
204
drop table t1, t2;
 
205
 
 
206
# INSERT by SELECT. 
 
207
create table t1 (a int, b varchar(255)) engine = blitzdb;
 
208
insert into t1 values (1, 'one'), (2, 'two'), (3, 'three'), (4, 'four');
 
209
insert into t1 values (5, 'five'), (6, 'six'), (7, 'seven'), (8, 'eight');
 
210
 
 
211
create table t2 (a int, b varchar(255), c double) engine = blitzdb;
 
212
insert into t2 (a, b) select a, b from t1 where a > 4;
 
213
insert into t2 (a) select a from t1 where a = 1;
 
214
select * from t2;
 
215
delete from t2;
 
216
 
 
217
insert into t2 (a, b) select * from t1;
 
218
select * from t2;
 
219
drop table t1;
 
220
 
 
221
# Large VARCHAR type (exceeds BlitzDB's stack space).
 
222
create table t1 (a int, b varchar(2048)) engine = blitzdb;
 
223
insert into t1 values (1, 'abcdefghijklmn');
 
224
insert into t1 values (1, 'abcdefghijklmn');
 
225
insert into t1 values (1, 'abcdefghijklmn');
 
226
insert into t1 values (1, 'abcdefghijklmn');
 
227
select * from t1;
 
228
drop table t1;