libdoltlite-sys 0.38.21

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 28-July-2023
#
#-------------------------------------------------------------------------
#

source [file join [file dirname [info script]] test_common.tcl]
set testprefix dmn_ro

#-------------------------------------------------------------------------
# 1.*: Test that containers can be attached and detached, and that this
#      is visible via virtual tables bcv_container and bcv_database 
#      on connections opened on path "/".
#

bcv_create_container cont1
bcv_upload_new_db cont1 t1.db {
  CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
  WITH s(i) AS (
    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
  )
  INSERT INTO t1 SELECT i, randomblob(500) FROM s;
}

start_new_daemon 0 
set cmd [bcvfs_create testdir.0 "bcvfs"]
bcvfs_attach $cmd cont1
sqlite3 db /cont1/t1.db -vfs bcvfs
sqlite3_bcvfs_register_vtab db

do_execsql_test 1.0 {
  SELECT count(y) FROM t1
} {10000}

db close
$cmd destroy
wait_daemon 0

start_daemon 0 
set cmd [bcvfs_create testdir.0 "bcvfs"]
# bcvfs_attach $cmd cont1

sqlite3 db /cont1/t1.db -vfs bcvfs -readonly 1
sqlite3_bcvfs_register_vtab db

do_execsql_test 1.1 {
  SELECT count(y) FROM t1
} {10000}

do_execsql_test 1.2 {
  BEGIN; 
    SELECT count(*) FROM t1 WHERE x = 100;
    SELECT count(*) FROM t1 WHERE x = 200;
    SELECT count(*) FROM t1 WHERE x = 300;
    SELECT count(*) FROM t1 WHERE x = 400;
    SELECT count(*) FROM t1 WHERE x = 500;
    SELECT count(*) FROM t1 WHERE x = 600;
    SELECT count(*) FROM t1 WHERE x = 700;
  END;
} {1 1 1 1 1 1 1}

wait_ms 1000
sqlite3 db2 file:/cont1/t1.db?readonly_shm=1 -uri 1 -vfs bcvfs 
db close

do_execsql2_test 1.3 {
  BEGIN; 
    SELECT count(*) FROM t1 WHERE x = 100;
    SELECT count(*) FROM t1 WHERE x = 200;
    SELECT count(*) FROM t1 WHERE x = 300;
    SELECT count(*) FROM t1 WHERE x = 400;
    SELECT count(*) FROM t1 WHERE x = 500;
    SELECT count(*) FROM t1 WHERE x = 600;
    SELECT count(*) FROM t1 WHERE x = 700;
  END;
} {1 1 1 1 1 1 1}

do_execsql2_test 1.4 {
  BEGIN; 
    SELECT count(*) FROM t1 WHERE x = 100;
    SELECT count(*) FROM t1 WHERE x = 200;
    SELECT count(*) FROM t1 WHERE x = 300;
    SELECT count(*) FROM t1 WHERE x = 400;
    SELECT count(*) FROM t1 WHERE x = 500;
    SELECT count(*) FROM t1 WHERE x = 600;
    SELECT count(*) FROM t1 WHERE x = 700;
  END;
} {1 1 1 1 1 1 1}

db2 close
$cmd destroy
wait_daemon 0

finish_test