/ Check-in [d7b3801d]
Login

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

Overview
Comment:Update comment for substrFunc(). Added additional SUBSTR() test cases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d7b3801dc7fad1b002f892fb5d82047ebff98369
User & Date: shaneh 2009-11-12 05:04:50
Context
2009-11-12
13:32
Factor out the code generator for BETWEEN into a subroutine. check-in: 5735f60b user: drh tags: trunk
05:04
Update comment for substrFunc(). Added additional SUBSTR() test cases. check-in: d7b3801d user: shaneh tags: trunk
04:26
Suppress unnecessary OP_Noop instructions on when the right table of a LEFT JOIN uses the index-only optimization. check-in: e8aec08b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

153
154
155
156
157
158
159


160
161
162
163
164
165
166
**
** substr(x,p1,p2)  returns p2 characters of x[] beginning with p1.
** p1 is 1-indexed.  So substr(x,1,1) returns the first character
** of x.  If x is text, then we actually count UTF-8 characters.
** If x is a blob, then we count bytes.
**
** If p1 is negative, then we begin abs(p1) from the end of x[].


*/
static void substrFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *z;







>
>







153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
**
** substr(x,p1,p2)  returns p2 characters of x[] beginning with p1.
** p1 is 1-indexed.  So substr(x,1,1) returns the first character
** of x.  If x is text, then we actually count UTF-8 characters.
** If x is a blob, then we count bytes.
**
** If p1 is negative, then we begin abs(p1) from the end of x[].
**
** If p2 is negative, return the p2 characters preceeding p1.
*/
static void substrFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *z;

Added test/func2.test.































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# 2009 November 11
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    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 built-in functions.
#

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

# Test plan:
#
#   func2-1.*: substr implementation (ascii)
#   func2-2.*: substr implementation (utf8)
#   func2-3.*: substr implementation (blob)
#

proc bin_to_hex {blob} {
  set bytes {}
  binary scan $blob \c* bytes
  set bytes2 [list]
  foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]}
  join $bytes2 {}
}

#----------------------------------------------------------------------------
# Test cases func2-1.*: substr implementation (ascii)
#

do_test func2-1.1 {
  execsql {SELECT 'Supercalifragilisticexpialidocious'}
} {Supercalifragilisticexpialidocious}

# substr(x,y), substr(x,y,z)
do_test func2-1.2.1 {
  catchsql {SELECT SUBSTR()}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-1.2.2 {
  catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious')}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-1.2.3 {
  catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1,1,1)}
} {1 {wrong number of arguments to function SUBSTR()}}

# p1 is 1-indexed
do_test func2-1.3 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.4 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.5 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2)}
} {upercalifragilisticexpialidocious}
do_test func2-1.6 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30)}
} {cious}
do_test func2-1.7 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34)}
} {s}
do_test func2-1.8 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35)}
} {{}}
do_test func2-1.9 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36)}
} {{}}

# if p1<0, start from right
do_test func2-1.10 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.11 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1)}
} {s}
do_test func2-1.12 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2)}
} {us}
do_test func2-1.13 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30)}
} {rcalifragilisticexpialidocious}
do_test func2-1.14 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.15 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35)}
} {Supercalifragilisticexpialidocious}
do_test func2-1.16 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36)}
} {Supercalifragilisticexpialidocious}

# p1 is 1-indexed, p2 length to return
do_test func2-1.17.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 1)}
} {{}}
do_test func2-1.17.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 2)}
} {S}
do_test func2-1.18 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 1)}
} {S}
do_test func2-1.19.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
} {{}}
do_test func2-1.19.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 1)}
} {u}
do_test func2-1.19.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 2)}
} {up}
do_test func2-1.20 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, 1)}
} {c}
do_test func2-1.21 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, 1)}
} {s}
do_test func2-1.22 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, 1)}
} {{}}
do_test func2-1.23 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 1)}
} {{}}

# if p1<0, start from right, p2 length to return
do_test func2-1.24 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0, 1)}
} {{}}
do_test func2-1.25.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 0)}
} {{}}
do_test func2-1.25.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 1)}
} {s}
do_test func2-1.25.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 2)}
} {s}
do_test func2-1.26 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2, 1)}
} {u}
do_test func2-1.27 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30, 1)}
} {r}
do_test func2-1.28.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 0)}
} {{}}
do_test func2-1.28.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 1)}
} {S}
do_test func2-1.28.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 2)}
} {Su}
do_test func2-1.29.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 1)}
} {{}}
do_test func2-1.29.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 2)}
} {S}
do_test func2-1.30.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 0)}
} {{}}
do_test func2-1.30.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 1)}
} {{}}
do_test func2-1.30.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 2)}
} {{}}
do_test func2-1.30.3 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 3)}
} {S}

# p1 is 1-indexed, p2 length to return, p2<0 return p2 chars before p1
do_test func2-1.31.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 0)}
} {{}}
do_test func2-1.31.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -1)}
} {{}}
do_test func2-1.31.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -2)}
} {{}}
do_test func2-1.32.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 0)}
} {{}}
do_test func2-1.32.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, -1)}
} {{}}
do_test func2-1.33.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
} {{}}
do_test func2-1.33.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -1)}
} {S}
do_test func2-1.33.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -2)}
} {S}
do_test func2-1.34.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, 0)}
} {{}}
do_test func2-1.34.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -1)}
} {u}
do_test func2-1.34.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -2)}
} {Su}
do_test func2-1.35.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -1)}
} {o}
do_test func2-1.35.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -2)}
} {do}
do_test func2-1.36 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, -1)}
} {u}
do_test func2-1.37 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, -1)}
} {s}
do_test func2-1.38.0 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 0)}
} {{}}
do_test func2-1.38.1 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -1)}
} {{}}
do_test func2-1.38.2 {
  execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -2)}
} {s}


#----------------------------------------------------------------------------
# Test cases func2-2.*: substr implementation (utf8)
#

# Only do the following tests if TCL has UTF-8 capabilities
#
if {"\u1234"!="u1234"} {

do_test func2-2.1.1 {
  execsql "SELECT 'hi\u1234ho'"
} "hi\u1234ho"

# substr(x,y), substr(x,y,z)
do_test func2-2.1.2 {
  catchsql "SELECT SUBSTR()"
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-2.1.3 {
  catchsql "SELECT SUBSTR('hi\u1234ho')"
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-2.1.4 {
  catchsql "SELECT SUBSTR('hi\u1234ho', 1,1,1)"
} {1 {wrong number of arguments to function SUBSTR()}}

do_test func2-2.2.0 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 0)"
} {{}}
do_test func2-2.2.1 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 1)"
} {{}}
do_test func2-2.2.2 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 2)"
} "h"
do_test func2-2.2.3 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 3)"
} "hi"
do_test func2-2.2.4 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 4)"
} "hi\u1234"
do_test func2-2.2.5 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 5)"
} "hi\u1234h"
do_test func2-2.2.6 {
  execsql "SELECT SUBSTR('hi\u1234ho', 0, 6)"
} "hi\u1234ho"

do_test func2-2.3.0 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 0)"
} {{}}
do_test func2-2.3.1 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 1)"
} "h"
do_test func2-2.3.2 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 2)"
} "hi"
do_test func2-2.3.3 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 3)"
} "hi\u1234"
do_test func2-2.3.4 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 4)"
} "hi\u1234h"
do_test func2-2.3.5 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 5)"
} "hi\u1234ho"
do_test func2-2.3.6 {
  execsql "SELECT SUBSTR('hi\u1234ho', 1, 6)"
} "hi\u1234ho"

do_test func2-2.4.0 {
  execsql "SELECT SUBSTR('hi\u1234ho', 3, 0)"
} {{}}
do_test func2-2.4.1 {
  execsql "SELECT SUBSTR('hi\u1234ho', 3, 1)"
} "\u1234"
do_test func2-2.4.2 {
  execsql "SELECT SUBSTR('hi\u1234ho', 3, 2)"
} "\u1234h"

do_test func2-2.5.0 {
  execsql "SELECT SUBSTR('\u1234', 0, 0)"
} {{}}
do_test func2-2.5.1 {
  execsql "SELECT SUBSTR('\u1234', 0, 1)"
} {{}}
do_test func2-2.5.2 {
  execsql "SELECT SUBSTR('\u1234', 0, 2)"
} "\u1234"
do_test func2-2.5.3 {
  execsql "SELECT SUBSTR('\u1234', 0, 3)"
} "\u1234"

do_test func2-2.6.0 {
  execsql "SELECT SUBSTR('\u1234', 1, 0)"
} {{}}
do_test func2-2.6.1 {
  execsql "SELECT SUBSTR('\u1234', 1, 1)"
} "\u1234"
do_test func2-2.6.2 {
  execsql "SELECT SUBSTR('\u1234', 1, 2)"
} "\u1234"
do_test func2-2.6.3 {
  execsql "SELECT SUBSTR('\u1234', 1, 3)"
} "\u1234"

do_test func2-2.7.0 {
  execsql "SELECT SUBSTR('\u1234', 2, 0)"
} {{}}
do_test func2-2.7.1 {
  execsql "SELECT SUBSTR('\u1234', 2, 1)"
} {{}}
do_test func2-2.7.2 {
  execsql "SELECT SUBSTR('\u1234', 2, 2)"
} {{}}

do_test func2-2.8.0 {
  execsql "SELECT SUBSTR('\u1234', -1, 0)"
} {{}}
do_test func2-2.8.1 {
  execsql "SELECT SUBSTR('\u1234', -1, 1)"
} "\u1234"
do_test func2-2.8.2 {
  execsql "SELECT SUBSTR('\u1234', -1, 2)"
} "\u1234"
do_test func2-2.8.3 {
  execsql "SELECT SUBSTR('\u1234', -1, 3)"
} "\u1234"

} ;# End \u1234!=u1234

#----------------------------------------------------------------------------
# Test cases func2-3.*: substr implementation (blob)
#

ifcapable {!bloblit} {
  finish_test
  return
}

do_test func2-3.1.1 {
  set blob [execsql "SELECT x'1234'"]
  bin_to_hex [lindex $blob 0]
} "1234"

# substr(x,y), substr(x,y,z)
do_test func2-3.1.2 {
  catchsql {SELECT SUBSTR()}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-3.1.3 {
  catchsql {SELECT SUBSTR(x'1234')}
} {1 {wrong number of arguments to function SUBSTR()}}
do_test func2-3.1.4 {
  catchsql {SELECT SUBSTR(x'1234', 1,1,1)}
} {1 {wrong number of arguments to function SUBSTR()}}

do_test func2-3.2.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', 0, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.2.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', 0, 1)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.2.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', 0, 2)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.2.3 {
  set blob [execsql "SELECT SUBSTR(x'1234', 0, 3)"]
  bin_to_hex [lindex $blob 0]
} "1234"

do_test func2-3.3.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.3.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, 1)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.3.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, 2)"]
  bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.3.3 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, 3)"]
  bin_to_hex [lindex $blob 0]
} "1234"

do_test func2-3.4.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.4.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, 1)"]
  bin_to_hex [lindex $blob 0]
} "34"
do_test func2-3.4.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, 2)"]
  bin_to_hex [lindex $blob 0]
} "34"
do_test func2-3.4.3 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, 3)"]
  bin_to_hex [lindex $blob 0]
} "34"

do_test func2-3.5.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.5.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, 1)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.5.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, 2)"]
  bin_to_hex [lindex $blob 0]
} "1234"
do_test func2-3.5.3 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, 3)"]
  bin_to_hex [lindex $blob 0]
} "1234"

do_test func2-3.6.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.6.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, -1)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.6.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, -2)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.6.3 {
  set blob [execsql "SELECT SUBSTR(x'1234', -1, -3)"]
  bin_to_hex [lindex $blob 0]
} "12"

do_test func2-3.7.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.7.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, -1)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.7.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', -2, -2)"]
  bin_to_hex [lindex $blob 0]
} {}

do_test func2-3.8.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.8.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, -1)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.8.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', 1, -2)"]
  bin_to_hex [lindex $blob 0]
} {}

do_test func2-3.9.0 {
  set blob [execsql "SELECT SUBSTR(x'1234', 2, 0)"]
  bin_to_hex [lindex $blob 0]
} {}
do_test func2-3.9.1 {
  set blob [execsql "SELECT SUBSTR(x'1234', 2, -1)"]
  bin_to_hex [lindex $blob 0]
} "12"
do_test func2-3.9.2 {
  set blob [execsql "SELECT SUBSTR(x'1234', 2, -2)"]
  bin_to_hex [lindex $blob 0]
} "12"

finish_test