/ Check-in [2217339b]
Login

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

Overview
Comment:Fix the SUBSTR() function so that when the 3rd argument is negative, it counts backwards from the selected start point. Ticket #3625. (CVS 6227)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2217339badf1e84edbed1309c39b9f8dfd7646ff
User & Date: drh 2009-02-01 19:23:32
Context
2009-02-01
19:42
Fix SUBSTR() so that it returns NULL if any argument is NULL. Ticket #3626. (CVS 6228) check-in: 779fce82 user: drh tags: trunk
19:23
Fix the SUBSTR() function so that when the 3rd argument is negative, it counts backwards from the selected start point. Ticket #3625. (CVS 6227) check-in: 2217339b user: drh tags: trunk
18:08
Change the replace() function to return a copy of its first argument when the 2nd argument is an empty string. Ticket #3624. (CVS 6226) check-in: ffebf10f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
195
196
197
198
199
200
201








202
203
204
205
206
207
208
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.212 2009/02/01 18:08:41 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

/*
................................................................................
    p1 += len;
    if( p1<0 ){
      p2 += p1;
      p1 = 0;
    }
  }else if( p1>0 ){
    p1--;








  }
  if( p1+p2>len ){
    p2 = len-p1;
  }
  if( p0type!=SQLITE_BLOB ){
    while( *z && p1 ){
      SQLITE_SKIP_UTF8(z);







|







 







>
>
>
>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.213 2009/02/01 19:23:32 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

/*
................................................................................
    p1 += len;
    if( p1<0 ){
      p2 += p1;
      p1 = 0;
    }
  }else if( p1>0 ){
    p1--;
  }
  if( p2<0 ){
    p1 += p2;
    p2 = -p2;
    if( p1<0 ){
      p2 += p1;
      p1 = 0;
    }
  }
  if( p1+p2>len ){
    p2 = len-p1;
  }
  if( p0type!=SQLITE_BLOB ){
    while( *z && p1 ){
      SQLITE_SKIP_UTF8(z);

Changes to test/substr.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
68
69
70
71
72
73
74






75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
#    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 the built-in SUBSTR() functions.
#
# $Id: substr.test,v 1.3 2007/10/12 19:11:55 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !tclvar {
  finish_test
  return
................................................................................
substr-test 1.4 abcdefg 1 100 abcdefg
substr-test 1.5 abcdefg 0 1 a
substr-test 1.6 abcdefg -1 1 g
substr-test 1.7 abcdefg -1 10 g
substr-test 1.8 abcdefg -5 3 cde
substr-test 1.9 abcdefg -7 3 abc
substr-test 1.10 abcdefg -100 98 abcde







# Make sure everything works with long unicode characters
#
substr-test 2.1 \u1234\u2345\u3456 1 1 \u1234
substr-test 2.2 \u1234\u2345\u3456 2 1 \u2345
substr-test 2.3 \u1234\u2345\u3456 1 2 \u1234\u2345
substr-test 2.4 \u1234\u2345\u3456 -1 1 \u3456
substr-test 2.5 a\u1234b\u2345c\u3456c -5 3 b\u2345c


# Basic functionality for BLOBs
#
subblob-test 3.1 61626364656667 1 1 61
subblob-test 3.2 61626364656667 2 1 62
subblob-test 3.3 61626364656667 1 2 6162
subblob-test 3.4 61626364656667 1 100 61626364656667







|







 







>
>
>
>
>
>








>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#    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 the built-in SUBSTR() functions.
#
# $Id: substr.test,v 1.4 2009/02/01 19:23:32 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !tclvar {
  finish_test
  return
................................................................................
substr-test 1.4 abcdefg 1 100 abcdefg
substr-test 1.5 abcdefg 0 1 a
substr-test 1.6 abcdefg -1 1 g
substr-test 1.7 abcdefg -1 10 g
substr-test 1.8 abcdefg -5 3 cde
substr-test 1.9 abcdefg -7 3 abc
substr-test 1.10 abcdefg -100 98 abcde
substr-test 1.11 abcdefg 5 -1 d
substr-test 1.12 abcdefg 5 -4 abcd
substr-test 1.13 abcdefg 5 -5 abcd
substr-test 1.14 abcdefg -5 -1 b
substr-test 1.15 abcdefg -5 -2 ab
substr-test 1.16 abcdefg -5 -3 ab

# Make sure everything works with long unicode characters
#
substr-test 2.1 \u1234\u2345\u3456 1 1 \u1234
substr-test 2.2 \u1234\u2345\u3456 2 1 \u2345
substr-test 2.3 \u1234\u2345\u3456 1 2 \u1234\u2345
substr-test 2.4 \u1234\u2345\u3456 -1 1 \u3456
substr-test 2.5 a\u1234b\u2345c\u3456c -5 3 b\u2345c
substr-test 2.6 a\u1234b\u2345c\u3456c -2 -3 b\u2345c

# Basic functionality for BLOBs
#
subblob-test 3.1 61626364656667 1 1 61
subblob-test 3.2 61626364656667 2 1 62
subblob-test 3.3 61626364656667 1 2 6162
subblob-test 3.4 61626364656667 1 100 61626364656667