mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Increase test coverage of alter.c to 100%. Fix bugs found in the process. (CVS 2603)
FossilOrigin-Name: b550d04d43a92f33a01438ae03df14678db3cdee
This commit is contained in:
15
manifest
15
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Additional\stests\sfor\sbetter\scoverage.\s(CVS\s2602)
|
C Increase\stest\scoverage\sof\salter.c\sto\s100%.\s\sFix\sbugs\sfound\sin\sthe\sprocess.\s(CVS\s2603)
|
||||||
D 2005-08-19T03:03:52
|
D 2005-08-19T19:14:13
|
||||||
F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
|
F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
|
||||||
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
|
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
|
||||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||||
@@ -28,7 +28,7 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
|||||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||||
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
|
F sqlite3.def c413e514217736884254739a105c8c942fdf0c2f
|
||||||
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
|
||||||
F src/alter.c 03041f2464e22532601254f87cb49997fa21dcdf
|
F src/alter.c 26d755f2143719dd3f5b8aaf6cbe3c7f95332528
|
||||||
F src/analyze.c 3ab32927f4d3067ead10e4c4f6fb61b2a93479cc
|
F src/analyze.c 3ab32927f4d3067ead10e4c4f6fb61b2a93479cc
|
||||||
F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f
|
F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f
|
||||||
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
|
F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
|
||||||
@@ -87,12 +87,13 @@ F src/vdbeapi.c dc5b78cabf8d6e33318bd3d4ed25307d2aadce9a
|
|||||||
F src/vdbeaux.c 874624698fad54a59c6a0bcccea9d5aaa8655ab6
|
F src/vdbeaux.c 874624698fad54a59c6a0bcccea9d5aaa8655ab6
|
||||||
F src/vdbefifo.c b8805850afe13b43f1de78d58088cb5d66f88e1e
|
F src/vdbefifo.c b8805850afe13b43f1de78d58088cb5d66f88e1e
|
||||||
F src/vdbemem.c 89154caae3b8d4d0397e1235390fc4ff8aba4233
|
F src/vdbemem.c 89154caae3b8d4d0397e1235390fc4ff8aba4233
|
||||||
F src/where.c a8401eb8eb8db37996e4c835cd4373de875c1488
|
F src/where.c 8392d521f901f83f95bf32e52255a0efe98677af
|
||||||
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
|
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
|
||||||
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
|
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
|
||||||
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
|
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
|
||||||
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
|
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
|
||||||
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
|
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
|
||||||
|
F test/altermalloc.test c3a76eb7f6b07793b316246aef5ecfd9f74c33b1
|
||||||
F test/analyze.test a1206c7430606ffa20bcbb220c87c2873f5efdd4
|
F test/analyze.test a1206c7430606ffa20bcbb220c87c2873f5efdd4
|
||||||
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
|
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
|
||||||
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
|
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
|
||||||
@@ -295,7 +296,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
|
|||||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||||
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
|
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
|
||||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||||
P 842a80bd8f18d6fd046604f9a057bcd738234f1f
|
P 4281a838f2f531af24b008d2834e8318798472c5
|
||||||
R 8baaaceefa2a5b1bbb0ec21eebabea20
|
R e46f0078da7fdd3d7209c1df240c1e04
|
||||||
U drh
|
U drh
|
||||||
Z 9490eb8ab23ad36efe902134f81dd66d
|
Z ff386666acb3fed8a078593bb81d2165
|
||||||
|
@@ -1 +1 @@
|
|||||||
4281a838f2f531af24b008d2834e8318798472c5
|
b550d04d43a92f33a01438ae03df14678db3cdee
|
@@ -12,7 +12,7 @@
|
|||||||
** This file contains C code routines that used to generate VDBE code
|
** This file contains C code routines that used to generate VDBE code
|
||||||
** that implements the ALTER TABLE command.
|
** that implements the ALTER TABLE command.
|
||||||
**
|
**
|
||||||
** $Id: alter.c,v 1.7 2005/06/06 21:19:57 drh Exp $
|
** $Id: alter.c,v 1.8 2005/08/19 19:14:13 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -258,6 +258,7 @@ void sqlite3AlterRenameTable(
|
|||||||
char *zWhere = 0; /* Where clause to locate temp triggers */
|
char *zWhere = 0; /* Where clause to locate temp triggers */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if( sqlite3_malloc_failed ) goto exit_rename_table;
|
||||||
assert( pSrc->nSrc==1 );
|
assert( pSrc->nSrc==1 );
|
||||||
|
|
||||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||||
@@ -500,8 +501,10 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
|||||||
int i;
|
int i;
|
||||||
int nAlloc;
|
int nAlloc;
|
||||||
|
|
||||||
|
|
||||||
/* Look up the table being altered. */
|
/* Look up the table being altered. */
|
||||||
assert( !pParse->pNewTable );
|
assert( pParse->pNewTable==0 );
|
||||||
|
if( sqlite3_malloc_failed ) goto exit_begin_add_column;
|
||||||
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
|
||||||
if( !pTab ) goto exit_begin_add_column;
|
if( !pTab ) goto exit_begin_add_column;
|
||||||
|
|
||||||
@@ -520,6 +523,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
|
|||||||
pNew = (Table *)sqliteMalloc(sizeof(Table));
|
pNew = (Table *)sqliteMalloc(sizeof(Table));
|
||||||
if( !pNew ) goto exit_begin_add_column;
|
if( !pNew ) goto exit_begin_add_column;
|
||||||
pParse->pNewTable = pNew;
|
pParse->pNewTable = pNew;
|
||||||
|
pNew->nRef = 1;
|
||||||
pNew->nCol = pTab->nCol;
|
pNew->nCol = pTab->nCol;
|
||||||
assert( pNew->nCol>0 );
|
assert( pNew->nCol>0 );
|
||||||
nAlloc = (((pNew->nCol-1)/8)*8)+8;
|
nAlloc = (((pNew->nCol-1)/8)*8)+8;
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
** so is applicable. Because this module is responsible for selecting
|
** so is applicable. Because this module is responsible for selecting
|
||||||
** indices, you might also think of this module as the "query optimizer".
|
** indices, you might also think of this module as the "query optimizer".
|
||||||
**
|
**
|
||||||
** $Id: where.c,v 1.163 2005/08/19 00:14:42 drh Exp $
|
** $Id: where.c,v 1.164 2005/08/19 19:14:13 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
|
|
||||||
@@ -525,6 +525,7 @@ static void exprAnalyze(
|
|||||||
int nPattern;
|
int nPattern;
|
||||||
int isComplete;
|
int isComplete;
|
||||||
|
|
||||||
|
if( sqlite3_malloc_failed ) return;
|
||||||
prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
|
prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft);
|
||||||
pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
|
pTerm->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight);
|
||||||
pTerm->prereqAll = prereqAll = exprTableUsage(pMaskSet, pExpr);
|
pTerm->prereqAll = prereqAll = exprTableUsage(pMaskSet, pExpr);
|
||||||
@@ -1383,6 +1384,9 @@ WhereInfo *sqlite3WhereBegin(
|
|||||||
createMask(&maskSet, pTabList->a[i].iCursor);
|
createMask(&maskSet, pTabList->a[i].iCursor);
|
||||||
}
|
}
|
||||||
exprAnalyzeAll(pTabList, &maskSet, &wc);
|
exprAnalyzeAll(pTabList, &maskSet, &wc);
|
||||||
|
if( sqlite3_malloc_failed ){
|
||||||
|
goto whereBeginNoMem;
|
||||||
|
}
|
||||||
|
|
||||||
/* Chose the best index to use for each table in the FROM clause.
|
/* Chose the best index to use for each table in the FROM clause.
|
||||||
**
|
**
|
||||||
|
118
test/altermalloc.test
Normal file
118
test/altermalloc.test
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
# 2005 September 19
|
||||||
|
#
|
||||||
|
# The author disclaims copyright to this source code. In place of
|
||||||
|
# a legal notice, here is a blessing:
|
||||||
|
#
|
||||||
|
# May you do good and not evil.
|
||||||
|
# May you find forgiveness for yourself and forgive others.
|
||||||
|
# May you share freely, never taking more than you give.
|
||||||
|
#
|
||||||
|
#*************************************************************************
|
||||||
|
# This file implements regression tests for SQLite library. The
|
||||||
|
# focus of this script is testing the ALTER TABLE statement and
|
||||||
|
# specifically out-of-memory conditions within that command.
|
||||||
|
#
|
||||||
|
# $Id: altermalloc.test,v 1.1 2005/08/19 19:14:13 drh Exp $
|
||||||
|
#
|
||||||
|
|
||||||
|
set testdir [file dirname $argv0]
|
||||||
|
source $testdir/tester.tcl
|
||||||
|
|
||||||
|
# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
|
||||||
|
ifcapable !altertable {
|
||||||
|
finish_test
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Usage: do_malloc_test <test name> <options...>
|
||||||
|
#
|
||||||
|
# The first argument, <test number>, is an integer used to name the
|
||||||
|
# tests executed by this proc. Options are as follows:
|
||||||
|
#
|
||||||
|
# -tclprep TCL script to run to prepare test.
|
||||||
|
# -sqlprep SQL script to run to prepare test.
|
||||||
|
# -tclbody TCL script to run with malloc failure simulation.
|
||||||
|
# -sqlbody TCL script to run with malloc failure simulation.
|
||||||
|
# -cleanup TCL script to run after the test.
|
||||||
|
#
|
||||||
|
# This command runs a series of tests to verify SQLite's ability
|
||||||
|
# to handle an out-of-memory condition gracefully. It is assumed
|
||||||
|
# that if this condition occurs a malloc() call will return a
|
||||||
|
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||||
|
# the "BUGS" section of malloc(3).
|
||||||
|
#
|
||||||
|
# Each iteration of a loop, the TCL commands in any argument passed
|
||||||
|
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||||
|
# passed to the -sqlbody switch are executed. Each iteration the
|
||||||
|
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||||
|
# each time the loop runs starting from 1. When all commands execute
|
||||||
|
# successfully, the loop ends.
|
||||||
|
#
|
||||||
|
proc do_malloc_test {tn args} {
|
||||||
|
array set ::mallocopts $args
|
||||||
|
|
||||||
|
set ::go 1
|
||||||
|
for {set ::n 1} {$::go} {incr ::n} {
|
||||||
|
|
||||||
|
do_test $tn.$::n {
|
||||||
|
|
||||||
|
sqlite_malloc_fail 0
|
||||||
|
catch {db close}
|
||||||
|
catch {file delete -force test.db}
|
||||||
|
catch {file delete -force test.db-journal}
|
||||||
|
catch {file delete -force test2.db}
|
||||||
|
catch {file delete -force test2.db-journal}
|
||||||
|
set ::DB [sqlite3 db test.db]
|
||||||
|
|
||||||
|
if {[info exists ::mallocopts(-tclprep)]} {
|
||||||
|
eval $::mallocopts(-tclprep)
|
||||||
|
}
|
||||||
|
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||||
|
execsql $::mallocopts(-sqlprep)
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite_malloc_fail $::n
|
||||||
|
set ::mallocbody {}
|
||||||
|
if {[info exists ::mallocopts(-tclbody)]} {
|
||||||
|
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||||
|
}
|
||||||
|
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||||
|
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
set v [catch $::mallocbody msg]
|
||||||
|
|
||||||
|
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||||
|
if {$leftover>0} {
|
||||||
|
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||||
|
set ::go 0
|
||||||
|
set v {1 1}
|
||||||
|
} else {
|
||||||
|
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||||
|
if {!$v2} {puts "\nError message returned: $msg"}
|
||||||
|
lappend v $v2
|
||||||
|
}
|
||||||
|
} {1 1}
|
||||||
|
sqlite_malloc_fail 0
|
||||||
|
|
||||||
|
if {[info exists ::mallocopts(-cleanup)]} {
|
||||||
|
catch $::mallocopts(-cleanup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset ::mallocopts
|
||||||
|
}
|
||||||
|
|
||||||
|
do_malloc_test altermalloc-1 -tclprep {
|
||||||
|
db close
|
||||||
|
} -tclbody {
|
||||||
|
if {[catch {sqlite3 db test.db}]} {
|
||||||
|
error "out of memory"
|
||||||
|
}
|
||||||
|
} -sqlbody {
|
||||||
|
CREATE TABLE t1(a int);
|
||||||
|
ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
|
||||||
|
ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
|
||||||
|
ALTER TABLE t1 RENAME TO t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
finish_test
|
Reference in New Issue
Block a user