1# 2011 March 24 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# This file implements regression tests for the session module. 12# 13 14if {![info exists testdir]} { 15 set testdir [file join [file dirname [info script]] .. .. test] 16} 17source [file join [file dirname [info script]] session_common.tcl] 18source $testdir/tester.tcl 19 20set testprefix session3 21 22# These tests - session3-1.* - verify that the session module behaves 23# correctly when confronted with a schema mismatch when applying a 24# changeset (in function sqlite3changeset_apply()). 25# 26# session3-1.1.*: Table does not exist in target db. 27# session3-1.2.*: Table has wrong number of columns in target db. 28# session3-1.3.*: Table has wrong PK columns in target db. 29# 30 31db close 32sqlite3_shutdown 33test_sqlite3_log log 34sqlite3 db test.db 35 36proc log {code msg} { lappend ::log $code $msg } 37 38forcedelete test.db2 39sqlite3 db2 test.db2 40 41do_execsql_test 1.0 { 42 CREATE TABLE t1(a PRIMARY KEY, b); 43} 44do_test 1.1 { 45 set ::log {} 46 do_then_apply_sql { 47 INSERT INTO t1 VALUES(1, 2); 48 INSERT INTO t1 VALUES(3, 4); 49 } 50 set ::log 51} {SQLITE_SCHEMA {sqlite3changeset_apply(): no such table: t1}} 52 53do_test 1.2.0 { 54 execsql { CREATE TABLE t1(a PRIMARY KEY, b, c) } db2 55} {} 56do_test 1.2.1 { 57 set ::log {} 58 do_then_apply_sql { 59 INSERT INTO t1 VALUES(5, 6); 60 INSERT INTO t1 VALUES(7, 8); 61 } 62 set ::log 63} {SQLITE_SCHEMA {sqlite3changeset_apply(): table t1 has 3 columns, expected 2}} 64 65do_test 1.3.0 { 66 execsql { 67 DROP TABLE t1; 68 CREATE TABLE t1(a, b PRIMARY KEY); 69 } db2 70} {} 71do_test 1.3.1 { 72 set ::log {} 73 do_then_apply_sql { 74 INSERT INTO t1 VALUES(9, 10); 75 INSERT INTO t1 VALUES(11, 12); 76 } 77 set ::log 78} {SQLITE_SCHEMA {sqlite3changeset_apply(): primary key mismatch for table t1}} 79 80 81catch { db close } 82catch { db2 close } 83sqlite3_shutdown 84test_sqlite3_log 85sqlite3_initialize 86 87finish_test 88 89