/ Changes On Branch uuid-funcs
Login

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

Changes In Branch uuid-funcs Excluding Merge-Ins

This is equivalent to a diff from 5c118617cf to 97ba442b8d

2019-10-23
18:14
Add uuid_string and uuid_blob functions (Leaf check-in: 97ba442b8d user: numist tags: uuid-funcs)
18:09
When a vector comparison appears in the WHERE clause and the constraint side has a COLLATE clause on the first term of the vector, be sure to honor that COLLATE clause. Ticket [135c9da7513e5a97]. (check-in: 978b2d20cf user: drh tags: trunk)
18:01
Create new branch named "uuid-funcs" (check-in: 815dc0437c user: numist tags: uuid-funcs)
2019-10-22
20:16
Merge the row-value fix from trunk. (check-in: 1fbd743861 user: drh tags: generated-columns)
19:51
Disqualify row-value comparisons for use by an index if the right-hand side has an affinity that does not match the index. Fix for ticket [6ef984af8972c2eb] (check-in: 5c118617cf user: drh tags: trunk)
11:29
Previous check-in to fix [b47e3627ecaadbde] was incomplete. This check-in completes the fix and adds a test cases. (check-in: c7da1c01f1 user: drh tags: trunk)

Changes to src/func.c.

1797
1798
1799
1800
1801
1802
1803


















































































1804
1805
1806
1807
1808
1809
1810
      sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
    }
  }
}
#else
# define groupConcatValue 0
#endif /* SQLITE_OMIT_WINDOWFUNC */



















































































/*
** This routine does per-connection function registration.  Most
** of the built-in functions above are part of the global function set.
** This routine only deals with those that are not global.
*/
void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3 *db){







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







1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
      sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT);
    }
  }
}
#else
# define groupConcatValue 0
#endif /* SQLITE_OMIT_WINDOWFUNC */

/*
** The uuid_blob() function. Interpret the argument as a RFC 4122 UUID string.
** Return a blob representing the parsed UUID.
*/
static void uuidBlob(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  int h, i, j = 0, rc = SQLITE_ERROR;
  unsigned char parsed[16];
  const char *zHex;
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  zHex = sqlite3_value_text(argv[0]);
  if( sqlite3_value_bytes(argv[0])==36 ){
    for (i=0, h = zHex[i]; i <= 36; i++, h=zHex[i]) {
      if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
        if( h !='-' ){
          break;
        }
      }else if (i==36 && h==0 ){
          rc = SQLITE_OK;
      }else{
        if( (h<'0' || h>'9')&&(h<'a'||h>'f')&&(h<'A'||h>'F') ){
          break;
        }
        if( j%2 ){
          parsed[j++ / 2] |= sqlite3HexToInt(h);
        }else{
          parsed[j++ / 2] = sqlite3HexToInt(h) << 4; 
        }
      }
    }
  }
  
  if( rc ){
    sqlite3_result_error(context, "parameter is not a valid UUID", -1);
    return;
  }else{
    sqlite3_result_blob(context, parsed, sizeof(parsed), SQLITE_TRANSIENT);
  }
}

/*
** The uuid_string() function. Argument must be a 128-bit blob. Return a
** RFC 4122 string representation of the blob.
*/
static void uuidString(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  int i, n;
  const unsigned char *pBlob;
  char *zHex, *z;
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  pBlob = sqlite3_value_blob(argv[0]);
  n = sqlite3_value_bytes(argv[0]);
  if( n>16 ){
    sqlite3_result_error_toobig(context);
    return;
  }
  if( n<16 ){
    sqlite3_result_error(context, "parameter too small to print as UUID", -1);
    return;
  }
  z = zHex = contextMalloc(context, 36);
  if( zHex ){
    for(i=0; i<16; i++, pBlob++){
      unsigned char c = *pBlob;
      *(z++) = hexdigits[(c>>4)&0xf];
      *(z++) = hexdigits[c&0xf];
      if( i==3||i==5||i==7||i==9 ){
        *(z++) = '-';
      }
    }
    sqlite3_result_text(context, zHex, 36, sqlite3_free);
  }
}

/*
** This routine does per-connection function registration.  Most
** of the built-in functions above are part of the global function set.
** This routine only deals with those that are not global.
*/
void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3 *db){
1903
1904
1905
1906
1907
1908
1909


1910
1911
1912
1913
1914
1915
1916
  ** The array cannot be constant since changes are made to the
  ** FuncDef.pHash elements at start-time.  The elements of this array
  ** are read-only after initialization is complete.
  **
  ** For peak efficiency, put the most frequently used function last.
  */
  static FuncDef aBuiltinFunc[] = {


#ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
    VFUNCTION(load_extension,    1, 0, 0, loadExt          ),
    VFUNCTION(load_extension,    2, 0, 0, loadExt          ),
#endif







>
>







1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
  ** The array cannot be constant since changes are made to the
  ** FuncDef.pHash elements at start-time.  The elements of this array
  ** are read-only after initialization is complete.
  **
  ** For peak efficiency, put the most frequently used function last.
  */
  static FuncDef aBuiltinFunc[] = {
    FUNCTION(uuid_str,           1, 0, 0, uuidString),
    FUNCTION(uuid_blob,          1, 0, 0, uuidBlob),
#ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
    VFUNCTION(load_extension,    1, 0, 0, loadExt          ),
    VFUNCTION(load_extension,    2, 0, 0, loadExt          ),
#endif