]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The new function code passes regression tests. (CVS 403)
authordrh <drh@noemail.net>
Thu, 28 Feb 2002 03:04:48 +0000 (03:04 +0000)
committerdrh <drh@noemail.net>
Thu, 28 Feb 2002 03:04:48 +0000 (03:04 +0000)
FossilOrigin-Name: b00cf110b1cc671b7200a5ce8b9e704f660763c9

manifest
manifest.uuid
src/expr.c
src/func.c
src/vdbe.c
test/func.test
test/select1.test

index 5e53a6616bb0b72815b6bfd3093304199f4c3d14..0fbd32037ddfe134d506ebb6ba5d98c624cfacda 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\scoredump.\s\sThere\sare\sstill\sproblems\sin\sthe\stest\ssuite\sthough.\s(CVS\s402)
-D 2002-02-28T01:46:12
+C The\snew\sfunction\scode\spasses\sregression\stests.\s(CVS\s403)
+D 2002-02-28T03:04:48
 F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d
 F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -23,8 +23,8 @@ F src/btree.c 495275fe14f3b718cf2f691dce979d4c0e1f8e5d
 F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3
 F src/build.c 7ada2426caba70cb1072ba268bedb694b5018065
 F src/delete.c 950d8f9097361419f1963875f9943344b469cf02
-F src/expr.c 173965f4d1ef4469ae3aa83b1240f7cb8d2a3846
-F src/func.c 2a607655d2aa8f1cb2179964c9ded3bbeab6b683
+F src/expr.c b70bedaffd27ea24c5c2a197a88b07e82dfa4967
+F src/func.c 14ac2dfa1845a9b12bf71557ae3a179d32902abe
 F src/hash.c cc259475e358baaf299b00a2c7370f2b03dda892
 F src/hash.h dca065dda89d4575f3176e75e9a3dc0f4b4fb8b9
 F src/insert.c 164d2d5e943268a8ff0594e1947599e04df0ce11
@@ -51,7 +51,7 @@ F src/threadtest.c 81f0598e0f031c1bd506af337fdc1b7e8dff263f
 F src/tokenize.c 4b5d30590a744b9bb5605a92d1f620ab2e7e75af
 F src/update.c 18971d265b0341574b7e3f73116e7947ddab0997
 F src/util.c 1c01f0a54a77ae9fb638d026d18093ee1b61e3b3
-F src/vdbe.c b7dda08abdcdbdb4996fc58e702f2ac140c4433e
+F src/vdbe.c 26a2b62f1d5d0806bd301413327efc85944ae40c
 F src/vdbe.h 8ab845e63e196e8eb5e51ce69f43b233e51db07e
 F src/where.c 664be01b0ce9ffaecbde609afbd4d8d3e5ed1585
 F test/all.test 7a8a8a7a579ed2bb4d8976d55402f21eacd58049
@@ -63,7 +63,7 @@ F test/conflict.test c794c6c8f6e59918107dbab2d201ae454bb47db8
 F test/copy.test b3cefcb520c64d7e7dfedbab06b4d4c31fa5b99a
 F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
 F test/expr.test c8a495050dcec3f9e68538c3ef466726933302c1
-F test/func.test 51dbe3f8a4c28972751697423e6acc5d6b551df1
+F test/func.test 13572d84cb0f5d4dbd9a51bf767eac047e6f9779
 F test/in.test c09312672e3f0709fa02c8e2e9cd8fb4bd6269aa
 F test/index.test c8a471243bbf878974b99baf5badd59407237cf3
 F test/insert.test c36d534a4ab58c2cd452a273e51b2b0dd1ede1f9
@@ -82,7 +82,7 @@ F test/printf.test 3cb415073754cb8ff076f26173143c3cd293a9da
 F test/quick.test 6f023c7a73fc413e6d65b7a1879c79764038dc05
 F test/quote.test 286db944717afa9a9bf829dd85e59185c65d5435
 F test/rowid.test 4c55943300cddf73dd0f88d40a268cab14c83274
-F test/select1.test 7d5ae792d6dbfa2c1b6345a32b154b7ba8d24bbc
+F test/select1.test 72328eb569399e2075a0ce0d84d67df93f27eef2
 F test/select2.test ed2c1882857106b85478f54f67000e14966be4c4
 F test/select3.test 9469c332250a75a0ef1771fb5da62dc04ec77f18
 F test/select4.test 29a2ffb187f3d8b6ca42a0a6b619e9cabe12e228
@@ -127,7 +127,7 @@ F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P c6a85c8ee3d653a294bcc033ac6cab2b6de06f96
-R 04a7bbe2baff580acccc1436b54d7bc7
+P 6af10cc53acc1ffa60de3f0d5880a6b72815404c
+R a8e13733ee5e31e5e4261dfef2a4a7b4
 U drh
-Z ca8712c82e6c361edcb455161975de2d
+Z 2f9159adbbc07ca082acf9822ba9ab2f
index 5fde4ea332300cb2be9ac477089de54f1f58029c..24370531732b57f138a85272654b1d6ccf5c3069 100644 (file)
@@ -1 +1 @@
-6af10cc53acc1ffa60de3f0d5880a6b72815404c
\ No newline at end of file
+b00cf110b1cc671b7200a5ce8b9e704f660763c9
\ No newline at end of file
index 48885eac01613f33d9f495e2674d70a8fadb2823..f265f0f4a9c9738f3e6f20fda1ca4fa4dbd00773 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.50 2002/02/28 01:46:12 drh Exp $
+** $Id: expr.c,v 1.51 2002/02/28 03:04:48 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -652,7 +652,8 @@ int sqliteExprCheck(Parse *pParse, Expr *pExpr, int allowAgg, int *pIsAgg){
       int i;
       FuncDef *pDef;
 
-      pDef = sqliteFindFunction(pParse->db, pExpr->token.z, pExpr->token.n,n,0);
+      pDef = sqliteFindFunction(pParse->db,
+         pExpr->token.z, pExpr->token.n, n, 0);
       if( pDef==0 ){
         pDef = sqliteFindFunction(pParse->db,
            pExpr->token.z, pExpr->token.n, -1, 0);
@@ -854,14 +855,15 @@ void sqliteExprCode(Parse *pParse, Expr *pExpr){
     case TK_FUNCTION: {
       int i;
       ExprList *pList = pExpr->pList;
+      int nExpr = pList ? pList->nExpr : 0;
       FuncDef *pDef;
       pDef = sqliteFindFunction(pParse->db,
-                      pExpr->token.z, pExpr->token.n, pList->nExpr, 0);
+                      pExpr->token.z, pExpr->token.n, nExpr, 0);
       assert( pDef!=0 );
-      for(i=0; i<pList->nExpr; i++){
+      for(i=0; i<nExpr; i++){
         sqliteExprCode(pParse, pList->a[i].pExpr);
       }
-      sqliteVdbeAddOp(v, OP_Function, pList->nExpr, 0);
+      sqliteVdbeAddOp(v, OP_Function, nExpr, 0);
       sqliteVdbeChangeP3(v, -1, (char*)pDef, P3_POINTER);
       break;
     }
@@ -1246,8 +1248,7 @@ FuncDef *sqliteFindFunction(
     assert( createFlag==0 );
     return pMaybe;
   }
-  if( p==0 && createFlag ){
-    p = sqliteMalloc( sizeof(*p) );
+  if( p==0 && createFlag && (p = sqliteMalloc(sizeof(*p)))!=0 ){
     p->nArg = nArg;
     p->pNext = pFirst;
     sqliteHashInsert(&db->aFunc, zName, nName, (void*)p);
index bd0f606a32c55248772d7a28332f37859645c27a..b7464146fa66f93620621f87ef602f40815f1f14 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.8 2002/02/28 01:46:13 drh Exp $
+** $Id: func.c,v 1.9 2002/02/28 03:04:48 drh Exp $
 */
 #include <ctype.h>
 #include <math.h>
@@ -31,6 +31,7 @@ static void minFunc(sqlite_func *context, int argc, const char **argv){
   const char *zBest; 
   int i;
 
+  if( argc==0 ) return;
   zBest = argv[0];
   for(i=1; i<argc; i++){
     if( sqliteCompare(argv[i], zBest)<0 ){
@@ -43,6 +44,7 @@ static void maxFunc(sqlite_func *context, int argc, const char **argv){
   const char *zBest; 
   int i;
 
+  if( argc==0 ) return;
   zBest = argv[0];
   for(i=1; i<argc; i++){
     if( sqliteCompare(argv[i], zBest)>0 ){
@@ -105,7 +107,7 @@ static void substrFunc(sqlite_func *context, int argc, const char **argv){
   len = strlen(z);
 #endif
   if( p1<0 ){
-    p1 = len-p1;
+    p1 += len;
   }else if( p1>0 ){
     p1--;
   }
@@ -201,9 +203,7 @@ static void sumStep(sqlite_func *context, int argc, const char **argv){
 static void sumFinalize(sqlite_func *context){
   SumCtx *p;
   p = sqlite_aggregate_context(context, sizeof(*p));
-  if( p ){
-    sqlite_set_result_double(context, p->sum);
-  }
+  sqlite_set_result_double(context, p ? p->sum : 0.0);
 }
 static void avgFinalize(sqlite_func *context){
   SumCtx *p;
index f1a769ca949761d842e04fb86cc79735435bd619..ad31ad1d1b2ec622cfe45924cce2d51438df49f1 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.127 2002/02/28 01:46:13 drh Exp $
+** $Id: vdbe.c,v 1.128 2002/02/28 03:04:48 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -552,6 +552,7 @@ char *sqlite_set_result_string(sqlite_func *p, const char *zResult, int n){
     p->s.flags = STK_Null;
     n = 0;
     p->z = 0;
+    p->s.n = 0;
   }else{
     if( n<0 ) n = strlen(zResult);
     if( n<NBFS-1 ){
@@ -567,8 +568,8 @@ char *sqlite_set_result_string(sqlite_func *p, const char *zResult, int n){
       }
       p->s.flags = STK_Str | STK_Dyn;
     }
+    p->s.n = n+1;
   }
-  p->s.n = n;
   return p->z;
 }
 void sqlite_set_result_int(sqlite_func *p, int iResult){
@@ -1878,7 +1879,7 @@ case OP_Function: {
   sqlite_func ctx;
 
   n = pOp->p1;
-  VERIFY( if( n<=0 ) goto bad_instruction; )
+  VERIFY( if( n<0 ) goto bad_instruction; )
   VERIFY( if( p->tos+1<n ) goto not_enough_stack; )
   for(i=p->tos-n+1; i<=p->tos; i++){
     if( (aStack[i].flags & STK_Null)==0 ){
index 066a00fc6b0883b288dd762356f00681983e26bb..af3311c640604b256a7d7fbb9e0345d042a5003d 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.7 2001/12/22 14:49:26 drh Exp $
+# $Id: func.test,v 1.8 2002/02/28 03:04:48 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -34,11 +34,11 @@ do_test func-1.0 {
 do_test func-1.1 {
   set r [catch {execsql {SELECT length(*) FROM tbl1 ORDER BY t1}} msg]
   lappend r $msg
-} {1 {too few arguments to function length()}}
+} {1 {wrong number of arguments to function length()}}
 do_test func-1.2 {
   set r [catch {execsql {SELECT length(t1,5) FROM tbl1 ORDER BY t1}} msg]
   lappend r $msg
-} {1 {too many arguments to function length()}}
+} {1 {wrong number of arguments to function length()}}
 do_test func-1.3 {
   execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1)
            ORDER BY length(t1)}
@@ -131,20 +131,20 @@ do_test func-4.1 {
     INSERT INTO t1 VALUES(3,-2,-5);
   }
   catchsql {SELECT abs(a,b) FROM t1}
-} {1 {too many arguments to function abs()}}
+} {1 {wrong number of arguments to function abs()}}
 do_test func-4.2 {
   catchsql {SELECT abs() FROM t1}
-} {1 {too few arguments to function abs()}}
+} {1 {wrong number of arguments to function abs()}}
 do_test func-4.3 {
   catchsql {SELECT abs(b) FROM t1 ORDER BY a}
 } {0 {2 1.2345678901234 2}}
 do_test func-4.4 {
   catchsql {SELECT abs(c) FROM t1 ORDER BY a}
-} {0 {3 12345.6789 5}}
+} {0 {3 12345.67890 5}}
 
 do_test func-4.5 {
   catchsql {SELECT round(a,b,c) FROM t1}
-} {1 {too many arguments to function round()}}
+} {1 {wrong number of arguments to function round()}}
 do_test func-4.6 {
   catchsql {SELECT round(b,2) FROM t1 ORDER BY b}
 } {0 {-2.00 1.23 2.00}}
@@ -162,6 +162,6 @@ do_test func-4.10 {
 } {0 {x3.0y x-12345.68y x-5.000y}}
 do_test func-4.11 {
   catchsql {SELECT round() FROM t1 ORDER BY a}
-} {1 {too few arguments to function round()}}
+} {1 {wrong number of arguments to function round()}}
 
 finish_test
index b1b18bf67558adfbea4e6f64d1429c2512f1b43d..a138494e69632aa26b42b57c9413014bb11a6125 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the SELECT statement.
 #
-# $Id: select1.test,v 1.19 2002/02/23 23:45:47 drh Exp $
+# $Id: select1.test,v 1.20 2002/02/28 03:04:48 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -107,7 +107,7 @@ execsql {INSERT INTO test1 VALUES(33,44)}
 do_test select1-2.1 {
   set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg]
   lappend v $msg
-} {1 {too many arguments to function count()}}
+} {1 {wrong number of arguments to function count()}}
 do_test select1-2.2 {
   set v [catch {execsql {SELECT count(f1) FROM test1}} msg]
   lappend v $msg
@@ -127,7 +127,7 @@ do_test select1-2.5 {
 do_test select1-2.6 {
   set v [catch {execsql {SELECT min(*) FROM test1}} msg]
   lappend v $msg
-} {1 {too few arguments to function min()}}
+} {0 {{} {}}}
 do_test select1-2.7 {
   set v [catch {execsql {SELECT Min(f1) FROM test1}} msg]
   lappend v $msg
@@ -139,7 +139,7 @@ do_test select1-2.8 {
 do_test select1-2.9 {
   set v [catch {execsql {SELECT MAX(*) FROM test1}} msg]
   lappend v $msg
-} {1 {too few arguments to function MAX()}}
+} {0 {{} {}}}
 do_test select1-2.10 {
   set v [catch {execsql {SELECT Max(f1) FROM test1}} msg]
   lappend v $msg
@@ -159,7 +159,7 @@ do_test select1-2.13 {
 do_test select1-2.14 {
   set v [catch {execsql {SELECT SUM(*) FROM test1}} msg]
   lappend v $msg
-} {1 {too few arguments to function SUM()}}
+} {1 {wrong number of arguments to function SUM()}}
 do_test select1-2.15 {
   set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
   lappend v $msg
@@ -167,7 +167,7 @@ do_test select1-2.15 {
 do_test select1-2.16 {
   set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
   lappend v $msg
-} {1 {too many arguments to function sum()}}
+} {1 {wrong number of arguments to function sum()}}
 do_test select1-2.17 {
   set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
   lappend v $msg
@@ -222,7 +222,7 @@ do_test select1-3.8 {
 do_test select1-3.9 {
   set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg]
   lappend v $msg
-} {1 {misuse of aggregate function count()}}
+} {1 {wrong number of arguments to function count()}}
 
 # ORDER BY expressions
 #
@@ -432,7 +432,7 @@ do_test select1-8.4 {
     SELECT f1/(f1-11), min(f1/(f1-11),5), max(f1/(f1-33),6)
     FROM test1 ORDER BY f1
   }
-} {{} 5 6 1.5 1.5 6}
+} {{} {} 6 1.5 1.5 6}
 do_test select1-8.5 {
   execsql {
     SELECT min(1,2,3), -max(1,2,3)