]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a few more tests and fix a few bugs that the tests uncovered. (CVS 652)
authordrh <drh@noemail.net>
Sat, 29 Jun 2002 02:20:08 +0000 (02:20 +0000)
committerdrh <drh@noemail.net>
Sat, 29 Jun 2002 02:20:08 +0000 (02:20 +0000)
FossilOrigin-Name: 91c0db66c86facb21b5b522afadd83d91a488256

manifest
manifest.uuid
src/expr.c
src/select.c
src/sqliteInt.h
src/update.c
src/vdbe.c
test/expr.test
test/func.test
test/subselect.test

index 38597d349f6cfe358fc502b83c204ad767e6dd97..a2d62defe6dcde5e189019f2628189672afc9337 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Additional\stest\scases\sadded.\s\sThe\sfollowing\sbug\sfixed:\sA\ssegfault\swas\soccurring\nif\sa\sVIEW\sconsisted\sof\sa\sjoin\swith\sa\sUSING\sclause.\s(CVS\s651)
-D 2002-06-28T12:18:47
+C Add\sa\sfew\smore\stests\sand\sfix\sa\sfew\sbugs\sthat\sthe\stests\suncovered.\s(CVS\s652)
+D 2002-06-29T02:20:08
 F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
 F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -23,7 +23,7 @@ F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
 F src/build.c 0834185cbe316dda5173de50886ed804b82e3ba6
 F src/delete.c 44c45460b1e03033756e35adc6d569ffbf30b725
 F src/encode.c 346b12b46148506c32038524b95c4631ab46d760
-F src/expr.c c5b8ee4d51df4de4ee51cadfd0123294e3d683d5
+F src/expr.c ecd8267f70f4099b760c3862527a52cdfb768612
 F src/func.c 5eae8227a8b0d276a64d51a3880a6e86f238fedf
 F src/hash.c 6a6236b89c8c060c65dabd300a1c8ce7c10edb72
 F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
@@ -37,11 +37,11 @@ F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e
 F src/parse.y c75ea2580de675bcb80ff8b7c10c0a15e02a21ab
 F src/printf.c 236ed7a79386feed4456fa728fff8be793f1547c
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 473670ff00c30ffa92784a49766c522181239a9a
+F src/select.c 63a10ea636c8ac8cdf2fbb804fbfcfd372150717
 F src/shell.c 0b06e4421ddf34f30263a2674abe768a2b5fd538
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in 75c5bbb066d0faf34424b7d1babf8b44d5b31af2
-F src/sqliteInt.h 0f2cca162fbb352ca53f97283dbafce31495dcce
+F src/sqliteInt.h 314a4feb08cccdeb90b434e6dde86b93d2f36b8e
 F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63
 F src/tclsqlite.c e932591c0bb522b0a35ea7dc861c623ccb2e3aa8
 F src/test1.c 29ed719d8ce890733fbeadb53cacc4e542d423ed
@@ -50,9 +50,9 @@ F src/test3.c 72ac6a9017a70e542954907a1dfd87ab6f7824e3
 F src/threadtest.c 81f0598e0f031c1bd506af337fdc1b7e8dff263f
 F src/tokenize.c ac4c46f190346b87da54ec3e2605d160af80c619
 F src/trigger.c d88ab4d68d68955c217b38fb6717e090fbbf54a4
-F src/update.c 6f6a4dcd71cd9ff730b7f12c83de5498cde4924f
+F src/update.c 06303bf3895032c7eccb748927f650ed02b9f0cf
 F src/util.c 876b259f9186e84b944b72e793dd3dad50e63e95
-F src/vdbe.c 0c7783ba52b1bd9e40331937c32d3aa3351ff4a3
+F src/vdbe.c c83ece2aeb3a6ce7de9a1636c98c3feec9267499
 F src/vdbe.h a9292f2b5fcecef924fa255fb74609e9cbc776c2
 F src/where.c 6a43aa6c80eab12221eeca754cba852a9ecd1e13
 F test/all.test e4d3821eeba751829b419cd47814bd20af4286d1
@@ -63,8 +63,8 @@ F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
 F test/conflict.test 4518cc3c1c40c4ba74220d9ee814257ae7d09c47
 F test/copy.test 92e21ebea11319c3f70448d3763fdaa0e2f1c21f
 F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
-F test/expr.test c61a92f7d76d63d7379d58bc35245e156c9b63c3
-F test/func.test 628ab513b0d9c54251a63e026a26b7b4347e54ab
+F test/expr.test 5fadd0bc87c223b424ce6752b576c1df346abf1f
+F test/func.test 7e5500c9db4b02fd62f9737931a6ada01e3b55d0
 F test/in.test c09312672e3f0709fa02c8e2e9cd8fb4bd6269aa
 F test/index.test c8a471243bbf878974b99baf5badd59407237cf3
 F test/insert.test a122afb86911e77c181d912348866a5b1a61eeab
@@ -94,7 +94,7 @@ F test/select4.test 10ba54f24ef6ca7958a7045b001079378db2370c
 F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac
 F test/select6.test efb8d0c07a440441db87db2c4ade6904e1407e85
 F test/sort.test 3b996ce7ca385f9cd559944ac0f4027a23aa546b
-F test/subselect.test f3bc1dcbddddcea08d818fcff75228ad3464fc83
+F test/subselect.test 64e71b1be804dc57c72b61d2bd7b506dbc962c40
 F test/table.test 42511f98a3e9bbee62913e3ae1774777faa23d35
 F test/tableapi.test 3c80421a889e1d106df16e5800fa787f0d2914a6
 F test/tclsqlite.test 6f4b9760681c7dbca52a18d0ab46a1679cdc79b9
@@ -137,7 +137,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P c07e493b62125e85eaea36b6945f1e146e2792b8
-R 533eee0cd3864ec067733fb32b2f681d
+P 96515b813eb57e1f48c28d357d1f38639b2fdcfa
+R c1f2449afe59030f9bd638b2fb549a9b
 U drh
-Z 42e105a8fbfb4f79b6ee97023cbdbecf
+Z e559f098ea075de4e2b198f365f605ef
index 5edd00ebdcc657b50618825432f52c3553bb2db7..dbe121612beb64674b905e07d640f1579ba54a01 100644 (file)
@@ -1 +1 @@
-96515b813eb57e1f48c28d357d1f38639b2fdcfa
\ No newline at end of file
+91c0db66c86facb21b5b522afadd83d91a488256
\ No newline at end of file
index 5b0cbd1b28d7e717fcec660a564b13bc1e33aed0..5b2d762e6d7fca5216facd89c2742e99ae45ff1e 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.75 2002/06/28 12:18:47 drh Exp $
+** $Id: expr.c,v 1.76 2002/06/29 02:20:08 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -370,7 +370,7 @@ int sqliteExprIsInteger(Expr *p, int *pValue){
 /*
 ** Return TRUE if the given string is a row-id column name.
 */
-static int sqliteIsRowid(const char *z){
+int sqliteIsRowid(const char *z){
   if( sqliteStrICmp(z, "_ROWID_")==0 ) return 1;
   if( sqliteStrICmp(z, "ROWID")==0 ) return 1;
   if( sqliteStrICmp(z, "OID")==0 ) return 1;
index d815061a3bebb2681d57c5d8a7e7bf4f1cb991e1..92fa302a529c7100bad53ec579d97c55ba325f48 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.101 2002/06/28 12:18:47 drh Exp $
+** $Id: select.c,v 1.102 2002/06/29 02:20:08 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -436,14 +436,16 @@ static int selectInnerLoop(
     ** item into the set table with bogus data.
     */
     case SRT_Set: {
+      int lbl = sqliteVdbeMakeLabel(v);
       assert( nColumn==1 );
-      sqliteVdbeAddOp(v, OP_IsNull, -1, sqliteVdbeCurrentAddr(v)+3);
-      sqliteVdbeAddOp(v, OP_String, 0, 0);
+      sqliteVdbeAddOp(v, OP_IsNull, -1, lbl);
       if( pOrderBy ){
         pushOntoSorter(pParse, v, pOrderBy);
       }else{
+        sqliteVdbeAddOp(v, OP_String, 0, 0);
         sqliteVdbeAddOp(v, OP_PutStrKey, iParm, 0);
       }
+      sqliteVdbeResolveLabel(v, lbl);
       break;
     }
 
index f8b45567b7b1295e21eae6df8310dcdf56d3d5a3..5f842e0c03dea8d4a8669ec34f054fda2492f7f6 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.132 2002/06/28 12:18:47 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.133 2002/06/29 02:20:09 drh Exp $
 */
 #include "sqlite.h"
 #include "hash.h"
@@ -908,6 +908,7 @@ void sqliteRollbackTransaction(Parse*);
 char *sqlite_mprintf(const char *, ...);
 int sqliteExprIsConstant(Expr*);
 int sqliteExprIsInteger(Expr*, int*);
+int sqliteIsRowid(const char*);
 void sqliteGenerateRowDelete(Vdbe*, Table*, int, int);
 void sqliteGenerateRowIndexDelete(Vdbe*, Table*, int, char*);
 void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
index 61ef0d267b4ec118ca130d4d0f0c139caa2f934e..0a6f6db203d210a91bedbaf7c15ad52c3a886728 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle UPDATE statements.
 **
-** $Id: update.c,v 1.45 2002/06/19 14:27:06 drh Exp $
+** $Id: update.c,v 1.46 2002/06/29 02:20:09 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -293,12 +293,8 @@ void sqliteUpdate(
   ** on top of the stack.)
   */
   if( chngRecno ){
-    if( pTab->iPKey<0 || (j = aXRef[pTab->iPKey])<0 ){
-      sqliteVdbeAddOp(v, OP_Dup, 0, 0);
-    }else{
-      sqliteExprCode(pParse, pChanges->a[j].pExpr);
-      sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
-    }
+    sqliteExprCode(pParse, pRecnoExpr);
+    sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
   }
 
   /* Compute new data for this record.  
index 1d3cbd9fa2c9ed8ae50069022eb81be63c7634e7..83b36d90ce92ae0f3af52ae2997a974887d4cc63 100644 (file)
@@ -30,7 +30,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.162 2002/06/28 01:02:38 drh Exp $
+** $Id: vdbe.c,v 1.163 2002/06/29 02:20:09 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1649,7 +1649,8 @@ case OP_NullCallback: {
 ** Look at the first P1 elements of the stack.  Append them all 
 ** together with the lowest element first.  Use P3 as a separator.  
 ** Put the result on the top of the stack.  The original P1 elements
-** are popped from the stack if P2==0 and retained if P2==1.
+** are popped from the stack if P2==0 and retained if P2==1.  If
+** any element of the stack is NULL, then the result is NULL.
 **
 ** If P3 is NULL, then use no separator.  When P1==1, this routine
 ** makes a copy of the top stack element into memory obtained
@@ -1671,12 +1672,21 @@ case OP_Concat: {
   nByte = 1 - nSep;
   for(i=p->tos-nField+1; i<=p->tos; i++){
     if( aStack[i].flags & STK_Null ){
-      nByte += nSep;
+      nByte = -1;
+      break;
     }else{
       if( Stringify(p, i) ) goto no_mem;
       nByte += aStack[i].n - 1 + nSep;
     }
   }
+  if( nByte<0 ){
+    if( pOp->p2==0 ) PopStack(p, nField);
+    VERIFY( NeedStack(p, p->tos+1); )
+    p->tos++;
+    aStack[p->tos].flags = STK_Null;
+    zStack[p->tos] = 0;
+    break;
+  }
   zNew = sqliteMalloc( nByte );
   if( zNew==0 ) goto no_mem;
   j = 0;
@@ -4194,11 +4204,14 @@ case OP_SortPut: {
   pSorter->pNext = p->pSort;
   p->pSort = pSorter;
   assert( aStack[tos].flags & STK_Dyn );
-  assert( aStack[nos].flags & STK_Dyn );
   pSorter->nKey = aStack[tos].n;
   pSorter->zKey = zStack[tos];
   pSorter->nData = aStack[nos].n;
-  pSorter->pData = zStack[nos];
+  if( aStack[nos].flags & STK_Dyn ){
+    pSorter->pData = zStack[nos];
+  }else{
+    pSorter->pData = sqliteStrDup(zStack[nos]);
+  }
   aStack[tos].flags = 0;
   aStack[nos].flags = 0;
   zStack[tos] = 0;
index 1acb06203d93ee6d70840b1d2134152b8195b879..c672988cb7e83bad8314131e8f409b6d2450dba2 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing expressions.
 #
-# $Id: expr.test,v 1.24 2002/05/31 15:51:26 drh Exp $
+# $Id: expr.test,v 1.25 2002/06/29 02:20:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -181,8 +181,8 @@ test_expr expr-3.27 {t1=NULL, t2='hi'} {t1 notnull} 0
 test_expr expr-3.28 {t1=NULL, t2='hi'} {t2 notnull} 1
 test_expr expr-3.28b {t1=NULL, t2='hi'} {t2 is not null} 1
 test_expr expr-3.29 {t1='xyz', t2='abc'} {t1||t2} {xyzabc}
-test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {abc}
-test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {xyz}
+test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {{}}
+test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {{}}
 test_expr expr-3.32 {t1='xyz', t2='abc'} {t1||' hi '||t2} {{xyz hi abc}}
 
 test_expr expr-4.1 {t1='abc', t2='Abc'} {t1<t2} 0
index 98e2a97f3cd9188062ca196d45cb8e41b3fde777..12cdcfe90d2d8822a645e08d755d0ba6b653ac80 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing built-in functions.
 #
-# $Id: func.test,v 1.12 2002/05/29 23:22:23 drh Exp $
+# $Id: func.test,v 1.13 2002/06/29 02:20:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -221,7 +221,7 @@ do_test func-5.5 {
   catchsql {SELECT upper(*) FROM t2}
 } {1 {wrong number of arguments to function upper()}}
 
-# Test the coalesce() function
+# Test the coalesce() and nullif() functions
 #
 do_test func-6.1 {
   execsql {SELECT coalesce(a,'xyz') FROM t2}
@@ -229,6 +229,16 @@ do_test func-6.1 {
 do_test func-6.2 {
   execsql {SELECT coalesce(upper(a),'nil') FROM t2}
 } {1 nil 345 nil 67890}
+do_test func-6.3 {
+  execsql {SELECT coalesce(nullif(1,1),'nil')}
+} {nil}
+do_test func-6.4 {
+  execsql {SELECT coalesce(nullif(1,2),'nil')}
+} {1}
+do_test func-6.5 {
+  execsql {SELECT coalesce(nullif(1,NULL),'nil')}
+} {1}
+
 
 # Test the last_insert_rowid() function
 #
@@ -243,6 +253,24 @@ do_test func-8.1 {
     SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2;
   }
 } {68236 3 22745.33 1 67890 5}
+do_test func-8.2 {
+  execsql {
+    SELECT max('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t2;
+  }
+} {z+67890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
+do_test func-8.3 {
+  execsql {
+    CREATE TEMP TABLE t3 AS SELECT a FROM t2 ORDER BY a DESC;
+    SELECT min('z+'||a||'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP') FROM t3;
+  }
+} {z+1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP}
 
+# How do you test the random() function in a meaningful, deterministic way?
+#
+do_test func-9.1 {
+  execsql {
+    SELECT random() is not null;
+  }
+} {1}
 
 finish_test
index 392ab5319ae8d0622ef29aa28a24d76aaf4033f9..11be13054b02ae0fe4dcb3d48f97db3818f6bf0b 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing SELECT statements that are part of
 # expressions.
 #
-# $Id: subselect.test,v 1.5 2002/05/26 20:54:35 drh Exp $
+# $Id: subselect.test,v 1.6 2002/06/29 02:20:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -82,4 +82,22 @@ do_test subselect-1.6 {
   execsql {SELECT x FROM t2 ORDER BY x}
 } {2 3 4}
 
+# Make sure sorting works for SELECTs there used as a scalar expression.
+#
+do_test subselect-2.1 {
+  execsql {
+    SELECT (SELECT a FROM t1 ORDER BY a), (SELECT a FROM t1 ORDER BY a DESC)
+  }
+} {1 5}
+do_test subselect-2.2 {
+  execsql {
+    SELECT 1 IN (SELECT a FROM t1 ORDER BY a);
+  }
+} {1}
+do_test subselect-2.3 {
+  execsql {
+    SELECT 2 IN (SELECT a FROM t1 ORDER BY a DESC);
+  }
+} {0}
+
 finish_test