/ Check-in [a07143fc]
Login

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

Overview
Comment:Invalidate prepared SQL statements when rolling back a transaction that includes schema modifications. (CVS 4216)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a07143fc0578a5fc7c891e94616ee0b353674d6e
User & Date: danielk1977 2007-08-13 15:28:34
Context
2007-08-13
16:15
Update version number of documentation in preparation for version 3.4.2. (CVS 4217) check-in: 1ed51e3c user: drh tags: trunk
15:28
Invalidate prepared SQL statements when rolling back a transaction that includes schema modifications. (CVS 4216) check-in: a07143fc user: danielk1977 tags: trunk
15:18
Disable tests that require 80-bit long doubles when the host only provides 64-bit long doubles. Ticket #2570. (CVS 4215) check-in: 4f4f8ef4 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
236
237
238
239
240
241
242

243
244
245
246
247
248
249
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.377 2007/06/22 15:21:16 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The version of the library
................................................................................
      }
      sqlite3BtreeRollback(db->aDb[i].pBt);
      db->aDb[i].inTrans = 0;
    }
  }
  sqlite3VtabRollback(db);
  if( db->flags&SQLITE_InternChanges ){

    sqlite3ResetInternalSchema(db, 0);
  }

  /* If one has been configured, invoke the rollback-hook callback */
  if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
    db->xRollbackCallback(db->pRollbackArg);
  }







|







 







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.378 2007/08/13 15:28:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The version of the library
................................................................................
      }
      sqlite3BtreeRollback(db->aDb[i].pBt);
      db->aDb[i].inTrans = 0;
    }
  }
  sqlite3VtabRollback(db);
  if( db->flags&SQLITE_InternChanges ){
    sqlite3ExpirePreparedStatements(db);
    sqlite3ResetInternalSchema(db, 0);
  }

  /* If one has been configured, invoke the rollback-hook callback */
  if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
    db->xRollbackCallback(db->pRollbackArg);
  }

Changes to test/misc4.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
36
37
38
39
40
41
42












43
44
45
46
47
48
49
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc4.test,v 1.21 2006/01/03 00:33:50 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Prepare a statement that will create a temporary table.  Then do
# a rollback.  Then try to execute the prepared statement.
#
................................................................................
    execsql {
      BEGIN;
      CREATE TABLE t3(a,b,c);
      INSERT INTO t1 SELECT * FROM t1;
      ROLLBACK;
    }
  } {}












  do_test misc4-1.3 {
    sqlite3_step $stmt
  } SQLITE_DONE
  do_test misc4-1.4 {
    execsql {
      SELECT * FROM temp.t2;
    }







|







 







>
>
>
>
>
>
>
>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc4.test,v 1.22 2007/08/13 15:28:35 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Prepare a statement that will create a temporary table.  Then do
# a rollback.  Then try to execute the prepared statement.
#
................................................................................
    execsql {
      BEGIN;
      CREATE TABLE t3(a,b,c);
      INSERT INTO t1 SELECT * FROM t1;
      ROLLBACK;
    }
  } {}

  # Because the previous transaction included a DDL statement and
  # was rolled back, statement $stmt was marked as expired. Executing it
  # now returns SQLITE_SCHEMA.
  do_test misc4-1.2.1 {
    list [sqlite3_step $stmt] [sqlite3_finalize $stmt]
  } {SQLITE_ERROR SQLITE_SCHEMA}
  do_test misc4-1.2.2 {
    set stmt [sqlite3_prepare $DB $sql -1 TAIL]
    set TAIL
  } {}

  do_test misc4-1.3 {
    sqlite3_step $stmt
  } SQLITE_DONE
  do_test misc4-1.4 {
    execsql {
      SELECT * FROM temp.t2;
    }

Changes to test/schema.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
24
25
26
27
28
29
30

31
32
33
34
35
36
37
...
328
329
330
331
332
333
334
335




























336
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file tests the various conditions under which an SQLITE_SCHEMA
# error should be returned.
#
# $Id: schema.test,v 1.6 2007/05/02 17:54:56 drh Exp $

#---------------------------------------------------------------------
# When any of the following types of SQL statements or actions are 
# executed, all pre-compiled statements are invalidated. An attempt
# to execute an invalidated statement always returns SQLITE_SCHEMA.
#
# CREATE/DROP TABLE...................................schema-1.*
................................................................................
# CREATE/DROP VIEW....................................schema-2.*
# CREATE/DROP TRIGGER.................................schema-3.*
# CREATE/DROP INDEX...................................schema-4.*
# DETACH..............................................schema-5.*
# Deleting a user-function............................schema-6.*
# Deleting a collation sequence.......................schema-7.*
# Setting or changing the authorization function......schema-8.*

#
# Test cases schema-9.* and schema-10.* test some specific bugs
# that came up during development.
#
# Test cases schema-11.* test that it is impossible to delete or
# change a collation sequence or user-function while SQL statements
# are executing. Adding new collations or functions is allowed.
................................................................................
    db collate tstcollate {}
  } msg]
  list $rc $msg
} {1 {Unable to delete/modify collation sequence due to active statements}}
do_test schema-11.8 {
  sqlite3_finalize $::STMT
} {SQLITE_OK}





























finish_test







|







 







>







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file tests the various conditions under which an SQLITE_SCHEMA
# error should be returned.
#
# $Id: schema.test,v 1.7 2007/08/13 15:28:35 danielk1977 Exp $

#---------------------------------------------------------------------
# When any of the following types of SQL statements or actions are 
# executed, all pre-compiled statements are invalidated. An attempt
# to execute an invalidated statement always returns SQLITE_SCHEMA.
#
# CREATE/DROP TABLE...................................schema-1.*
................................................................................
# CREATE/DROP VIEW....................................schema-2.*
# CREATE/DROP TRIGGER.................................schema-3.*
# CREATE/DROP INDEX...................................schema-4.*
# DETACH..............................................schema-5.*
# Deleting a user-function............................schema-6.*
# Deleting a collation sequence.......................schema-7.*
# Setting or changing the authorization function......schema-8.*
# Rollback of a DDL statement.........................schema-12.*
#
# Test cases schema-9.* and schema-10.* test some specific bugs
# that came up during development.
#
# Test cases schema-11.* test that it is impossible to delete or
# change a collation sequence or user-function while SQL statements
# are executing. Adding new collations or functions is allowed.
................................................................................
    db collate tstcollate {}
  } msg]
  list $rc $msg
} {1 {Unable to delete/modify collation sequence due to active statements}}
do_test schema-11.8 {
  sqlite3_finalize $::STMT
} {SQLITE_OK}

# The following demonstrates why statements need to be expired whenever
# there is a rollback (explicit or otherwise).
#
do_test schema-12.1 {
  # Begin a transaction and create a table. This increments 
  # the schema cookie. Then compile an SQL statement, using
  # the current (incremented) value of the cookie.
  execsql {
    BEGIN;
    CREATE TABLE t3(a, b, c);
  }
  set ::STMT [sqlite3_prepare $::DB "CREATE TABLE t4(a,b,c)" -1 TAIL]

  # Rollback the transaction, resetting the schema cookie to the value
  # it had at the start of this test case. Then create a table, 
  # incrementing the schema cookie.
  execsql {
    ROLLBACK;
    CREATE TABLE t4(a, b, c);
  }

  # The schema cookie now has the same value as it did when SQL statement
  # $::STMT was prepared. So unless it has been expired, it would be
  # possible to run the "CREATE TABLE t4" statement and create a
  # duplicate table.
  list [sqlite3_step $::STMT] [sqlite3_finalize $::STMT]
} {SQLITE_ERROR SQLITE_SCHEMA}

finish_test