libdoltlite-sys 0.38.26

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 08-Feb-2022
#
#-------------------------------------------------------------------------
#

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

bcv_create_container cont1
bcv_upload_new_db cont1 t1.db {
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES('fox', 'guard');
}

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

do_test 1.0 {
  sqlite3 db /cont1/t1.db -vfs bcvfs
  sqlite3_bcvfs_register_vtab db
  set {} {}
} {}

do_execsql_test 1.1 {
  SELECT * FROM t1
} {fox guard}

do_execsql_test 1.2 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 1 1 0 0 {} 1 0 1
}

bcv_upload_new_db cont1 t2.db {
  CREATE TABLE t2(a, b);
  INSERT INTO t2 VALUES('a', 'b');
}

do_execsql_test 1.3 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 1 1 0 0 {} 1 0 1
}

$::cmd poll cont1
do_execsql_test 1.4 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 1 1 0 0 {} 1 0 1
  cont1 t2.db 1 0 0 0 {} 0 0 0
}

bcv_mkdir testdir
set cmd2 [bcvfs_create testdir bcvfs2]
bcvfs_attach $cmd2 cont1
sqlite3 db2 /cont1/t1.db -vfs bcvfs2

do_execsql2_test 1.5 {
  INSERT INTO t1 VALUES('hen', 'house');
  PRAGMA bcv_upload;
}

db2 close
$cmd2 destroy

do_execsql_test 1.6 { SELECT * FROM t1 } { fox guard }
$::cmd poll cont1
do_execsql_test 1.7 { SELECT * FROM t1 } { fox guard hen house }

do_catchsql_test 1.8 { 
  INSERT INTO t1 VALUES('a', 'b');
} {1 {attempt to write a readonly database}}

do_test 1.9 { 
  $::cmd upload cont1
} {}
do_test 1.10 { 
  $::cmd upload nosuchcont
} {}

catch { db close }
$cmd destroy
wait_daemon 0

finish_test