]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
adding length() and substr() tests. fix shell.c bug (CVS 144)
authordrh <drh@noemail.net>
Mon, 28 Aug 2000 16:21:58 +0000 (16:21 +0000)
committerdrh <drh@noemail.net>
Mon, 28 Aug 2000 16:21:58 +0000 (16:21 +0000)
FossilOrigin-Name: b8cec9b938b4be1ccf230588d8e1564fb3ac4316

VERSION
manifest
manifest.uuid
src/shell.c
src/vdbe.c
test/func.test [new file with mode: 0644]
www/changes.tcl

diff --git a/VERSION b/VERSION
index 21e8796a09d4f26935ffc4879147879a153f0193..ee90284c27f187a315f1267b063fa81b5b84f613 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.3
+1.0.4
index daa7d4f11d6e0a043ee110f49071530fefcb89ac..03d85b4d170fab70c4a87181f0a9e3646a7fb2b4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,9 +1,9 @@
-C Added\slength()\sand\ssubstr()\sfunctions\s(CVS\s143)
-D 2000-08-28T15:51:44
+C adding\slength()\sand\ssubstr()\stests.\s\sfix\sshell.c\sbug\s(CVS\s144)
+D 2000-08-28T16:21:59
 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
 F Makefile.in 036bce328b963f48dbaadbec8cc4144a1fd9e50a
 F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
-F VERSION 8fbc549835992841cbef4232a1d5b86780d3ad5b
+F VERSION a13d4e1d1641b231b44592642d25363ccc2cbb05
 F configure 078a370347baf9375baa8053857ca1e6bc84afa7 x
 F configure.in 381aeb4564f1562b7b2a115f5e99035c561a7fea
 F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
@@ -16,7 +16,7 @@ F src/insert.c f146f149ad2422a1dc3bfa7a1651a25940f98958
 F src/main.c 9a89579b40e498920f86e89878f52185457b9c2c
 F src/parse.y 5d199034de5d29ebedb42c1c51f34db4df40cbe5
 F src/select.c d382e96c2221d08367cc87976f2b574537c9de97
-F src/shell.c 061186b1a4f0884037d067f0f102ec5d382119b5
+F src/shell.c f1ef4268c679e4a9faedc7b0bbf8045d062d1f9c
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in d341439fc1432c7d7014bcff5f7b6e914571232c
 F src/sqliteInt.h b65fdecac7281aafb4c9ff3e79ea1b5546478385
@@ -24,7 +24,7 @@ F src/tclsqlite.c 89dc4ba2b521f3e919d6d7aaa4cc1c2aba8e16f3
 F src/tokenize.c 097bec5843d4a0fb4509e036fee93bac080c5e73
 F src/update.c 51b9ef7434b15e31096155da920302e9db0d27fc
 F src/util.c b75b33e6bd5d47898bb7ed9fdd0dea4fe7c19b00
-F src/vdbe.c a2372aebfcf2a5ed4530cd956a8cdbb595c67991
+F src/vdbe.c 4dd50dbbfb753bae763f0e4eb21b1d17f5cc1423
 F src/vdbe.h 6413cd0165ac62b0839fe3e077cb7c9f0b736295
 F src/where.c 3dfad2ffd0aa994d5eceac88852f7189c8d1d3c8
 F test/all.test 0950c135cab7e60c07bd745ccfad1476211e5bd7
@@ -32,6 +32,7 @@ F test/copy.test b77a1214bd7756f2849d5c4fa6e715c0ff0c34eb
 F test/dbbe.test c6079572516aeb2739a35fd272b105c45c30cc76
 F test/delete.test 402ee3ccb6e544582d24c573ef70b34d09583ae7
 F test/expr.test 09b55ccf81cb8cc2f9cd83d592a2ba187ee48ba8
+F test/func.test 02aed8845b98bde1043dda97455de1d37238ebb3
 F test/in.test 2c560c0f55fb777029fd9bb5378f2997582aa603
 F test/index.test 950be6116122c6e2db7c2c345eabcdb854ced1d0
 F test/insert.test 66f4c3bd600fec8eb1e733b928cbe6fa885eff0c
@@ -61,7 +62,7 @@ F www/arch.fig 4e26e9dca3c49724fc8f554c695ddea9f2413156
 F www/arch.png c4d908b79065a72e7dcf19317f36d1324c550e87
 F www/arch.tcl 4f6a9afecc099a27bba17b4f8cc9561abc15dc40
 F www/c_interface.tcl 1b79e404a0dd46f44cd453a44b01df568c9586d1
-F www/changes.tcl a457553fce8400977cc484ae47a0a2011491bb7f
+F www/changes.tcl 3f58bd3095d46f73f5b04f4584aa9a628586cdaf
 F www/crosscompile.tcl 19734ce7f18b16ff2ed8479412abf8aca56e1dcc
 F www/fileformat.tcl cfb7fba80b7275555281ba2f256c00734bcdd1c9
 F www/index.tcl 2f5cc070b8fa8c3fc2f71bba4e6b7877d528fbde
@@ -70,7 +71,7 @@ F www/mingw.tcl fc5f4ba9d336b6e8c97347cc6496d6162461ef60
 F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
 F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
 F www/vdbe.tcl bcbfc33bcdd0ebad95eab31286adb9e1bc289520
-P d35a1f8b37333e2df86c22c2dbd766132b4931b2
-R 33478b7323acb1d67e1ce4b66b8bba30
+P 0eef538f3de66fede7c88f8be8c3458d84107c3f
+R b19d9376e2ed736a8c71d021909787e7
 U drh
-Z a1f7d622d82864a914f4580098647f78
+Z a629695fda46772305184d1159d79249
index 8b147137cd9d1c57f779b688a7ad9b85fb94403d..1a647189cf079cb739720131c556a7dbe704a7ce 100644 (file)
@@ -1 +1 @@
-0eef538f3de66fede7c88f8be8c3458d84107c3f
\ No newline at end of file
+b8cec9b938b4be1ccf230588d8e1564fb3ac4316
\ No newline at end of file
index bc05f76edd12657a6f1d673582ddd1fac251b9ed..0d5198aa36d93516005a2e17f4c90bc5237547a6 100644 (file)
@@ -24,7 +24,7 @@
 ** This file contains code to implement the "sqlite" command line
 ** utility for accessing SQLite databases.
 **
-** $Id: shell.c,v 1.23 2000/08/22 13:40:19 drh Exp $
+** $Id: shell.c,v 1.24 2000/08/28 16:21:59 drh Exp $
 */
 #include <stdlib.h>
 #include <string.h>
@@ -253,9 +253,9 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
              w = 0;
           }
           if( w<=0 ){
-            w = strlen(azCol[i]);
+            w = strlen(azCol[i] ? azCol[i] : "");
             if( w<10 ) w = 10;
-            n = strlen(azArg[i]);
+            n = strlen(azArg[i] ? azArg[i] : "");
             if( w<n ) w = n;
           }
           if( i<ArraySize(p->actualWidth) ){
index d258beaa5ee21bda438a842f1ccf0e972694b5d5..d174cbbbc99c13906b960dbf2a5d439973b77390 100644 (file)
@@ -41,7 +41,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.39 2000/08/28 15:51:44 drh Exp $
+** $Id: vdbe.c,v 1.40 2000/08/28 16:22:00 drh Exp $
 */
 #include "sqliteInt.h"
 #include <unistd.h>
@@ -3185,28 +3185,31 @@ int sqliteVdbeExec(
         if( pOp->p1==0 ){
           if( p->tos<0 ) goto not_enough_stack;
           Integerify(p, p->tos);
-          start = p->aStack[p->tos].i;
+          start = p->aStack[p->tos].i - 1;
           PopStack(p, 1);
         }else{
-          start = pOp->p1;
+          start = pOp->p1 - 1;
         }
         if( p->tos<0 ) goto not_enough_stack;
         Stringify(p, p->tos);
         n = p->aStack[p->tos].n - 1;
         if( start<0 ){
-          start += n;
+          start += n + 1;
           if( start<0 ){
             cnt += start;
             start = 0;
           }
         }
+        if( start>n ){
+          start = n;
+        }
         if( cnt<0 ) cnt = 0;
         if( cnt > n ){
           cnt = n;
         }
         z = sqliteMalloc( cnt+1 );
         if( z==0 ) goto no_mem;
-        strncpy(z, p->zStack[p->tos], cnt);
+        strncpy(z, &p->zStack[p->tos][start], cnt);
         z[cnt] = 0;
         PopStack(p, 1);
         p->tos++;
diff --git a/test/func.test b/test/func.test
new file mode 100644 (file)
index 0000000..52d7db2
--- /dev/null
@@ -0,0 +1,92 @@
+# Copyright (c) 1999, 2000 D. Richard Hipp
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA  02111-1307, USA.
+#
+# Author contact information:
+#   drh@hwaci.com
+#   http://www.hwaci.com/drh/
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing built-in functions.
+#
+# $Id: func.test,v 1.1 2000/08/28 16:22:00 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Create a table to work with.
+#
+execsql {CREATE TABLE tbl1(t1 text)}
+foreach word {this program is free software} {
+  execsql "INSERT INTO tbl1 VALUES('$word')"
+}
+
+# Make sure the table was created properly.
+#
+do_test func-0.0 {
+  execsql {SELECT t1 FROM tbl1 ORDER BY t1}
+} {free is program software this}
+
+# Check out the length() function
+#
+do_test func-1.0 {
+  execsql {SELECT length(t1) FROM tbl1 ORDER BY t1}
+} {4 2 7 8 4}
+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()}}
+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()}}
+do_test func-1.3 {
+  execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1)
+           ORDER BY length(t1)}
+} {2 1 4 2 7 1 8 1}
+
+# Check out the substr() function
+#
+do_test func-2.0 {
+  execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1}
+} {fr is pr so th}
+do_test func-2.1 {
+  execsql {SELECT substr(t1,2,1) FROM tbl1 ORDER BY t1}
+} {r s r o h}
+do_test func-2.2 {
+  execsql {SELECT substr(t1,3,3) FROM tbl1 ORDER BY t1}
+} {ee {} ogr ftw is}
+do_test func-2.3 {
+  execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1}
+} {e s m e s}
+do_test func-2.4 {
+  execsql {SELECT substr(t1,-1,2) FROM tbl1 ORDER BY t1}
+} {e s m e s}
+do_test func-2.5 {
+  execsql {SELECT substr(t1,-2,1) FROM tbl1 ORDER BY t1}
+} {e i a r i}
+do_test func-2.6 {
+  execsql {SELECT substr(t1,-2,2) FROM tbl1 ORDER BY t1}
+} {ee is am re is}
+do_test func-2.7 {
+  execsql {SELECT substr(t1,-4,2) FROM tbl1 ORDER BY t1}
+} {fr {} gr wa th}
+do_test func-2.8 {
+  execsql {SELECT t1 FROM tbl1 ORDER BY substr(t1,2,20)}
+} {this software free program is}
+
+finish_test
index fe7fb32957e88fb8007093f3da4da6f54c5922b4..58d21db3251a916bec505817d3aceb6662303957 100644 (file)
@@ -17,6 +17,13 @@ proc chng {date desc} {
   puts "<DD><P><UL>$desc</UL></P></DD>"
 }
 
+chng {2000 Aug 28 (Version 1.0.4)} {
+<li>Added functions <b>length()</b> and <b>substr()</b>.</li>
+<li>Fix a bug in the <b>sqlite</b> shell program that was causing
+    a coredump when the output mode was "column" and the first row
+    of data contained a NULL.</li>
+}
+
 chng {2000 Aug 22 (Version 1.0.3)} {
 <li>In the sqlite shell, print the "Database opened READ ONLY" message
     to stderr instead of stdout.</li>