limbo/testing/update.test
Jussi Saurio 30e4511d62
Some checks failed
Python / sdist (push) Has been cancelled
Build and push limbo-sim image / deploy (push) Has been cancelled
Go Tests / test (push) Has been cancelled
Java Tests / test (push) Has been cancelled
JavaScript / stable - aarch64-apple-darwin - node@20 (push) Has been cancelled
Python / macos-arm64 (aarch64) (push) Has been cancelled
JavaScript / stable - x86_64-apple-darwin - node@20 (push) Has been cancelled
JavaScript / stable - x86_64-pc-windows-msvc - node@20 (push) Has been cancelled
JavaScript / stable - x86_64-unknown-linux-gnu - node@20 (push) Has been cancelled
Rust / cargo-fmt-check (push) Has been cancelled
Python / configure-strategy (push) Has been cancelled
Python / lint (push) Has been cancelled
Python / check-requirements (push) Has been cancelled
Python / linux (x86_64) (push) Has been cancelled
Python / macos-x86_64 (x86_64) (push) Has been cancelled
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Rust / build-native (macos-latest) (push) Has been cancelled
Rust / build-native (windows-latest) (push) Has been cancelled
Rust / clippy (push) Has been cancelled
Rust / build-wasm (push) Has been cancelled
Rust / test-limbo (push) Has been cancelled
Rust / test-sqlite (push) Has been cancelled
Rust Benchmarks+Nyrkiö / bench (push) Has been cancelled
Rust Benchmarks+Nyrkiö / clickbench (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h (push) Has been cancelled
JavaScript / Test bindings on x86_64-apple-darwin - node@18 (push) Has been cancelled
JavaScript / Test bindings on x86_64-apple-darwin - node@20 (push) Has been cancelled
JavaScript / Test bindings on Linux-x64-gnu - node@18 (push) Has been cancelled
JavaScript / Test bindings on Linux-x64-gnu - node@20 (push) Has been cancelled
JavaScript / Build universal macOS binary (push) Has been cancelled
JavaScript / Publish (push) Has been cancelled
Python / test (push) Has been cancelled
Python / Release (push) Has been cancelled
Merge 'NOT NULL constraint' from Anton Harniakou
Implements basic support for `NOT NULL` contraint check.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1675
2025-06-13 14:25:24 +03:00

214 lines
6.2 KiB
Tcl
Executable file

#!/usr/bin/env tclsh
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_execsql_test_on_specific_db {:memory:} basic-update {
create table temp (t1 integer);
insert into temp values (1);
update temp set t1 = 2;
select * from temp;
} {2}
do_execsql_test_on_specific_db {:memory:} update-mul {
create table temp (t1 integer);
insert into temp values (1),(2.0),('3'),('4.0');
update temp set t1 = 2;
select * from temp;
} {2
2
2
2}
do_execsql_test_on_specific_db {:memory:} update-where {
create table temp (a,b,c);
insert into temp values (1,2,33);
insert into temp values (1,22,33);
insert into temp values (1,22,33);
update temp set a = 6 where b = 2;
select * from temp;
} {6|2|33
1|22|33
1|22|33}
do_execsql_test_on_specific_db {:memory:} update-where-2 {
create table temp (a,b,c);
insert into temp values (1,22,33);
insert into temp values (1,22,33);
insert into temp values (1,22,33);
insert into temp values (6,22,33);
insert into temp values (1,22,33);
insert into temp values (1,22,33);
update temp set b = 100000 where a = 6;
select b from temp where a = 6;
} {100000}
do_execsql_test_on_specific_db {:memory:} update-all-many {
create table temp (a,b,c);
insert into temp values (1,22,33),(1,22,33),(1,22,33),(1,22,33),(1,22,33),(1,22,33),(1,22,33),(1,22,33);
update temp set a = 1234234234234234;
select COUNT(*) from temp where a = 1234234234234234;
} {8}
do_execsql_test_on_specific_db {:memory:} update-large-small {
create table temp (a,b,c);
insert into temp values (randomblob(1024), 1, 2);
update temp set a = 'a';
select * from temp;
} {a|1|2}
do_execsql_test_on_specific_db {:memory:} update-null {
create table temp (a,b,c);
insert into temp values (NULL, 1, 2);
insert into temp values (3, 4, 5);
update temp set a = 10 where a IS NULL;
select * from temp;
} {10|1|2
3|4|5}
do_execsql_test_on_specific_db {:memory:} update-not-null-1 {
create table temp (a,b not null,c);
insert into temp values (1, 2, 3);
update temp set b = 999;
select * from temp;
} {1|999|3}
do_execsql_test_in_memory_any_error update-not-null-2 {
create table temp (a,b not null,c);
insert into temp values (1, 2, 3);
update temp set b = NULL;
}
do_execsql_test_on_specific_db {:memory:} update-not-null-3 {
create table temp (a not null, b not null, c not null);
update temp set a = null, b = null, c = null;
select * from temp;
} {}
do_execsql_test_on_specific_db {:memory:} update-mixed-types {
create table temp (a);
insert into temp values (1);
insert into temp values ('2');
insert into temp values (3.0);
insert into temp values (X'01');
update temp set a = 'updated';
select * from temp;
} {updated
updated
updated
updated}
do_execsql_test_on_specific_db {:memory:} update-with-expression {
create table temp (a, b);
insert into temp values (1, 10);
insert into temp values (2, 20);
insert into temp values (3, 30);
update temp set a = b * 3 / 2;
select * from temp;
} {15|10
30|20
45|30}
do_execsql_test_on_specific_db {:memory:} update-self-reference {
create table temp (a, b);
insert into temp values (1, 10);
insert into temp values (2, 20);
update temp set a = b where a = 1;
select * from temp;
} {10|10
2|20}
do_execsql_test_on_specific_db {:memory:} update-self-ref-all {
create table temp (a, b, c);
insert into temp values (1, 2, 3);
insert into temp values (4, 5, 6);
update temp set a = b;
select * from temp;
} {2|2|3
5|5|6}
do_execsql_test_on_specific_db {:memory:} update-large-text {
create table temp (a);
insert into temp values ('short');
update temp set a = 'this is a very large text field that exceeds the default cell size and should trigger overflow handling in the btree implementation';
select * from temp;
} {{this is a very large text field that exceeds the default cell size and should trigger overflow handling in the btree implementation}}
do_execsql_test_on_specific_db {:memory:} update-with-null-condition {
create table temp (a, b);
insert into temp values (NULL, 1);
insert into temp values (2, NULL);
insert into temp values (3, 4);
update temp set a = 99 where b IS NULL;
select * from temp;
} {|1
99|
3|4}
do_execsql_test_on_specific_db {:memory:} update-to-null {
create table temp (a, b);
insert into temp values (1, 10);
insert into temp values (2, 20);
update temp set a = NULL where b = 10;
select * from temp;
} {|10
2|20}
do_execsql_test_on_specific_db {:memory:} update-with-randomblob {
create table temp (a, b);
insert into temp values (randomblob(100), 1);
update temp set a = randomblob(200);
select length(a) from temp;
} {200}
do_execsql_test_on_specific_db {:memory:} update-multiple-columns {
create table temp (a, b, c);
insert into temp values (1, 2, 3);
insert into temp values (4, 5, 6);
update temp set a = 10, b = 20, c = 30;
select * from temp;
} {10|20|30
10|20|30}
do_execsql_test_on_specific_db {:memory:} update-true-expr {
create table temp (a, b, c);
insert into temp values (1, 2, 3);
insert into temp values (4, 5, 6);
update temp set a = 10, b = 20, c = 30 where 1;
select * from temp;
} {10|20|30
10|20|30}
# https://github.com/tursodatabase/limbo/issues/1625
do_execsql_test_on_specific_db {:memory:} update_cache_full_regression_test_#1625 {
CREATE TABLE t(x);
INSERT INTO t VALUES (randomblob(4096));
UPDATE t SET x = randomblob(4096) WHERE rowid = 1;
SELECT count(*) FROM t;
} {1}
do_execsql_test_on_specific_db {:memory:} update_index_regression_test {
CREATE TABLE t(x, y);
CREATE INDEX tx ON t (x);
CREATE UNIQUE INDEX tyu ON t (y);
INSERT INTO t VALUES (1, 1);
SELECT x FROM t; -- uses tx index
SELECT y FROM t; -- uses ty index
UPDATE t SET x=2, y=2;
SELECT x FROM t; -- uses tx index
SELECT y FROM t; -- uses ty index
} {1
1
2
2}
do_execsql_test_on_specific_db {:memory:} update_where_or_regression_test {
CREATE TABLE t (a INTEGER);
INSERT INTO t VALUES (1), ('hi');
UPDATE t SET a = X'6C6F76656C795F7265766F6C74' WHERE ~ 'gorgeous_thropy' OR NOT -3830873834.233324;
SELECT * from t;
} {lovely_revolt
lovely_revolt}