/ Check-in [779fce82]
Login

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

Overview
Comment:Fix SUBSTR() so that it returns NULL if any argument is NULL. Ticket #3626. (CVS 6228)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:779fce82b7a89b972da488ce8bd35e23ca120c04
User & Date: drh 2009-02-01 19:42:38
Context
2009-02-02
01:50
Restrict the RANDOM() function to have zero arguments. Ticket #3627. (CVS 6229) check-in: b8b546b6 user: drh tags: trunk
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
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
...
167
168
169
170
171
172
173





174
175
176
177
178
179
180
** 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"

/*
................................................................................
  const unsigned char *z;
  const unsigned char *z2;
  int len;
  int p0type;
  i64 p1, p2;

  assert( argc==3 || argc==2 );





  p0type = sqlite3_value_type(argv[0]);
  if( p0type==SQLITE_BLOB ){
    len = sqlite3_value_bytes(argv[0]);
    z = sqlite3_value_blob(argv[0]);
    if( z==0 ) return;
    assert( len==sqlite3_value_bytes(argv[0]) );
  }else{







|







 







>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
** 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.214 2009/02/01 19:42:38 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

/*
................................................................................
  const unsigned char *z;
  const unsigned char *z2;
  int len;
  int p0type;
  i64 p1, p2;

  assert( argc==3 || argc==2 );
  if( sqlite3_value_type(argv[1])==SQLITE_NULL
   || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL)
  ){
    return;
  }
  p0type = sqlite3_value_type(argv[0]);
  if( p0type==SQLITE_BLOB ){
    len = sqlite3_value_bytes(argv[0]);
    z = sqlite3_value_blob(argv[0]);
    if( z==0 ) return;
    assert( len==sqlite3_value_bytes(argv[0]) );
  }else{

Changes to test/substr.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
74
75
76
77
78
79
80


















81
82
83
84
85
86
87
#    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.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







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#    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.5 2009/02/01 19:42:38 drh Exp $

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

ifcapable !tclvar {
  finish_test
  return
................................................................................
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 NULL is returned if any parameter is NULL
#
do_test substr-1.90 {
  db eval {SELECT ifnull(substr(NULL,1,1),'nil')}
} nil
do_test substr-1.91 {
  db eval {SELECT ifnull(substr(NULL,1),'nil')}
} nil
do_test substr-1.92 {
  db eval {SELECT ifnull(substr('abcdefg',NULL,1),'nil')}
} nil
do_test substr-1.93 {
  db eval {SELECT ifnull(substr('abcdefg',NULL),'nil')}
} nil
do_test substr-1.94 {
  db eval {SELECT ifnull(substr('abcdefg',1,NULL),'nil')}
} nil

# 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