/ Check-in [b8cec9b9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:adding length() and substr() tests. fix shell.c bug (CVS 144)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b8cec9b938b4be1ccf230588d8e1564fb3ac4316
User & Date: drh 2000-08-28 16:21:59
Context
2000-08-28
16:25
Version 1.0.4 (CVS 496) check-in: 92346e00 user: drh tags: trunk
16:21
adding length() and substr() tests. fix shell.c bug (CVS 144) check-in: b8cec9b9 user: drh tags: trunk
15:51
Added length() and substr() functions (CVS 143) check-in: 0eef538f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to VERSION.

     1         -1.0.3
            1  +1.0.4

Changes to src/shell.c.

    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains code to implement the "sqlite" command line
    25     25   ** utility for accessing SQLite databases.
    26     26   **
    27         -** $Id: shell.c,v 1.23 2000/08/22 13:40:19 drh Exp $
           27  +** $Id: shell.c,v 1.24 2000/08/28 16:21:59 drh Exp $
    28     28   */
    29     29   #include <stdlib.h>
    30     30   #include <string.h>
    31     31   #include <stdio.h>
    32     32   #include "sqlite.h"
    33     33   #include <unistd.h>
    34     34   #include <ctype.h>
................................................................................
   249    249             int w, n;
   250    250             if( i<ArraySize(p->colWidth) ){
   251    251                w = p->colWidth[i];
   252    252             }else{
   253    253                w = 0;
   254    254             }
   255    255             if( w<=0 ){
   256         -            w = strlen(azCol[i]);
          256  +            w = strlen(azCol[i] ? azCol[i] : "");
   257    257               if( w<10 ) w = 10;
   258         -            n = strlen(azArg[i]);
          258  +            n = strlen(azArg[i] ? azArg[i] : "");
   259    259               if( w<n ) w = n;
   260    260             }
   261    261             if( i<ArraySize(p->actualWidth) ){
   262    262               p->actualWidth[i] = w; 
   263    263             }
   264    264             if( p->showHeader ){
   265    265               fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");

Changes to src/vdbe.c.

    37     37   ** inplicit conversion from one type to the other occurs as necessary.
    38     38   ** 
    39     39   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    40     40   ** function which does the work of interpreting a VDBE program.
    41     41   ** But other routines are also provided to help in building up
    42     42   ** a program instruction by instruction.
    43     43   **
    44         -** $Id: vdbe.c,v 1.39 2000/08/28 15:51:44 drh Exp $
           44  +** $Id: vdbe.c,v 1.40 2000/08/28 16:22:00 drh Exp $
    45     45   */
    46     46   #include "sqliteInt.h"
    47     47   #include <unistd.h>
    48     48   
    49     49   /*
    50     50   ** SQL is translated into a sequence of instructions to be
    51     51   ** executed by a virtual machine.  Each instruction is an instance
................................................................................
  3181   3181             PopStack(p, 1);
  3182   3182           }else{
  3183   3183             cnt = pOp->p2;
  3184   3184           }
  3185   3185           if( pOp->p1==0 ){
  3186   3186             if( p->tos<0 ) goto not_enough_stack;
  3187   3187             Integerify(p, p->tos);
  3188         -          start = p->aStack[p->tos].i;
         3188  +          start = p->aStack[p->tos].i - 1;
  3189   3189             PopStack(p, 1);
  3190   3190           }else{
  3191         -          start = pOp->p1;
         3191  +          start = pOp->p1 - 1;
  3192   3192           }
  3193   3193           if( p->tos<0 ) goto not_enough_stack;
  3194   3194           Stringify(p, p->tos);
  3195   3195           n = p->aStack[p->tos].n - 1;
  3196   3196           if( start<0 ){
  3197         -          start += n;
         3197  +          start += n + 1;
  3198   3198             if( start<0 ){
  3199   3199               cnt += start;
  3200   3200               start = 0;
  3201   3201             }
         3202  +        }
         3203  +        if( start>n ){
         3204  +          start = n;
  3202   3205           }
  3203   3206           if( cnt<0 ) cnt = 0;
  3204   3207           if( cnt > n ){
  3205   3208             cnt = n;
  3206   3209           }
  3207   3210           z = sqliteMalloc( cnt+1 );
  3208   3211           if( z==0 ) goto no_mem;
  3209         -        strncpy(z, p->zStack[p->tos], cnt);
         3212  +        strncpy(z, &p->zStack[p->tos][start], cnt);
  3210   3213           z[cnt] = 0;
  3211   3214           PopStack(p, 1);
  3212   3215           p->tos++;
  3213   3216           p->zStack[p->tos] = z;
  3214   3217           p->aStack[p->tos].n = cnt + 1;
  3215   3218           p->aStack[p->tos].flags = STK_Str|STK_Dyn;
  3216   3219           break;

Added test/func.test.

            1  +# Copyright (c) 1999, 2000 D. Richard Hipp
            2  +#
            3  +# This program is free software; you can redistribute it and/or
            4  +# modify it under the terms of the GNU General Public
            5  +# License as published by the Free Software Foundation; either
            6  +# version 2 of the License, or (at your option) any later version.
            7  +#
            8  +# This program is distributed in the hope that it will be useful,
            9  +# but WITHOUT ANY WARRANTY; without even the implied warranty of
           10  +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
           11  +# General Public License for more details.
           12  +# 
           13  +# You should have received a copy of the GNU General Public
           14  +# License along with this library; if not, write to the
           15  +# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
           16  +# Boston, MA  02111-1307, USA.
           17  +#
           18  +# Author contact information:
           19  +#   drh@hwaci.com
           20  +#   http://www.hwaci.com/drh/
           21  +#
           22  +#***********************************************************************
           23  +# This file implements regression tests for SQLite library.  The
           24  +# focus of this file is testing built-in functions.
           25  +#
           26  +# $Id: func.test,v 1.1 2000/08/28 16:22:00 drh Exp $
           27  +
           28  +set testdir [file dirname $argv0]
           29  +source $testdir/tester.tcl
           30  +
           31  +# Create a table to work with.
           32  +#
           33  +execsql {CREATE TABLE tbl1(t1 text)}
           34  +foreach word {this program is free software} {
           35  +  execsql "INSERT INTO tbl1 VALUES('$word')"
           36  +}
           37  +
           38  +# Make sure the table was created properly.
           39  +#
           40  +do_test func-0.0 {
           41  +  execsql {SELECT t1 FROM tbl1 ORDER BY t1}
           42  +} {free is program software this}
           43  +
           44  +# Check out the length() function
           45  +#
           46  +do_test func-1.0 {
           47  +  execsql {SELECT length(t1) FROM tbl1 ORDER BY t1}
           48  +} {4 2 7 8 4}
           49  +do_test func-1.1 {
           50  +  set r [catch {execsql {SELECT length(*) FROM tbl1 ORDER BY t1}} msg]
           51  +  lappend r $msg
           52  +} {1 {too few arguments to function length()}}
           53  +do_test func-1.2 {
           54  +  set r [catch {execsql {SELECT length(t1,5) FROM tbl1 ORDER BY t1}} msg]
           55  +  lappend r $msg
           56  +} {1 {too many arguments to function length()}}
           57  +do_test func-1.3 {
           58  +  execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1)
           59  +           ORDER BY length(t1)}
           60  +} {2 1 4 2 7 1 8 1}
           61  +
           62  +# Check out the substr() function
           63  +#
           64  +do_test func-2.0 {
           65  +  execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1}
           66  +} {fr is pr so th}
           67  +do_test func-2.1 {
           68  +  execsql {SELECT substr(t1,2,1) FROM tbl1 ORDER BY t1}
           69  +} {r s r o h}
           70  +do_test func-2.2 {
           71  +  execsql {SELECT substr(t1,3,3) FROM tbl1 ORDER BY t1}
           72  +} {ee {} ogr ftw is}
           73  +do_test func-2.3 {
           74  +  execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1}
           75  +} {e s m e s}
           76  +do_test func-2.4 {
           77  +  execsql {SELECT substr(t1,-1,2) FROM tbl1 ORDER BY t1}
           78  +} {e s m e s}
           79  +do_test func-2.5 {
           80  +  execsql {SELECT substr(t1,-2,1) FROM tbl1 ORDER BY t1}
           81  +} {e i a r i}
           82  +do_test func-2.6 {
           83  +  execsql {SELECT substr(t1,-2,2) FROM tbl1 ORDER BY t1}
           84  +} {ee is am re is}
           85  +do_test func-2.7 {
           86  +  execsql {SELECT substr(t1,-4,2) FROM tbl1 ORDER BY t1}
           87  +} {fr {} gr wa th}
           88  +do_test func-2.8 {
           89  +  execsql {SELECT t1 FROM tbl1 ORDER BY substr(t1,2,20)}
           90  +} {this software free program is}
           91  +
           92  +finish_test

Changes to www/changes.tcl.

    12     12   }
    13     13   
    14     14   
    15     15   proc chng {date desc} {
    16     16     puts "<DT><B>$date</B></DT>"
    17     17     puts "<DD><P><UL>$desc</UL></P></DD>"
    18     18   }
           19  +
           20  +chng {2000 Aug 28 (Version 1.0.4)} {
           21  +<li>Added functions <b>length()</b> and <b>substr()</b>.</li>
           22  +<li>Fix a bug in the <b>sqlite</b> shell program that was causing
           23  +    a coredump when the output mode was "column" and the first row
           24  +    of data contained a NULL.</li>
           25  +}
    19     26   
    20     27   chng {2000 Aug 22 (Version 1.0.3)} {
    21     28   <li>In the sqlite shell, print the "Database opened READ ONLY" message
    22     29       to stderr instead of stdout.</li>
    23     30   <li>In the sqlite shell, now print the version number on initial startup.</li>
    24     31   <li>Add the <b>sqlite_version[]</b> string constant to the library</li>
    25     32   <li>Makefile updates</li>