mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-12-15 22:39:05 +00:00
ad79ef48a2
* add tests * add bench
93 lines
2.0 KiB
Plaintext
93 lines
2.0 KiB
Plaintext
|
|
CREATE TABLE t1(a, b, c);
|
|
CREATE TABLE x1(x, y, z);
|
|
CREATE TABLE x2(x, y, z);
|
|
|
|
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
|
INSERT INTO x1 VALUES(
|
|
new.a REGEXP 'abc',
|
|
new.b REGEXP 'abc',
|
|
new.c REGEXP 'abc'
|
|
);
|
|
END;
|
|
|
|
CREATE TRIGGER tr2 AFTER INSERT ON t1 BEGIN
|
|
INSERT INTO x2 VALUES(
|
|
new.a REGEXP 'def',
|
|
new.b REGEXP 'def',
|
|
new.c REGEXP 'def'
|
|
);
|
|
END;
|
|
|
|
INSERT INTO t1 VALUES('abc', 'def', 'abc');
|
|
SELECT * FROM t1;
|
|
|
|
SELECT * FROM x1
|
|
SELECT * FROM x2
|
|
|
|
CREATE TABLE t2(a, b);
|
|
CREATE TABLE t3(c, d);
|
|
CREATE TABLE t4(e, f);
|
|
|
|
CREATE TRIGGER t2_tr1 AFTER UPDATE ON t2 BEGIN
|
|
UPDATE t3 SET d = new.b WHERE c = old.a;
|
|
END;
|
|
|
|
CREATE TRIGGER t3_tr1 AFTER UPDATE ON t3 BEGIN
|
|
UPDATE t4 SET f = new.d WHERE e = old.c AND new.d REGEXP 'a.*';
|
|
END;
|
|
|
|
CREATE TRIGGER t4_tr1 AFTER UPDATE ON t4 BEGIN
|
|
SELECT CASE WHEN new.f REGEXP '.*y.*' THEN error() ELSE 1 END;
|
|
END;
|
|
|
|
INSERT INTO t2 VALUES(1, 'a_x_1');
|
|
INSERT INTO t2 VALUES(2, 'a_y_1');
|
|
|
|
INSERT INTO t3 VALUES(1, 'b1');
|
|
INSERT INTO t3 VALUES(2, 'b2');
|
|
|
|
INSERT INTO t4 VALUES(1, 'b1');
|
|
INSERT INTO t4 VALUES(2, 'b2');
|
|
|
|
|
|
UPDATE t2 SET b = 'a_abc_1';
|
|
|
|
|
|
SELECT * FROM t2;
|
|
SELECT * FROM t3;
|
|
SELECT * FROM t4;
|
|
|
|
|
|
CREATE TABLE t5(a);
|
|
CREATE TABLE t6(x);
|
|
|
|
CREATE TRIGGER t5tr AFTER DELETE ON t5 BEGIN
|
|
DELETE FROM t6 WHERE t6.x REGEXP old.a;
|
|
END;
|
|
|
|
INSERT INTO t5 VALUES ('^a.*'), ('^b.*'), ('^c.*');
|
|
INSERT INTO t6 VALUES ('eab'), ('abc'), ('bcd'), ('cde'), ('dea');
|
|
|
|
DELETE FROM t5;
|
|
SELECT * FROM t6;
|
|
|
|
SELECT 'abc' REGEXP '\W'
|
|
SELECT 'a c' REGEXP '\W'
|
|
SELECT ' ' REGEXP '\W'
|
|
SELECT 'abc' REGEXP '\w'
|
|
SELECT 'a c' REGEXP '\w'
|
|
SELECT ' ' REGEXP '\w'
|
|
SELECT 'abc' REGEXP '\D'
|
|
SELECT 'abc' REGEXP '[^a-z]'
|
|
SELECT 'a c' REGEXP '[^a-z]'
|
|
SELECT ' ' REGEXP '[^a-z]'
|
|
SELECT 'abc' REGEXP '[a-z]'
|
|
SELECT 'a c' REGEXP '[a-z]'
|
|
SELECT ' ' REGEXP '[a-z]'
|
|
SELECT 'abc' REGEXP '[^a-z]{2
|
|
SELECT 'a c' REGEXP '[^a-z]{2
|
|
SELECT ' ' REGEXP '[^a-z]{2
|
|
SELECT 'abc' REGEXP '\W{1,1
|
|
SELECT 'abc' REGEXP '\W{1
|