⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pragma.test

📁 最新的sqlite3.6.2源代码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
#ifcapable schema_version {# First check that we can set the schema version and then retrieve the# same value.do_test pragma-8.1.1 {  execsql {    PRAGMA schema_version = 105;  }} {}do_test pragma-8.1.2 {  execsql2 {    PRAGMA schema_version;  }} {schema_version 105}do_test pragma-8.1.3 {  execsql {    PRAGMA schema_version = 106;  }} {}do_test pragma-8.1.4 {  execsql {    PRAGMA schema_version;  }} 106# Check that creating a table modifies the schema-version (this is really# to verify that the value being read is in fact the schema version).do_test pragma-8.1.5 {  execsql {    CREATE TABLE t4(a, b, c);    INSERT INTO t4 VALUES(1, 2, 3);    SELECT * FROM t4;  }} {1 2 3}do_test pragma-8.1.6 {  execsql {    PRAGMA schema_version;  }} 107# Now open a second connection to the database. Ensure that changing the# schema-version using the first connection forces the second connection# to reload the schema. This has to be done using the C-API test functions,# because the TCL API accounts for SCHEMA_ERROR and retries the query.do_test pragma-8.1.7 {  sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]  execsql {    SELECT * FROM t4;  } db2} {1 2 3}do_test pragma-8.1.8 {  execsql {    PRAGMA schema_version = 108;  }} {}do_test pragma-8.1.9 {  set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]  sqlite3_step $::STMT} SQLITE_ERRORdo_test pragma-8.1.10 {  sqlite3_finalize $::STMT} SQLITE_SCHEMA# Make sure the schema-version can be manipulated in an attached database.file delete -force test2.dbfile delete -force test2.db-journalifcapable attach {  do_test pragma-8.1.11 {    execsql {      ATTACH 'test2.db' AS aux;      CREATE TABLE aux.t1(a, b, c);      PRAGMA aux.schema_version = 205;    }  } {}  do_test pragma-8.1.12 {    execsql {      PRAGMA aux.schema_version;    }  } 205}do_test pragma-8.1.13 {  execsql {    PRAGMA schema_version;  }} 108# And check that modifying the schema-version in an attached database# forces the second connection to reload the schema.ifcapable attach {  do_test pragma-8.1.14 {    sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]    execsql {      ATTACH 'test2.db' AS aux;      SELECT * FROM aux.t1;    } db2  } {}  do_test pragma-8.1.15 {    execsql {      PRAGMA aux.schema_version = 206;    }  } {}  do_test pragma-8.1.16 {    set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]    sqlite3_step $::STMT  } SQLITE_ERROR  do_test pragma-8.1.17 {    sqlite3_finalize $::STMT  } SQLITE_SCHEMA  do_test pragma-8.1.18 {    db2 close  } {}}# Now test that the user-version can be read and written (and that we aren't# accidentally manipulating the schema-version instead).do_test pragma-8.2.1 {  execsql2 {    PRAGMA user_version;  }} {user_version 0}do_test pragma-8.2.2 {  execsql {    PRAGMA user_version = 2;  }} {}do_test pragma-8.2.3.1 {  execsql2 {    PRAGMA user_version;  }} {user_version 2}do_test pragma-8.2.3.2 {  db close  sqlite3 db test.db  execsql {    PRAGMA user_version;  }} {2}do_test pragma-8.2.4.1 {  execsql {    PRAGMA schema_version;  }} {108}ifcapable vacuum {  do_test pragma-8.2.4.2 {    execsql {      VACUUM;      PRAGMA user_version;    }  } {2}  do_test pragma-8.2.4.3 {    execsql {      PRAGMA schema_version;    }  } {109}}ifcapable attach {  db eval {ATTACH 'test2.db' AS aux}    # Check that the user-version in the auxilary database can be manipulated (  # and that we aren't accidentally manipulating the same in the main db).  do_test pragma-8.2.5 {    execsql {      PRAGMA aux.user_version;    }  } {0}  do_test pragma-8.2.6 {    execsql {      PRAGMA aux.user_version = 3;    }  } {}  do_test pragma-8.2.7 {    execsql {      PRAGMA aux.user_version;    }  } {3}  do_test pragma-8.2.8 {    execsql {      PRAGMA main.user_version;    }  } {2}    # Now check that a ROLLBACK resets the user-version if it has been modified  # within a transaction.  do_test pragma-8.2.9 {    execsql {      BEGIN;      PRAGMA aux.user_version = 10;      PRAGMA user_version = 11;    }  } {}  do_test pragma-8.2.10 {    execsql {      PRAGMA aux.user_version;    }  } {10}  do_test pragma-8.2.11 {    execsql {      PRAGMA main.user_version;    }  } {11}  do_test pragma-8.2.12 {    execsql {      ROLLBACK;      PRAGMA aux.user_version;    }  } {3}  do_test pragma-8.2.13 {    execsql {      PRAGMA main.user_version;    }  } {2}}# Try a negative value for the user-versiondo_test pragma-8.2.14 {  execsql {    PRAGMA user_version = -450;  }} {}do_test pragma-8.2.15 {  execsql {    PRAGMA user_version;  }} {-450}} ; # ifcapable schema_version# Check to see if TEMP_STORE is memory or disk.  Return strings# "memory" or "disk" as appropriate.#proc check_temp_store {} {  db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}  db eval {PRAGMA database_list} {    if {$name=="temp"} {      set bt [btree_from_db db 1]      if {[btree_ismemdb $bt]} {        return "memory"      }      return "disk"    }  }  return "unknown"}# Test temp_store and temp_store_directory pragmas#ifcapable pager_pragmas {do_test pragma-9.1 {  db close  sqlite3 db test.db  execsql {    PRAGMA temp_store;  }} {0}if {$TEMP_STORE<=1} {  do_test pragma-9.1.1 {    check_temp_store  } {disk}} else {  do_test pragma-9.1.1 {    check_temp_store  } {memory}}do_test pragma-9.2 {  db close  sqlite3 db test.db  execsql {    PRAGMA temp_store=file;    PRAGMA temp_store;  }} {1}if {$TEMP_STORE==3} {  # When TEMP_STORE is 3, always use memory regardless of pragma settings.  do_test pragma-9.2.1 {    check_temp_store  } {memory}} else {  do_test pragma-9.2.1 {    check_temp_store  } {disk}}do_test pragma-9.3 {  db close  sqlite3 db test.db  execsql {    PRAGMA temp_store=memory;    PRAGMA temp_store;  }} {2}if {$TEMP_STORE==0} {  # When TEMP_STORE is 0, always use the disk regardless of pragma settings.  do_test pragma-9.3.1 {    check_temp_store  } {disk}} else {  do_test pragma-9.3.1 {    check_temp_store  } {memory}}do_test pragma-9.4 {  execsql {    PRAGMA temp_store_directory;  }} {}do_test pragma-9.5 {  set pwd [string map {' ''} [pwd]]  execsql "    PRAGMA temp_store_directory='$pwd';  "} {}do_test pragma-9.6 {  execsql {     PRAGMA temp_store_directory;  }} [list [pwd]]do_test pragma-9.7 {  catchsql {     PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';  }} {1 {not a writable directory}}do_test pragma-9.8 {  execsql {     PRAGMA temp_store_directory='';  }} {}if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {  ifcapable tempdb {    do_test pragma-9.9 {      execsql {         PRAGMA temp_store_directory;        PRAGMA temp_store=FILE;        CREATE TEMP TABLE temp_store_directory_test(a integer);        INSERT INTO temp_store_directory_test values (2);        SELECT * FROM temp_store_directory_test;      }    } {2}    do_test pragma-9.10 {      catchsql "        PRAGMA temp_store_directory='$pwd';        SELECT * FROM temp_store_directory_test;      "    } {1 {no such table: temp_store_directory_test}}  }}  do_test pragma-9.11 {  execsql {    PRAGMA temp_store = 0;    PRAGMA temp_store;  }} {0}do_test pragma-9.12 {  execsql {    PRAGMA temp_store = 1;    PRAGMA temp_store;  }} {1}do_test pragma-9.13 {  execsql {    PRAGMA temp_store = 2;    PRAGMA temp_store;  }} {2}do_test pragma-9.14 {  execsql {    PRAGMA temp_store = 3;    PRAGMA temp_store;  }} {0}do_test pragma-9.15 {  catchsql {    BEGIN EXCLUSIVE;    CREATE TEMP TABLE temp_table(t);    INSERT INTO temp_table VALUES('valuable data');    PRAGMA temp_store = 1;  }} {1 {temporary storage cannot be changed from within a transaction}}do_test pragma-9.16 {  execsql {    SELECT * FROM temp_table;    COMMIT;  }} {{valuable data}}do_test pragma-9.17 {  execsql {    INSERT INTO temp_table VALUES('valuable data II');    SELECT * FROM temp_table;  }} {{valuable data} {valuable data II}}do_test pragma-9.18 {  set rc [catch {    db eval {SELECT t FROM temp_table} {      execsql {pragma temp_store = 1}    }  } msg]  list $rc $msg} {1 {temporary storage cannot be changed from within a transaction}}} ;# ifcapable pager_pragmasifcapable trigger {do_test pragma-10.0 {  catchsql {    DROP TABLE main.t1;  }  execsql {    PRAGMA count_changes = 1;    CREATE TABLE t1(a PRIMARY KEY);    CREATE TABLE t1_mirror(a);    CREATE TABLE t1_mirror2(a);    CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN       INSERT INTO t1_mirror VALUES(new.a);    END;    CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN       INSERT INTO t1_mirror2 VALUES(new.a);    END;    CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN       UPDATE t1_mirror SET a = new.a WHERE a = old.a;    END;    CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN       UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;    END;    CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN       DELETE FROM t1_mirror WHERE a = old.a;    END;    CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN       DELETE FROM t1_mirror2 WHERE a = old.a;    END;  }} {}do_test pragma-10.1 {  execsql {    INSERT INTO t1 VALUES(randstr(10,10));  }} {1}do_test pragma-10.2 {  execsql {    UPDATE t1 SET a = randstr(10,10);  }} {1}do_test pragma-10.3 {  execsql {    DELETE FROM t1;  }} {1}} ;# ifcapable triggerifcapable schema_pragmas {  do_test pragma-11.1 {    execsql2 {      pragma collation_list;    }  } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}  do_test pragma-11.2 {    db collate New_Collation blah...    execsql {      pragma collation_list;    }  } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}}ifcapable schema_pragmas&&tempdb {  do_test pragma-12.1 {    sqlite3 db2 test.db    execsql {      PRAGMA temp.table_info('abc');    } db2  } {}  db2 close  do_test pragma-12.2 {    sqlite3 db2 test.db    execsql {      PRAGMA temp.default_cache_size = 200;      PRAGMA temp.default_cache_size;    } db2  } {200}  db2 close  do_test pragma-12.3 {    sqlite3 db2 test.db    execsql {      PRAGMA temp.cache_size = 400;      PRAGMA temp.cache_size;    } db2  } {400}  db2 close}ifcapable bloblit {do_test pragma-13.1 {  execsql {    DROP TABLE IF EXISTS t4;    PRAGMA vdbe_trace=on;    PRAGMA vdbe_listing=on;    PRAGMA sql_trace=on;    CREATE TABLE t4(a INTEGER PRIMARY KEY,b);    INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');    INSERT INTO t4(b) VALUES(randstr(30,30));    INSERT INTO t4(b) VALUES(1.23456);    INSERT INTO t4(b) VALUES(NULL);    INSERT INTO t4(b) VALUES(0);    INSERT INTO t4(b) SELECT b||b||b||b FROM t4;    SELECT * FROM t4;  }  execsql {    PRAGMA vdbe_trace=off;    PRAGMA vdbe_listing=off;    PRAGMA sql_trace=off;  }} {}} ;# ifcapable bloblit ifcapable pager_pragmas {  db close  file delete -force test.db  sqlite3 db test.db  do_test pragma-14.1 {    execsql { pragma auto_vacuum = 0 }    execsql { pragma page_count }  } {0}  do_test pragma-14.2 {    execsql {       CREATE TABLE abc(a, b, c);      PRAGMA page_count;    }  } {2}  do_test pragma-14.3 {    execsql {       BEGIN;      CREATE TABLE def(a, b, c);      PRAGMA page_count;    }  } {3}  do_test pragma-14.4 {    set page_size [db one {pragma page_size}]    expr [file size test.db] / $page_size  } {2}  do_test pragma-14.5 {    execsql {      ROLLBACK;      PRAGMA page_count;    }  } {2}  do_test pragma-14.6 {    file delete -force test2.db    sqlite3 db2 test2.db    execsql {      PRAGMA auto_vacuum = 0;      CREATE TABLE t1(a, b, c);      CREATE TABLE t2(a, b, c);      CREATE TABLE t3(a, b, c);      CREATE TABLE t4(a, b, c);    } db2    db2 close    execsql {      ATTACH 'test2.db' AS aux;      PRAGMA aux.page_count;    }   } {5}}# Test that the value set using the cache_size pragma is not reset when the# schema is reloaded.#ifcapable pager_pragmas {  db close  sqlite3 db test.db  do_test pragma-15.1 {    execsql {      PRAGMA cache_size=59;      PRAGMA cache_size;    }  } {59}  do_test pragma-15.2 {    sqlite3 db2 test.db    execsql {      CREATE TABLE newtable(a, b, c);    } db2    db2 close  } {}  do_test pragma-15.3 {    # Evaluating this statement will cause the schema to be reloaded (because    # the schema was changed by another connection in pragma-15.2). At one    # point there was a bug that reset the cache_size to its default value    # when this happened.     execsql { SELECT * FROM sqlite_master }    execsql { PRAGMA cache_size }  } {59}}# Reset the sqlite3_temp_directory variable for the next run of tests:sqlite3 dbX :memory:dbX eval {PRAGMA temp_store_directory = ""}dbX closefinish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -