mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-24 11:34:21 +01:00
- Make all constraints a list of WhereTerms in a ProcessedWhereClause - Support multiple joins instead of just one
149 lines
5.4 KiB
Tcl
Executable File
149 lines
5.4 KiB
Tcl
Executable File
#!/usr/bin/env tclsh
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
do_execsql_test cross-join {
|
|
select * from users, products limit 1;
|
|
} {1|Jamie|Foster|dylan00@example.com|496-522-9493|62375\ Johnson\ Rest\ Suite\ 322|West\ Lauriestad|IL|35865|94|1|hat|79.0}
|
|
|
|
do_execsql_test cross-join-specific-columns {
|
|
select first_name, price from users, products limit 1;
|
|
} {Jamie|79.0}
|
|
|
|
do_execsql_test cross-join-where-right-tbl {
|
|
select users.first_name, products.name from users join products where products.id = 1 limit 2;
|
|
} {Jamie|hat
|
|
Cindy|hat}
|
|
|
|
do_execsql_test cross-join-where-left-tbl {
|
|
select users.first_name, products.name from users join products where users.id = 1 limit 2;
|
|
} {Jamie|hat
|
|
Jamie|cap}
|
|
|
|
do_execsql_test inner-join-pk {
|
|
select users.first_name as user_name, products.name as product_name from users join products on users.id = products.id;
|
|
} {Jamie|hat
|
|
Cindy|cap
|
|
Tommy|shirt
|
|
Jennifer|sweater
|
|
Edward|sweatshirt
|
|
Nicholas|shorts
|
|
Aimee|jeans
|
|
Rachel|sneakers
|
|
Matthew|boots
|
|
Daniel|coat
|
|
Travis|accessories}
|
|
|
|
do_execsql_test inner-join-non-pk-unqualified {
|
|
select first_name, name from users join products on first_name != name limit 1;
|
|
} {Jamie|hat}
|
|
|
|
do_execsql_test inner-join-non-pk-qualified {
|
|
select users.first_name as user_name, products.name as product_name from users join products on users.first_name = products.name;
|
|
} {}
|
|
|
|
do_execsql_test inner-join-self {
|
|
select u1.first_name as user_name, u2.first_name as neighbor_name from users u1 join users as u2 on u1.id = u2.id + 1 limit 1;
|
|
} {Cindy|Jamie}
|
|
|
|
do_execsql_test inner-join-self-with-where {
|
|
select u1.first_name as user_name, u2.first_name as neighbor_name from users u1 join users as u2 on u1.id = u2.id + 1 where u1.id = 5 limit 1;
|
|
} {Edward|Jennifer}
|
|
|
|
# Uncomment this test when it works. Sqlite3 returns 'Aaron' due to the way it reorders tables in the join based on the where clause.
|
|
#do_execsql_test inner-join-with-where-2 {
|
|
# select u.first_name from users u join products as p on u.first_name != p.name where u.last_name = 'Williams' limit 1;
|
|
#} {Laura} <-- sqlite3 returns 'Aaron'
|
|
|
|
do_execsql_test left-join-pk {
|
|
select users.first_name as user_name, products.name as product_name from users left join products on users.id = products.id limit 12;
|
|
} {Jamie|hat
|
|
Cindy|cap
|
|
Tommy|shirt
|
|
Jennifer|sweater
|
|
Edward|sweatshirt
|
|
Nicholas|shorts
|
|
Aimee|jeans
|
|
Rachel|sneakers
|
|
Matthew|boots
|
|
Daniel|coat
|
|
Travis|accessories
|
|
Alan|}
|
|
|
|
do_execsql_test left-join-with-where {
|
|
select u.first_name, p.name from users u left join products as p on u.id = p.id where u.id >= 10 limit 5;
|
|
} {Daniel|coat
|
|
Travis|accessories
|
|
Alan|
|
|
Michael|
|
|
Brianna|}
|
|
|
|
do_execsql_test left-join-with-where-2 {
|
|
select users.first_name, products.name from users left join products on users.id < 2 where users.id < 3;
|
|
} {Jamie|hat
|
|
Jamie|cap
|
|
Jamie|shirt
|
|
Jamie|sweater
|
|
Jamie|sweatshirt
|
|
Jamie|shorts
|
|
Jamie|jeans
|
|
Jamie|sneakers
|
|
Jamie|boots
|
|
Jamie|coat
|
|
Jamie|accessories
|
|
Cindy|}
|
|
|
|
do_execsql_test left-join-non-pk {
|
|
select users.first_name as user_name, products.name as product_name from users left join products on users.first_name = products.name limit 3;
|
|
} {Jamie|
|
|
Cindy|
|
|
Tommy|}
|
|
|
|
do_execsql_test left-join-self {
|
|
select u1.first_name as user_name, u2.first_name as neighbor_name from users u1 left join users as u2 on u1.id = u2.id + 1 limit 2;
|
|
} {Jamie|
|
|
Cindy|Jamie}
|
|
|
|
do_execsql_test left-join-self-with-where {
|
|
select u1.first_name as user_name, u2.first_name as neighbor_name from users u1 left join users as u2 on u1.id = u2.id + 1 where u1.id = 5 limit 2;
|
|
} {Edward|Jennifer}
|
|
|
|
do_execsql_test left-join-multiple-cond-and {
|
|
select u.first_name, p.name from users u left join products as p on u.id = p.id and u.first_name = p.name limit 2;
|
|
} {Jamie|
|
|
Cindy|}
|
|
|
|
do_execsql_test left-join-multiple-cond-or {
|
|
select u.first_name, p.name from users u left join products as p on u.id = p.id or u.first_name = p.name limit 2;
|
|
} {Jamie|hat
|
|
Cindy|cap}
|
|
|
|
do_execsql_test left-join-no-join-conditions-but-multiple-where {
|
|
select u.first_name, p.name from users u left join products as p where u.id = p.id or u.first_name = p.name limit 2;
|
|
} {Jamie|hat
|
|
Cindy|cap}
|
|
|
|
do_execsql_test four-way-inner-join {
|
|
select u1.first_name, u2.first_name, u3.first_name, u4.first_name from users u1 join users u2 on u1.id = u2.id join users u3 on u2.id = u3.id + 1 join users u4 on u3.id = u4.id + 1 limit 1;
|
|
} {Tommy|Tommy|Cindy|Jamie}
|
|
|
|
do_execsql_test leftjoin-innerjoin-where {
|
|
select u.first_name, p.name, p2.name from users u left join products p on p.name = u.first_name join products p2 on length(p2.name) > 8 where u.first_name = 'Franklin';
|
|
} {Franklin||sweatshirt
|
|
Franklin||accessories}
|
|
|
|
do_execsql_test leftjoin-leftjoin-where {
|
|
select u.first_name, p.name, p2.name from users u left join products p on p.name = u.first_name join products p2 on length(p2.name) > 8 where u.first_name = 'Franklin';
|
|
} {Franklin||sweatshirt
|
|
Franklin||accessories}
|
|
|
|
do_execsql_test innerjoin-leftjoin-where {
|
|
select u.first_name, u2.first_name, p.name from users u join users u2 on u.id = u2.id + 1 left join products p on p.name = u.first_name where u.first_name = 'Franklin';
|
|
} {Franklin|Cynthia|}
|
|
|
|
do_execsql_test innerjoin-leftjoin-with-or-terms {
|
|
select u.first_name, u2.first_name, p.name from users u join users u2 on u.id = u2.id + 1 left join products p on p.name = u.first_name or p.name like 'sweat%' where u.first_name = 'Franklin';
|
|
} {Franklin|Cynthia|sweater
|
|
Franklin|Cynthia|sweatshirt}
|