/ Check-in [92d49499]
Login

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

Overview
Comment:Smaller and hopefully faster routine for converting blob literals into binary. (CVS 4967)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 92d49499ee3371db64267c7e2ba72a5e12ea76f3
User & Date: drh 2008-04-04 15:12:22
Context
2008-04-05
18:41
Add the sqlite3PutVarint32 routine as an alternative to sqlite3PutVarint. Gives 0.5% speed increase. (CVS 4968) check-in: b2517a7d user: drh tags: trunk
2008-04-04
15:12
Smaller and hopefully faster routine for converting blob literals into binary. (CVS 4967) check-in: 92d49499 user: drh tags: trunk
12:21
Fix the output labels on the tests in malloc9. (CVS 4966) check-in: 9987a7b1 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/util.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
593
594
595
596
597
598
599


600
601








602
603
604
605
606
607
608
609

610
611
612
613
614
615
616
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.217 2008/03/19 13:03:34 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>


/*
................................................................................
}



#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
/*
** Translate a single byte of Hex into an integer.


*/
static int hexToInt(int h){








  if( h>='0' && h<='9' ){
    return h - '0';
  }else if( h>='a' && h<='f' ){
    return h - 'a' + 10;
  }else{
    assert( h>='A' && h<='F' );
    return h - 'A' + 10;
  }

}
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */

#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
/*
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
** value.  Return a pointer to its binary value.  Space to hold the







|







 







>
>


>
>
>
>
>
>
>
>








>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.218 2008/04/04 15:12:22 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>


/*
................................................................................
}



#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
/*
** Translate a single byte of Hex into an integer.
** This routinen only works if h really is a valid hexadecimal
** character:  0..9a..fA..F
*/
static int hexToInt(int h){
#if !defined(SQLITE_EBCDIC)
  int x = h - '0';
  if( x>9 ){
    x = (h - 'A' + 10) & 0xf;
  }
  assert( x>=0 && x<=15 );
  return x;
#else
  if( h>='0' && h<='9' ){
    return h - '0';
  }else if( h>='a' && h<='f' ){
    return h - 'a' + 10;
  }else{
    assert( h>='A' && h<='F' );
    return h - 'A' + 10;
  }
#endif
}
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */

#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
/*
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
** value.  Return a pointer to its binary value.  Space to hold the

Changes to test/blob.test.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
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
#    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.
#
# $Id: blob.test,v 1.6 2008/01/22 23:37:10 drh Exp $

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

ifcapable {!bloblit} {
  finish_test
  return
................................................................................
  set blob [execsql {SELECT x'';}]
  bin_to_hex [lindex $blob 0]
} {}
do_test blob-1.3 {
  set blob [execsql {SELECT x'abcdEF12';}]
  bin_to_hex [lindex $blob 0]
} {ABCDEF12}





# Try some syntax errors in blob literals.
do_test blob-1.4 {
  catchsql {SELECT X'01020k304', 100}
} {1 {unrecognized token: "X'01020k304'"}}
do_test blob-1.5 {
  catchsql {SELECT X'01020, 100}
................................................................................
} {1 {unrecognized token: "X'01020, 100"}}
do_test blob-1.6 {
  catchsql {SELECT X'01020 100'}
} {1 {unrecognized token: "X'01020 100'"}}
do_test blob-1.7 {
  catchsql {SELECT X'01001'}
} {1 {unrecognized token: "X'01001'"}}




















# Insert a blob into a table and retrieve it.
do_test blob-2.0 {
  execsql {
    CREATE TABLE t1(a BLOB, b BLOB);
    INSERT INTO t1 VALUES(X'123456', x'7890ab');
    INSERT INTO t1 VALUES(X'CDEF12', x'345678');







|







 







>
>
>
>







 







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







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
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
#    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.
#
# $Id: blob.test,v 1.7 2008/04/04 15:12:22 drh Exp $

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

ifcapable {!bloblit} {
  finish_test
  return
................................................................................
  set blob [execsql {SELECT x'';}]
  bin_to_hex [lindex $blob 0]
} {}
do_test blob-1.3 {
  set blob [execsql {SELECT x'abcdEF12';}]
  bin_to_hex [lindex $blob 0]
} {ABCDEF12}
do_test blob-1.3.2 {
  set blob [execsql {SELECT x'0123456789abcdefABCDEF';}]
  bin_to_hex [lindex $blob 0]
} {0123456789ABCDEFABCDEF}

# Try some syntax errors in blob literals.
do_test blob-1.4 {
  catchsql {SELECT X'01020k304', 100}
} {1 {unrecognized token: "X'01020k304'"}}
do_test blob-1.5 {
  catchsql {SELECT X'01020, 100}
................................................................................
} {1 {unrecognized token: "X'01020, 100"}}
do_test blob-1.6 {
  catchsql {SELECT X'01020 100'}
} {1 {unrecognized token: "X'01020 100'"}}
do_test blob-1.7 {
  catchsql {SELECT X'01001'}
} {1 {unrecognized token: "X'01001'"}}
do_test blob-1.8 {
  catchsql {SELECT x'012/45'}
} {1 {unrecognized token: "x'012/45'"}}
do_test blob-1.9 {
  catchsql {SELECT x'012:45'}
} {1 {unrecognized token: "x'012:45'"}}
do_test blob-1.10 {
  catchsql {SELECT x'012@45'}
} {1 {unrecognized token: "x'012@45'"}}
do_test blob-1.11 {
  catchsql {SELECT x'012G45'}
} {1 {unrecognized token: "x'012G45'"}}
do_test blob-1.12 {
  catchsql {SELECT x'012`45'}
} {1 {unrecognized token: "x'012`45'"}}
do_test blob-1.13 {
  catchsql {SELECT x'012g45'}
} {1 {unrecognized token: "x'012g45'"}}


# Insert a blob into a table and retrieve it.
do_test blob-2.0 {
  execsql {
    CREATE TABLE t1(a BLOB, b BLOB);
    INSERT INTO t1 VALUES(X'123456', x'7890ab');
    INSERT INTO t1 VALUES(X'CDEF12', x'345678');