2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A** The author disclaims copyright to this source code. In place of 2N/A** a legal notice, here is a blessing: 2N/A** May you do good and not evil. 2N/A** May you find forgiveness for yourself and forgive others. 2N/A** May you share freely, never taking more than you give. 2N/A************************************************************************* 2N/A** This file contains the C functions that implement various SQL 2N/A** functions of SQLite. 2N/A** There is only one exported symbol in this file - the function 2N/A** sqliteRegisterBuildinFunctions() found at the bottom of the file. 2N/A** All other code has file scope. 2N/A** $Id: func.c,v 1.43.2.3 2004/07/18 23:03:11 drh Exp $ 2N/A** Implementation of the non-aggregate min() and max() functions 2N/A int mask;
/* 0 for min() or 0xffffffff for max() */ 2N/A** Return the type of the argument. 2N/A** Implementation of the length() function 2N/A for(
len=0; *z; z++){
if( (
0xc0&*z)!=
0x80 )
len++; }
2N/A** Implementation of the abs() function 2N/A** Implementation of the substr() function 2N/A for(i=0; i<
p1 && z[i]; i++){
2N/A if( (z[i]&
0xc0)==
0x80 )
p1++;
2N/A while( z[i] && (z[i]&
0xc0)==
0x80 ){ i++;
p1++; }
2N/A if( (z[i]&
0xc0)==
0x80 )
p2++;
2N/A while( z[i] && (z[i]&
0xc0)==
0x80 ){ i++;
p2++; }
2N/A** Implementation of the round() function 2N/A** Implementation of the upper() and lower() SQL functions. 2N/A for(i=0; z[i]; i++){
2N/A for(i=0; z[i]; i++){
2N/A * A utility wrapper around u8_textprep_str() that returns an allocated 2N/A * string. The result must be freed or passed to 2N/A * sqlite_set_result_string(). 2N/A * This is a Solaris-specific function, though it could be made 2N/A * portable. u8_textprep_str() and friends are CDDL'ed. This code was 2N/A * added to this file without changing the public domain notice, and 2N/A * therefore is in the public domain as well. 2N/A * u8_textprep_str() does not allocate memory. The input and 2N/A * output buffers may differ in size (though that would be more 2N/A * likely when normalization is done). We have to loop over it... 2N/A * To improve the chances that we can avoid looping we add 10 2N/A * bytes of output buffer room the first go around. 2N/A /* adjust outbytesleft and outlen */ 2N/A * A Unicode-capable case-folding (to lower) function 2N/A * See block comment for case_fold_utf8(). 2N/A * SQLite functions can take many arguments, but this function 2N/A * uses only one, and we call sqlite_create_function() with 2N/A * SQLite functions can take many arguments, but this function 2N/A * uses only one, and we call sqlite_create_function() with 2N/A** Implementation of the IFNULL(), NVL(), and COALESCE() functions. 2N/A** All three do the same thing. They return the first non-NULL 2N/A** Implementation of random(). Return a random integer. 2N/A** Implementation of the last_insert_rowid() SQL function. The return 2N/A** value is the same as the sqlite_last_insert_rowid() API function. 2N/A** Implementation of the change_count() SQL function. The return 2N/A** value is the same as the sqlite_changes() API function. 2N/A** Implementation of the last_statement_change_count() SQL function. The 2N/A** return value is the same as the sqlite_last_statement_changes() API function. 2N/A** Implementation of the like() SQL function. This function implements 2N/A** the build-in LIKE operator. The first argument to the function is the 2N/A** string and the second argument is the pattern. So, the SQL statements: 2N/A** is implemented as like(A,B). 2N/A** Implementation of the glob() SQL function. This function implements 2N/A** the build-in GLOB operator. The first argument to the function is the 2N/A** string and the second argument is the pattern. So, the SQL statements: 2N/A** is implemented as glob(A,B). 2N/A** Implementation of the NULLIF(x,y) function. The result is the first 2N/A** argument if the arguments are different. The result is NULL if the 2N/A** arguments are equal to each other. 2N/A** Implementation of the VERSION(*) function. The result is the version 2N/A** of the SQLite library that is running. 2N/A** EXPERIMENTAL - This is not an official function. The interface may 2N/A** change. This function may disappear. Do not write code that depends 2N/A** Implementation of the QUOTE() function. This function takes a single 2N/A** argument. If the argument is numeric, the return value is the same as 2N/A** the argument. If the argument is NULL, the return value is the string 2N/A** "NULL". Otherwise, the argument is enclosed in single quotes with 2N/A** single-quote escapes. 2N/A for(i=n=0;
argv[0][i]; i++){
if(
argv[0][i]==
'\'' ) n++; }
2N/A** Compute the soundex encoding of a word. 2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2N/A 0, 0,
1,
2,
3, 0,
1,
2, 0, 0,
2,
2,
4,
5,
5, 0,
2N/A 1,
2,
6,
2,
3, 0,
1, 0,
2, 0,
2, 0, 0, 0, 0, 0,
2N/A 0, 0,
1,
2,
3, 0,
1,
2, 0, 0,
2,
2,
4,
5,
5, 0,
2N/A 1,
2,
6,
2,
3, 0,
1, 0,
2, 0,
2, 0, 0, 0, 0, 0,
2N/A** This function generates a string of random characters. Used for 2N/A** generating test data. 2N/A static const unsigned char zSrc[] =
2N/A "abcdefghijklmnopqrstuvwxyz" 2N/A "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 2N/A** An instance of the following structure holds the context of a 2N/A** sum() or avg() aggregate computation. 2N/A double sum;
/* Sum of terms */ 2N/A int cnt;
/* Number of elements summed */ 2N/A** Routines used to compute the sum or average. 2N/A** An instance of the following structure holds the context of a 2N/A** variance or standard deviation computation. 2N/A double sum;
/* Sum of terms */ 2N/A double sum2;
/* Sum of the squares of terms */ 2N/A int cnt;
/* Number of terms counted */ 2N/A#
if 0
/* Omit because math library is required */ 2N/A** Routines used to compute the standard deviation as an aggregate. 2N/A** The following structure keeps track of state information for the 2N/A** count() aggregate function. 2N/A** Routines to implement the count() aggregate function. 2N/A** This function tracks state information for the min() and max() 2N/A** aggregate functions. 2N/A char *z;
/* The best so far */ 2N/A char zBuf[
28];
/* Space that can be used for storage */ 2N/A** Routines to implement min() and max() aggregate functions. 2N/A int mask;
/* 0 for min() or 0xffffffff for max() */ 2N/A if(
argv[0]==0 )
return;
/* Ignore NULL values */ 2N/A if( p->z==0 )
return;
2N/A** This function registered all of the above C functions as SQL 2N/A** functions. This should be the only routine in this file with 2N/A {
"min", 0, 0, 0, 0 },
2N/A {
"max", 0, 0,
2, 0 },
2N/A {
"coalesce", 0, 0, 0, 0 },
2N/A {
"coalesce",
1, 0, 0, 0 },
2N/A {
"last_statement_change_count",