# 2023 August 7
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests for the content= and content_rowid= options.
#

source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5contentless5

# If SQLITE_ENABLE_FTS5 is defined, omit this file.
ifcapable !fts5 {
  finish_test
  return
}

do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, content='', contentless_delete=1);
  INSERT INTO t1 VALUES('A', 'B', 'C');
  INSERT INTO t1 VALUES('D', 'E', 'F');
  INSERT INTO t1 VALUES('G', 'H', 'I');
}

do_execsql_test 1.01 {
  CREATE TABLE t2(x, y);
  INSERT INTO t2 VALUES('x', 'y');
}

# explain_i "UPDATE t1 SET a='a' WHERE t1.rowid=1"    
breakpoint
explain_i "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1 AND b IS NULL"     

#breakpoint
#explain_i "UPDATE t1 SET a='a' WHERE b IS NULL AND rowid=?"

foreach {tn up err} {
  1   "UPDATE t1 SET a='a', b='b', c='c' WHERE rowid=1"                  0
  2   "UPDATE t1 SET a='a', b='b'        WHERE rowid=1"                  1
  3   "UPDATE t1 SET        b='b', c='c' WHERE rowid=1"                  1
  4   "UPDATE t1 SET a='a',        c='c' WHERE rowid=1"                  1
  5   "UPDATE t1 SET a='a',        c='c' WHERE t1.rowid=1 AND b IS NULL" 1
  6   "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1"                     1
  7   "UPDATE t1 SET a='a', b='b', c='c' FROM t2 WHERE t1.rowid=1"       0
} {

  set res(0) {0 {}}
  set res(1) {1 {cannot UPDATE a subset of columns on fts5 contentless-delete table: t1}}
  do_catchsql_test 1.$tn $up $res($err)
}

finish_test

