1
# Basic Test Routine for unindexed BlitzDB Tables
4
drop table if exists t1, t2;
8
create table t1 (a int, b double, c float) engine = blitzdb;
9
create table t2 (a int, b text, c blob) engine = blitzdb;
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;
24
create table t1 (a int, b int, c varchar(255)) engine = blitzdb;
26
insert into t1 values (1, 8, "one");
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;
38
select c from t1 where a = 4;
39
select c from t1 where a > 5;
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;
47
update t1 set c = "first half" where a <= 4;
48
update t1 set c = "second half" where a > 4;
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);
56
select count(*) from t2;
58
delete from t1 where c = "first half";
59
delete from t1 where c = "second half";
60
select count(*) from t1;
63
rename table t2 to t1;
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;
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;
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;
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;
93
#alter table t1 drop a;
94
#alter table t1 drop b;
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);
110
select name, sum(point) from t1 group by name;
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');
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';
125
select * from t1 where string like 'a%';
126
select * from t1 where string like 'ac%';
127
select * from t1 where string like 'acc%';
129
select * from t1 where string like '____';
130
select * from t1 where string like '_____';
131
select * from t1 where string like '___________';
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);
139
--error ER_BAD_NULL_ERROR # NOT NULL Violation
140
insert into t1 values (NULL, 1);
143
select * from t1 where a is null;
144
select * from t1 where b is null;
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');
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';
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);
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);
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;
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);
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;
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');
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;
217
insert into t2 (a, b) select * from t1;
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');