/ Check-in [2af1f065]
Login

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

Overview
Comment:Make sure BEGIN, COMMIT, and ROLLBACK are really no-ops when preceded by EXPLAIN. Ticket #626. (CVS 1267)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2af1f065b5eb39fd3ecac00f8a66d1b4186aead5
User & Date: drh 2004-02-24 01:04:12
Context
2004-02-24
01:05
Refactor parts of write operations. (CVS 1268) check-in: 5b0147ae user: drh tags: trunk
01:04
Make sure BEGIN, COMMIT, and ROLLBACK are really no-ops when preceded by EXPLAIN. Ticket #626. (CVS 1267) check-in: 2af1f065 user: drh tags: trunk
2004-02-22
20:05
Use sqliteVdbeOp3 instead of sqliteVdbeChangeP3 where applicable. (CVS 1266) check-in: 51f1e8f7 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
....
2024
2025
2026
2027
2028
2029
2030

2031
2032

2033
2034
2035
2036
2037
2038
2039
....
2041
2042
2043
2044
2045
2046
2047

2048

2049

2050

2051
2052
2053
2054
2055
2056
2057
....
2064
2065
2066
2067
2068
2069
2070

2071
2072

2073
2074
2075
2076
2077
2078
2079
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**     PRAGMA
**
** $Id: build.c,v 1.174 2004/02/22 20:05:01 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Check to see if the schema for the database needs
................................................................................
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ) return;
  if( db->flags & SQLITE_InTrans ){
    sqliteErrorMsg(pParse, "cannot start a transaction within a transaction");
    return;
  }
  sqliteBeginWriteOperation(pParse, 0, 0);

  db->flags |= SQLITE_InTrans;
  db->onError = onError;

}

/*
** Commit a transaction
*/
void sqliteCommitTransaction(Parse *pParse){
  sqlite *db;
................................................................................
  if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ) return;
  if( (db->flags & SQLITE_InTrans)==0 ){
    sqliteErrorMsg(pParse, "cannot commit - no transaction is active");
    return;
  }

  db->flags &= ~SQLITE_InTrans;

  sqliteEndWriteOperation(pParse);

  db->onError = OE_Default;

}

/*
** Rollback a transaction
*/
void sqliteRollbackTransaction(Parse *pParse){
  sqlite *db;
................................................................................
    sqliteErrorMsg(pParse, "cannot rollback - no transaction is active");
    return; 
  }
  v = sqliteGetVdbe(pParse);
  if( v ){
    sqliteVdbeAddOp(v, OP_Rollback, 0, 0);
  }

  db->flags &= ~SQLITE_InTrans;
  db->onError = OE_Default;

}

/*
** Generate VDBE code that will verify the schema cookie for all
** named database files.
*/
void sqliteCodeVerifySchema(Parse *pParse, int iDb){







|







 







>
|
|
>







 







>
|
>

>
|
>







 







>
|
|
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
....
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
....
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
....
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**     PRAGMA
**
** $Id: build.c,v 1.175 2004/02/24 01:04:12 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Check to see if the schema for the database needs
................................................................................
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0) ) return;
  if( db->flags & SQLITE_InTrans ){
    sqliteErrorMsg(pParse, "cannot start a transaction within a transaction");
    return;
  }
  sqliteBeginWriteOperation(pParse, 0, 0);
  if( !pParse->explain ){
    db->flags |= SQLITE_InTrans;
    db->onError = onError;
  }
}

/*
** Commit a transaction
*/
void sqliteCommitTransaction(Parse *pParse){
  sqlite *db;
................................................................................
  if( pParse==0 || (db=pParse->db)==0 || db->aDb[0].pBt==0 ) return;
  if( pParse->nErr || sqlite_malloc_failed ) return;
  if( sqliteAuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ) return;
  if( (db->flags & SQLITE_InTrans)==0 ){
    sqliteErrorMsg(pParse, "cannot commit - no transaction is active");
    return;
  }
  if( !pParse->explain ){
    db->flags &= ~SQLITE_InTrans;
  }
  sqliteEndWriteOperation(pParse);
  if( !pParse->explain ){
    db->onError = OE_Default;
  }
}

/*
** Rollback a transaction
*/
void sqliteRollbackTransaction(Parse *pParse){
  sqlite *db;
................................................................................
    sqliteErrorMsg(pParse, "cannot rollback - no transaction is active");
    return; 
  }
  v = sqliteGetVdbe(pParse);
  if( v ){
    sqliteVdbeAddOp(v, OP_Rollback, 0, 0);
  }
  if( !pParse->explain ){
    db->flags &= ~SQLITE_InTrans;
    db->onError = OE_Default;
  }
}

/*
** Generate VDBE code that will verify the schema cookie for all
** named database files.
*/
void sqliteCodeVerifySchema(Parse *pParse, int iDb){

Changes to test/misc3.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
232
233
234
235
236
237
238

239













240
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc3.test,v 1.7 2004/02/09 14:35:28 drh Exp $

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

# Ticket #529.  Make sure an ABORT does not damage the in-memory cache
# that will be used by subsequent statements in the same transaction.
#
................................................................................
    SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1);
  }
} {64}

# Ticket #601:  Putting a left join inside "SELECT * FROM (<join-here>)"
# gives different results that if the outer "SELECT * FROM ..." is omitted.
#
do_test misc4-5.1 {
  execsql {
    CREATE TABLE x1 (b, c);
    INSERT INTO x1 VALUES('dog',3);
    INSERT INTO x1 VALUES('cat',1);
    INSERT INTO x1 VALUES('dog',4);
    CREATE TABLE x2 (c, e);
    INSERT INTO x2 VALUES(1,'one');
................................................................................
      SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
         (SELECT b, max(c) AS c FROM x1 GROUP BY b)
         USING(c)
    );
  }
} {1 one cat 2 two {} 3 three {} 4 four dog}
















finish_test







|







 







|







 







>
|
>
>
>
>
>
>
>
>
>
>
>
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc3.test,v 1.8 2004/02/24 01:04:12 drh Exp $

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

# Ticket #529.  Make sure an ABORT does not damage the in-memory cache
# that will be used by subsequent statements in the same transaction.
#
................................................................................
    SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1);
  }
} {64}

# Ticket #601:  Putting a left join inside "SELECT * FROM (<join-here>)"
# gives different results that if the outer "SELECT * FROM ..." is omitted.
#
do_test misc3-5.1 {
  execsql {
    CREATE TABLE x1 (b, c);
    INSERT INTO x1 VALUES('dog',3);
    INSERT INTO x1 VALUES('cat',1);
    INSERT INTO x1 VALUES('dog',4);
    CREATE TABLE x2 (c, e);
    INSERT INTO x2 VALUES(1,'one');
................................................................................
      SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
         (SELECT b, max(c) AS c FROM x1 GROUP BY b)
         USING(c)
    );
  }
} {1 one cat 2 two {} 3 three {} 4 four dog}

# Ticket #626:  make sure EXPLAIN prevents BEGIN and COMMIT from working.
#
do_test misc3-6.1 {
  execsql {EXPLAIN BEGIN}
  catchsql {BEGIN}
} {0 {}}
do_test misc3-6.2 {
  execsql {EXPLAIN COMMIT}
  catchsql {COMMIT}
} {0 {}}
do_test misc3-6.3 {
  execsql {BEGIN; EXPLAIN ROLLBACK}
  catchsql {ROLLBACK}
} {0 {}}

finish_test