Improved test coverage on insert.c. (CVS 2210)

FossilOrigin-Name: c772f75166d55192132e732e8a0ddda5926f00f2
This commit is contained in:
drh 2005-01-14 01:22:00 +00:00
parent 3b93bc8cb1
commit d6fe961ef4
4 changed files with 108 additions and 12 deletions

View File

@ -1,5 +1,5 @@
C Need\sSQLITE_MEMDEBUG\sinstead\sof\sSQLITE_DEBUG\sin\stclsqlite.c.\s(CVS\s2209) C Improved\stest\scoverage\son\sinsert.c.\s(CVS\s2210)
D 2005-01-13T23:54:32 D 2005-01-14T01:22:01
F Makefile.in 6ce51dde6a8fe82fc12f20dec750572f6a19f56a F Makefile.in 6ce51dde6a8fe82fc12f20dec750572f6a19f56a
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -39,7 +39,7 @@ F src/expr.c ecfc8fd972e73650708e1109f97b1c5a785e0a0e
F src/func.c dc188d862d7276ea897655b248e2cb17022686e3 F src/func.c dc188d862d7276ea897655b248e2cb17022686e3
F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5 F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/insert.c f6b69e40e8938f63a2368cbcb5087a56098cf632 F src/insert.c 2a8fadfd7494881632fcae453f115d42a7a58dee
F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
F src/main.c cbe5a05baabad9fabb733065d0fb00c0b36f6ef1 F src/main.c cbe5a05baabad9fabb733065d0fb00c0b36f6ef1
F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
@ -136,6 +136,7 @@ F test/index.test 1294997b4743007af57f8148c63ba14f07ad31ab
F test/index2.test ed2409af110aa06ec0c9fedfa050031887c38707 F test/index2.test ed2409af110aa06ec0c9fedfa050031887c38707
F test/insert.test 56f9c20c9adc8d707490c4ffa5d4daa94826ea03 F test/insert.test 56f9c20c9adc8d707490c4ffa5d4daa94826ea03
F test/insert2.test 0bb50ff999e35a21549d8ee5dc44db8ac24d31a7 F test/insert2.test 0bb50ff999e35a21549d8ee5dc44db8ac24d31a7
F test/insert3.test 421f6017ad268fcdba0b8ab56a2dff7265d3cf23
F test/interrupt.test 5b4d8389e6cf2d01b94f87cfd02d9df1073bfb2d F test/interrupt.test 5b4d8389e6cf2d01b94f87cfd02d9df1073bfb2d
F test/intpkey.test b57cf5236fde1bd8cbc1388fa0c91908f6fd9194 F test/intpkey.test b57cf5236fde1bd8cbc1388fa0c91908f6fd9194
F test/ioerr.test 259bef101273a8e7b16d004018ee5a7873a26889 F test/ioerr.test 259bef101273a8e7b16d004018ee5a7873a26889
@ -268,7 +269,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
P 7113b5ed8d51718356ce1cc51896a3070875a7e2 P 6e905270a933fd4c99f6db6707ed79166f6484ee
R 97b9862e7f5be337d69e7b8a5cce7fca R b0f921b0cc4246465f13a208b372d988
U drh U drh
Z 48311deeb016a5dd529c213b5f492974 Z 0f466f7cb587c20134aa5d2e4fe7cd6a

View File

@ -1 +1 @@
6e905270a933fd4c99f6db6707ed79166f6484ee c772f75166d55192132e732e8a0ddda5926f00f2

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite. ** to handle INSERT statements in SQLite.
** **
** $Id: insert.c,v 1.129 2005/01/10 02:48:49 danielk1977 Exp $ ** $Id: insert.c,v 1.130 2005/01/14 01:22:01 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -496,9 +496,8 @@ void sqlite3Insert(
sqlite3VdbeAddOp(v, OP_Integer, -1, 0); sqlite3VdbeAddOp(v, OP_Integer, -1, 0);
}else if( useTempTable ){ }else if( useTempTable ){
sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn); sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn);
}else if( pSelect ){
sqlite3VdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
}else{ }else{
assert( pSelect==0 ); /* Otherwise useTempTable is true */
sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr); sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3); sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0); sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
@ -520,9 +519,8 @@ void sqlite3Insert(
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt); sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
}else if( useTempTable ){ }else if( useTempTable ){
sqlite3VdbeAddOp(v, OP_Column, srcTab, j); sqlite3VdbeAddOp(v, OP_Column, srcTab, j);
}else if( pSelect ){
sqlite3VdbeAddOp(v, OP_Dup, nColumn-j-1, 1);
}else{ }else{
assert( pSelect==0 ); /* Otherwise useTempTable is true */
sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr); sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr);
} }
} }

97
test/insert3.test Normal file
View File

@ -0,0 +1,97 @@
# 2005 January 13
#
# 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 file is testing corner cases of the INSERT statement.
#
# $Id: insert3.test,v 1.1 2005/01/14 01:22:01 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Create a table and a corresponding insert trigger. Do a self-insert
# into the table.
#
do_test insert3-1.0 {
execsql {
CREATE TABLE t1(a,b);
CREATE TABLE log(x UNIQUE, y);
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
UPDATE log SET y=y+1 WHERE x=new.a;
INSERT OR IGNORE INTO log VALUES(new.a, 1);
END;
INSERT INTO t1 VALUES('hello','world');
INSERT INTO t1 VALUES(5,10);
SELECT * FROM log ORDER BY x;
}
} {5 1 hello 1}
do_test insert3-1.1 {
execsql {
INSERT INTO t1 SELECT a, b+10 FROM t1;
SELECT * FROM log ORDER BY x;
}
} {5 2 hello 2}
do_test insert3-1.2 {
execsql {
CREATE TABLE log2(x PRIMARY KEY,y);
CREATE TRIGGER r2 BEFORE INSERT ON t1 BEGIN
UPDATE log2 SET y=y+1 WHERE x=new.b;
INSERT OR IGNORE INTO log2 VALUES(new.b,1);
END;
INSERT INTO t1 VALUES(453,'hi');
SELECT * FROM log ORDER BY x;
}
} {5 2 453 1 hello 2}
do_test insert3-1.3 {
execsql {
SELECT * FROM log2 ORDER BY x;
}
} {hi 1}
do_test insert3-1.4 {
execsql {
INSERT INTO t1 SELECT * FROM t1;
SELECT 'a:', x, y FROM log UNION ALL SELECT 'b:', x, y FROM log2 ORDER BY x;
}
} {a: 5 4 b: 10 2 b: 20 1 a: 453 2 a: hello 4 b: hi 2 b: world 1}
do_test insert3-1.5 {
execsql {
INSERT INTO t1(a) VALUES('xyz');
SELECT * FROM log ORDER BY x;
}
} {5 4 453 2 hello 4 xyz 1}
do_test insert3-2.1 {
execsql {
CREATE TABLE t2(
a INTEGER PRIMARY KEY,
b DEFAULT 'b',
c DEFAULT 'c'
);
CREATE TABLE t2dup(a,b,c);
CREATE TRIGGER t2r1 BEFORE INSERT ON t2 BEGIN
INSERT INTO t2dup(a,b,c) VALUES(new.a,new.b,new.c);
END;
INSERT INTO t2(a) VALUES(123);
INSERT INTO t2(b) VALUES(234);
INSERT INTO t2(c) VALUES(345);
SELECT * FROM t2dup;
}
} {123 b c -1 234 c -1 b 345}
do_test insert3-2.2 {
execsql {
DELETE FROM t2dup;
INSERT INTO t2(a) SELECT 1 FROM t1 LIMIT 1;
INSERT INTO t2(b) SELECT 987 FROM t1 LIMIT 1;
INSERT INTO t2(c) SELECT 876 FROM t1 LIMIT 1;
SELECT * FROM t2dup;
}
} {1 b c -1 987 c -1 b 876}
finish_test