/ Check-in [80c299f8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Check the value of the schema cookie before reading the sqlite_master table. (CVS 1585)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:80c299f8839d920c61854f575498340b28db98d7
User & Date: danielk1977 2004-06-14 08:26:35
Context
2004-06-14
09:35
Ensure master journal file is deleted when a transaction is committed. (CVS 1586) check-in: cb3cbe00 user: danielk1977 tags: trunk
08:26
Check the value of the schema cookie before reading the sqlite_master table. (CVS 1585) check-in: 80c299f8 user: danielk1977 tags: trunk
06:13
Change tests in pager.test to account for the extra cache hit in the code that updates file change counter. (CVS 1584) check-in: 76ac9a78 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.
    14     14   **
    15         -** $Id: where.c,v 1.104 2004/06/10 10:51:48 danielk1977 Exp $
           15  +** $Id: where.c,v 1.105 2004/06/14 08:26:35 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** The query generator uses an array of instances of this structure to
    21     21   ** help it analyze the subexpressions of the WHERE clause.  Each WHERE
    22     22   ** clause subexpression is separated from the others by an AND operator.
................................................................................
   699    699       Index *pIx;
   700    700   
   701    701       pTab = pTabList->a[i].pTab;
   702    702       if( pTab->isTransient || pTab->pSelect ) continue;
   703    703       sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
   704    704       sqlite3VdbeAddOp(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum);
   705    705       sqlite3VdbeAddOp(v, OP_SetNumColumns, pTabList->a[i].iCursor, pTab->nCol);
   706         -    if( pTab->tnum>1 ){
   707         -      sqlite3CodeVerifySchema(pParse, pTab->iDb);
   708         -    }
          706  +    sqlite3CodeVerifySchema(pParse, pTab->iDb);
   709    707       if( (pIx = pWInfo->a[i].pIdx)!=0 ){
   710    708         sqlite3VdbeAddOp(v, OP_Integer, pIx->iDb, 0);
   711    709         sqlite3VdbeOp3(v, OP_OpenRead, pWInfo->a[i].iCur, pIx->tnum,
   712    710                        (char*)&pIx->keyInfo, P3_KEYINFO);
   713    711       }
   714    712     }
   715    713   

Changes to test/enc2.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The focus of
    12     12   # this file is testing the SQLite routines used for converting between the
    13     13   # various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
    14     14   # UTF-16be).
    15     15   #
    16         -# $Id: enc2.test,v 1.9 2004/06/13 23:07:04 drh Exp $
           16  +# $Id: enc2.test,v 1.10 2004/06/14 08:26:37 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
           20  +
           21  +# The rough organisation of tests in this file is:
           22  +#
           23  +# enc2.1.*: Simple tests with a UTF-8 db.
           24  +# enc2.2.*: Simple tests with a UTF-16LE db.
           25  +# enc2.3.*: Simple tests with a UTF-16BE db.
           26  +# enc2.4.*: Test that attached databases must have the same text encoding
           27  +#           as the main database.
           28  +# enc2.5.*: Test the behaviour of the library when a collation sequence is
           29  +#           not available for the most desirable text encoding.
           30  +# enc2.6.*: Test that the VerifyCookie opcode protects against assuming the
           31  +#           wrong text encoding for the database.
    20     32   
    21     33   db close
    22     34   
    23     35   # Return the UTF-8 representation of the supplied UTF-16 string $str. 
    24     36   proc utf8 {str} {
    25     37     # If $str ends in two 0x00 0x00 bytes, knock these off before
    26     38     # converting to UTF-8 using TCL.
................................................................................
   247    259   } {one two three four five UTF-16LE}
   248    260   breakpoint
   249    261   do_test enc2-5.11 {
   250    262     add_test_collate $DB 1 0 0
   251    263     set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
   252    264     lappend res $::test_collate_enc
   253    265   } {one two three four five UTF-8}
          266  +
          267  +db close
          268  +file delete -force test.db
          269  +
          270  +# The following tests - enc2-6.* - function as follows:
          271  +#
          272  +# 1: Open an empty database file assuming UTF-16 encoding.
          273  +# 2: Open the same database with a different handle assuming UTF-8. Create
          274  +#    a table using this handle.
          275  +# 3: Read the sqlite_master table from the first handle. 
          276  +# 4: Ensure the first handle recognises the database encoding is UTF-8.
          277  +#
          278  +do_test enc2-6.1 {
          279  +  sqlite db test.db
          280  +  execsql {
          281  +    PRAGMA encoding = 'UTF-16';
          282  +    SELECT * FROM sqlite_master;
          283  +  }
          284  +} {}
          285  +do_test enc2-6.2 {
          286  +  set enc [execsql {
          287  +    PRAGMA encoding;
          288  +  }]
          289  +  string range $enc 0 end-2 ;# Chop off the "le" or "be"
          290  +} {UTF-16}
          291  +do_test enc2-6.3 {
          292  +  sqlite db2 test.db
          293  +  execsql {
          294  +    PRAGMA encoding = 'UTF-8';
          295  +    CREATE TABLE abc(a, b, c);
          296  +  } db2
          297  +} {}
          298  +do_test enc2-6.4 {
          299  +  execsql {
          300  +    SELECT * FROM sqlite_master;
          301  +  }
          302  +} {table abc abc 2 {CREATE TABLE abc(a, b, c)}}
          303  +do_test enc2-6.5 {
          304  +  execsql {
          305  +    PRAGMA encoding;
          306  +  }
          307  +} {UTF-8}
          308  +
          309  +db close
          310  +db2 close
          311  +
   254    312   
   255    313   finish_test
          314  +
          315  +
          316  +
          317  +
          318  +

Changes to test/lock.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is database locks.
    13     13   #
    14         -# $Id: lock.test,v 1.24 2004/06/12 01:43:27 danielk1977 Exp $
           14  +# $Id: lock.test,v 1.25 2004/06/14 08:26:37 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Create an alternative connection to the database
    21     21   #
................................................................................
    39     39     } db2
    40     40   } {0 t1}
    41     41   
    42     42   do_test lock-1.6 {
    43     43     execsql {INSERT INTO t1 VALUES(1,2)}
    44     44     execsql {SELECT * FROM t1}
    45     45   } {1 2}
    46         -do_test lock-1.7.1 {
    47         -  catchsql {SELECT * FROM t1} db2
    48         -} {1 {no such table: t1}}
           46  +# Update: The schema is now brought up to date by test lock-1.5.
           47  +# do_test lock-1.7.1 {
           48  +#   catchsql {SELECT * FROM t1} db2
           49  +# } {1 {no such table: t1}}
    49     50   do_test lock-1.7.2 {
    50     51     catchsql {SELECT * FROM t1} db2
    51     52   } {0 {1 2}}
    52     53   do_test lock-1.8 {
    53     54     execsql {UPDATE t1 SET a=b, b=a} db2
    54     55     execsql {SELECT * FROM t1} db2
    55     56   } {2 1}

Changes to test/temptable.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for temporary tables and indices.
    14     14   #
    15         -# $Id: temptable.test,v 1.12 2004/06/10 10:51:53 danielk1977 Exp $
           15  +# $Id: temptable.test,v 1.13 2004/06/14 08:26:37 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Create an alternative connection to the database
    21     21   #
    22     22   do_test temptable-1.0 {
................................................................................
   233    233     }
   234    234   } {3 4}
   235    235   do_test temptable-4.10.1 {
   236    236     catchsql {
   237    237       SELECT * FROM t2;
   238    238     } db2
   239    239   } {0 {1 2}}
   240         -do_test temptable-4.10.2 {
   241         -  catchsql {
   242         -    SELECT name FROM sqlite_master WHERE type='table'
   243         -  } db2
   244         -} {1 {database schema has changed}}
          240  +# Update: The schema is reloaded in test temptable-4.10.1. And tclsqlite.c
          241  +#         handles it and retries the query anyway.
          242  +# do_test temptable-4.10.2 {
          243  +#   catchsql {
          244  +#     SELECT name FROM sqlite_master WHERE type='table'
          245  +#   } db2
          246  +# } {1 {database schema has changed}}
   245    247   do_test temptable-4.10.3 {
   246    248     catchsql {
   247    249       SELECT name FROM sqlite_master WHERE type='table'
   248    250     } db2
   249    251   } {0 {t1 t2}}
   250    252   do_test temptable-4.11 {
   251    253     execsql {

Changes to test/thread1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is multithreading behavior
    13     13   #
    14         -# $Id: thread1.test,v 1.5 2004/06/10 05:59:25 danielk1977 Exp $
           14  +# $Id: thread1.test,v 1.6 2004/06/14 08:26:37 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Skip this whole file if the thread testing code is not enabled
    21     21   #
................................................................................
    92     92   } SQLITE_OK
    93     93   do_test thread1-1.12 {
    94     94     catchsql {SELECT name FROM sqlite_master}
    95     95     execsql {SELECT name FROM sqlite_master}
    96     96   } {t1 t2}
    97     97   
    98     98   
    99         -# Under this scenario:
           99  +#
          100  +# The following tests - thread1-2.* - test the following scenario:
   100    101   #
   101         -#    read-lock A
   102         -#    read-lock B
   103         -#    unlock A
   104         -#    write-lock C
   105         -#
   106         -# Make sure the write-lock fails with SQLITE_BUSY 
          102  +# 1:  Read-lock thread A
          103  +# 2:  Read-lock thread B
          104  +# 3:  Attempt to write in thread C -> SQLITE_BUSY
          105  +# 4:  Check db write failed from main thread.
          106  +# 5:  Unlock from thread A.
          107  +# 6:  Attempt to write in thread C -> SQLITE_BUSY
          108  +# 7:  Check db write failed from main thread.
          109  +# 8:  Unlock from thread B.
          110  +# 9:  Attempt to write in thread C -> SQLITE_DONE
          111  +# 10: Finalize the write from thread C
          112  +# 11: Check db write succeeded from main thread.
   107    113   #
   108    114   do_test thread1-2.1 {
   109    115     thread_halt *
   110    116     thread_create A test.db
   111    117     thread_compile A {SELECT a FROM t1}
   112    118     thread_step A
   113    119     thread_result A