diff --git a/manifest b/manifest index 3ecd3fe9fc..6ccebcf07b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sthe\snew\sAPI\scalls\smore\sconsistently.\s(CVS\s1459) -D 2004-05-26T02:04:57 +C Use\sthe\snew\sform\sof\sthe\ssqlite3_create_function()\sAPI.\s(CVS\s1460) +D 2004-05-26T06:18:37 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -28,17 +28,17 @@ F src/btree.c 6db76fbf63efd6008c5e6cb038ea40f94abffcf7 F src/btree.h b65140b5ae891f30d2a39e64b9f0343225553545 F src/build.c 35cbeb439b49cca5eb5e8a1de010a5194f4523e8 F src/copy.c 3c4ee52cc6ab3dea44ddfa8426c19155b2bbf242 -F src/date.c 098aee0a006d6e14dcd8f3ad21733691790c4459 +F src/date.c 1a6a72549e1eb8454b8bacb1734892cdcd78cebb F src/delete.c f4a04c0c5c67852a44768c29f408ddda8cfeeab2 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 F src/expr.c 5b283e68bd6df365b7c2ad10bd04cc54c2b4b07c -F src/func.c e67a36ae28ee3495d02261f74989a7bb192658fd +F src/func.c ddd86cbd438e385123785b67bd6c37a40a3c92bd F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb F src/insert.c 48bb15bff280767684a0f9ee4ae5973c9504f880 F src/legacy.c a856d2d5317ed2ac93c2c6cbba7d4faa564a5b20 -F src/main.c c9044ad6896e41aa9bab1957cfd4e9725e5efb01 -F src/md5.c 32ec4d879e9b34d6a597ae8bda684d8e395003f4 +F src/main.c bb49b5a4394e94a56ea25d71bfdfb924bd43b7b6 +F src/md5.c 833671b541a76fc0e62404433c9176706eeacdf0 F src/os.h ab42f4a7c4c716f26b988e759b6e12085a3bfc67 F src/os_common.h 744286a27de55c52f1b18921e8d17abbf7fafc0f F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0 @@ -53,13 +53,13 @@ F src/parse.y 567718866b94d58a6c7681cc45ba7987771d583a F src/pragma.c 02b57adda458874eddc2bd71d56d02e496759a97 F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 -F src/select.c 867cab23c0577d4ac0510c925a85b8e032cfe139 +F src/select.c 42996047868542619a8879bce3b446d92c81ead0 F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f -F src/sqlite.h.in a9d71fd4f781cc61e586b8eabed4d271d88e31c2 +F src/sqlite.h.in c36ab3d4dc1b863ba0cf79905210180b8059a839 F src/sqliteInt.h 6559811caeae0d1855e0b973e363a8c5141e566b F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2 -F src/tclsqlite.c a125a8b99d427e132cb6e728cf9310f6554b410b -F src/test1.c a9f40903f6a14150ca1201da492d4f5a652a1c0c +F src/tclsqlite.c 2700a35f494e8fc5ad2742bcae09d2cb66a295ab +F src/test1.c d23bf61826665d1c6df0d1e565cdf0b7a065e6ce F src/test2.c 6195a1ca2c8d0d2d93644e86da3289b403486872 F src/test3.c 5e4a6d596f982f6f47a5f9f75ede9b4a3b739968 F src/test4.c 014478492bddb3f9b4a3151b05f9ac708fe279fb @@ -70,7 +70,7 @@ F src/update.c 2b5ec85fa19020686ed2fc4a3fc43cbcefbfdfa7 F src/utf.c 1d38da85bffb928fb0d9f301e7db913a6df486ce F src/util.c 4c0adcbc9ce6678dd046931253e45d623c6d279f F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad -F src/vdbe.c 0c10b0036444f99eb625c6a003d007e3043187ef +F src/vdbe.c 4db41e7cc51368614ce8bf428aee1400e471ef1b F src/vdbe.h ebd59ee7a988d39c58b27149593f09a432ad1410 F src/vdbeInt.h c8706615ad49c7a5292daa31425dd1b0b24b3b9b F src/vdbeaux.c a792ac602eb81c15ebdea64931bd3fad85b025f2 @@ -203,7 +203,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P e83138250ce0a8caacbd1822eec2e06796d2f5f2 -R 2d9cfc7b0183db7d18c182936822729e +P 17e7db488dac6b30d174f2272edf1046c2bb9990 +R 113d8544ffd910b3c5420bd788cff980 U danielk1977 -Z a8211c11f21dbceb0c77c5b2788c41e4 +Z bc1bc018e744dabad71dcba7ffcd3363 diff --git a/manifest.uuid b/manifest.uuid index 1201a7037f..7a699cdb7b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -17e7db488dac6b30d174f2272edf1046c2bb9990 \ No newline at end of file +0317bef4b0c219ca2888c90553201e53230fb360 \ No newline at end of file diff --git a/src/date.c b/src/date.c index 4eb2aba5ce..935b086909 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.23 2004/05/25 12:05:57 danielk1977 Exp $ +** $Id: date.c,v 1.24 2004/05/26 06:18:37 danielk1977 Exp $ ** ** NOTES: ** @@ -866,8 +866,8 @@ void sqlite3RegisterDateTimeFunctions(sqlite *db){ int i; for(i=0; i #include @@ -668,16 +668,16 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){ for(i=0; i127 ) return 1; - nName = strlen(zName); - if( nName>255 ) return 1; - p = sqlite3FindFunction(db, zName, nName, nArg, 1); + + if( db==0 || zFunctionName==0 || sqlite3SafetyCheck(db) ){ + return SQLITE_ERROR; + } + if( (xFunc && (xFinal || xStep)) || (!xFunc && (!xFinal && !xStep)) ){ + return SQLITE_ERROR; + } + if( nArg<-1 || nArg>127 ){ + return SQLITE_ERROR; + } + + nName = strlen(zFunctionName); + if( nName>255 ){ + return SQLITE_ERROR; + } + + p = sqlite3FindFunction(db, zFunctionName, nName, nArg, 1); if( p==0 ) return 1; p->xFunc = xFunc; - p->xStep = 0; - p->xFinalize = 0; - p->pUserData = pUserData; - return 0; -} -int sqlite3_create_aggregate( - sqlite *db, /* Add the function to this database connection */ - const char *zName, /* Name of the function to add */ - int nArg, /* Number of arguments */ - void (*xStep)(sqlite3_context*,int,sqlite3_value**), /* The step function */ - void (*xFinalize)(sqlite3_context*), /* The finalizer */ - void *pUserData /* User data */ -){ - FuncDef *p; - int nName; - if( db==0 || zName==0 || sqlite3SafetyCheck(db) ) return 1; - if( nArg<-1 || nArg>127 ) return 1; - nName = strlen(zName); - if( nName>255 ) return 1; - p = sqlite3FindFunction(db, zName, nName, nArg, 1); - if( p==0 ) return 1; - p->xFunc = 0; p->xStep = xStep; - p->xFinalize = xFinalize; + p->xFinalize = xFinal; p->pUserData = pUserData; - return 0; + return SQLITE_OK; +} + +int sqlite3_create_function16( + sqlite3 *db, + const void *zFunctionName, + int nArg, + int eTextRep, + int iCollateArg, + void *pUserData, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*) +){ + int rc; + char *zFunctionName8; + zFunctionName8 = sqlite3utf16to8(zFunctionName, -1, SQLITE3_BIGENDIAN); + if( !zFunctionName8 ){ + return SQLITE_NOMEM; + } + rc = sqlite3_create_function(db, zFunctionName8, nArg, eTextRep, + iCollateArg, pUserData, xFunc, xStep, xFinal); + sqliteFree(zFunctionName8); + return rc; } /* diff --git a/src/md5.c b/src/md5.c index 571132cb6b..ee5cb552e8 100644 --- a/src/md5.c +++ b/src/md5.c @@ -382,7 +382,7 @@ static void md5finalize(sqlite3_context *context){ sqlite3_result_text(context, zBuf, -1, 1); } void Md5_Register(sqlite *db){ - sqlite3_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0); + sqlite3_create_function(db, "md5sum", -1, 0, 0, 0, 0, md5step, md5finalize); } diff --git a/src/select.c b/src/select.c index f9bd39fe16..52c35ebce5 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.175 2004/05/25 23:35:19 danielk1977 Exp $ +** $Id: select.c,v 1.176 2004/05/26 06:18:38 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -1272,9 +1272,9 @@ static int multiSelect( int rc = SQLITE_OK; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ +#if 0 /* NOT USED */ char *affStr = 0; -#if 0 /* NOT USED */ if( !aff ){ int len; rc = fillInColumnList(pParse, p); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 3d8ee52387..a1d8f76499 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.79 2004/05/26 02:04:57 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.80 2004/05/26 06:18:38 danielk1977 Exp $ */ #ifndef _SQLITE_H_ #define _SQLITE_H_ @@ -57,6 +57,8 @@ extern const char sqlite3_encoding[]; ** following opaque structure. */ typedef struct sqlite sqlite; +typedef struct sqlite sqlite3; + /* ** A function to close the database. @@ -417,61 +419,6 @@ void sqlite3_freemem(void *p); const char *sqlite3_libversion(void); const char *sqlite3_libencoding(void); -/* -** A pointer to the following structure is used to communicate with -** the implementations of user-defined functions. -*/ -typedef struct sqlite3_context sqlite3_context; -typedef struct Mem sqlite3_value; - - -/* -** Use the following routines to create new user-defined functions. See -** the documentation for details. -*/ -int sqlite3_create_function( - sqlite*, /* Database where the new function is registered */ - const char *zName, /* Name of the new function */ - int nArg, /* Number of arguments. -1 means any number */ - void (*xFunc)(sqlite3_context*,int,sqlite3_value **), /* C code to implement */ - void *pUserData /* Available via the sqlite3_user_data() call */ -); -int sqlite3_create_aggregate( - sqlite*, /* Database where the new function is registered */ - const char *zName, /* Name of the function */ - int nArg, /* Number of arguments */ - void (*xStep)(sqlite3_context*,int,sqlite3_value**), /* Called for each row */ - void (*xFinalize)(sqlite3_context*), /* Called once to get final result */ - void *pUserData /* Available via the sqlite3_user_data() call */ -); - -/* -** Use the following routine to define the datatype returned by a -** user-defined function. The second argument can be one of the -** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it -** can be an integer greater than or equal to zero. When the datatype -** parameter is non-negative, the type of the result will be the -** same as the datatype-th argument. If datatype==SQLITE_NUMERIC -** then the result is always numeric. If datatype==SQLITE_TEXT then -** the result is always text. If datatype==SQLITE_ARGS then the result -** is numeric if any argument is numeric and is text otherwise. -*/ -int sqlite3_function_type( - sqlite *db, /* The database there the function is registered */ - const char *zName, /* Name of the function */ - int datatype /* The datatype for this function */ -); -#define SQLITE_NUMERIC (-1) -#define SQLITE_TEXT (-2) -#define SQLITE_ARGS (-3) - -/* -** The next routine returns the number of calls to xStep for a particular -** aggregate function instance. The current call to xStep counts so this -** routine always returns at least 1. -*/ -int sqlite3_aggregate_count(sqlite3_context*); - /* ** This routine registers a callback with the SQLite library. The ** callback is invoked (at compile-time, not at run-time) for each @@ -647,11 +594,192 @@ int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out); */ int sqlite_decode_binary(const unsigned char *in, unsigned char *out); +/* +** Open the sqlite database file "filename", where "filename" is UTF-8 +** encoded. An sqlite3* handle is returned in *ppDb, even if an error +** occurs. If the database is opened (or created) successfully, then +** SQLITE_OK is returned. Otherwise an error code is returned and the +** sqlite3_errmsg() function may be used to obtain an English language +** explanation of the error. +** +** If the database file does not exist, then a new database is created +** using UTF-8 text encoding. +** +** Whether or not an error occurs when it is opened, resources associated +** with the sqlite3* handle should be released by passing it to +** sqlite3_close() when it is no longer required. +*/ +int sqlite3_open( + const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + const char **args /* Null terminated array of option strings */ +); -typedef sqlite sqlite3; +/* +** Open the sqlite database file "filename", where "filename" is native +** byte order UTF-16 encoded. An sqlite3* handle is returned in *ppDb, even +** if an error occurs. If the database is opened (or created) successfully, +** then SQLITE_OK is returned. Otherwise an error code is returned and the +** sqlite3_errmsg() function may be used to obtain an English language +** explanation of the error. +** +** If the database file does not exist, then a new database is created +** using UTF-16 text encoding in the machines native byte order. +** +** Whether or not an error occurs when it is opened, resources associated +** with the sqlite3* handle should be released by passing it to +** sqlite3_close() when it is no longer required. +*/ +int sqlite3_open16( + const void *filename, /* Database filename (UTF-16) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + const char **args /* Null terminated array of option strings */ +); +/* +** Return the error code for the most recent sqlite3_* API call associated +** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent +** API call was successful. +** +** Calls to many sqlite3_* functions set the error code and string returned +** by sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16() +** (overwriting the previous values). Note that calls to sqlite3_errcode(), +** sqlite3_errmsg() and sqlite3_errmsg16() themselves do not affect the +** results of future invocations. +** +** Assuming no other intervening sqlite3_* API calls are made, the error +** code returned by this function is associated with the same error as +** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16(). +*/ +int sqlite3_errcode(sqlite3 *db); + +/* +** Return a pointer to a UTF-8 encoded string describing in english the +** error condition for the most recent sqlite3_* API call. The returned +** string is always terminated by an 0x00 byte. +** +** The string "not an error" is returned when the most recent API call was +** successful. +*/ +const char *sqlite3_errmsg(sqlite3*); + +/* +** Return a pointer to a UTF-16 native byte order encoded string describing +** in english the error condition for the most recent sqlite3_* API call. +** The returned string is always terminated by a pair of 0x00 bytes. +** +** The string "not an error" is returned when the most recent API call was +** successful. +*/ +const void *sqlite3_errmsg16(sqlite3*); + +/* +** An instance of the following opaque structure is used to represent +** a compiled SQL statment. +*/ typedef struct sqlite3_stmt sqlite3_stmt; +/* +** To execute an SQL query, it must first be compiled into a byte-code +** program using one of the following routines. The only difference between +** them is that the second argument, specifying the SQL statement to +** compile, is assumed to be encoded in UTF-8 for the sqlite3_prepare() +** function and UTF-16 for sqlite3_prepare16(). +** +** The first parameter "db" is an SQLite database handle. The second +** parameter "zSql" is the statement to be compiled, encoded as either +** UTF-8 or UTF-16 (see above). If the next parameter, "nBytes", is less +** than zero, then zSql is read up to the first nul terminator. If +** "nBytes" is not less than zero, then it is the length of the string zSql +** in bytes (not characters). +** +** *pzTail is made to point to the first byte past the end of the first +** SQL statement in zSql. This routine only compiles the first statement +** in zSql, so *pzTail is left pointing to what remains uncompiled. +** +** *ppStmt is left pointing to a compiled SQL statement that can be +** executed using sqlite3_step(). Or if there is an error, *ppStmt may be +** set to NULL. If the input text contained no SQL (if the input is and +** empty string or a comment) then *ppStmt is set to NULL. +** +** On success, SQLITE_OK is returned. Otherwise an error code is returned. +*/ +int sqlite3_prepare( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nBytes, /* Length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ +); +int sqlite3_prepare16( + sqlite3 *db, /* Database handle */ + const void *zSql, /* SQL statement, UTF-16 encoded */ + int nBytes, /* Length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const void **pzTail /* OUT: Pointer to unused portion of zSql */ +); + +/* +** Return the number of columns in the result set returned by the compiled +** SQL statement. This routine returns 0 if pStmt is an SQL statement +** that does not return data (for example an UPDATE). +*/ +int sqlite3_column_count(sqlite3_stmt *pStmt); + +/* +** The first parameter is a compiled SQL statement. This function returns +** the column heading for the Nth column of that statement, where N is the +** second function parameter. The string returned is UTF-8 encoded. +*/ +const char *sqlite3_column_name(sqlite3_stmt*,int); + +/* +** The first parameter is a compiled SQL statement. This function returns +** the column heading for the Nth column of that statement, where N is the +** second function parameter. The string returned is UTF-16 encoded. +*/ +const void *sqlite3_column_name16(sqlite3_stmt*,int); + +/* +** The first parameter is a compiled SQL statement. If this statement +** is a SELECT statement, the Nth column of the returned result set +** of the SELECT is a table column then the declared type of the table +** column is returned. If the Nth column of the result set is not at table +** column, then a NULL pointer is returned. The returned string is always +** UTF-8 encoded. For example, in the database schema: +** +** CREATE TABLE t1(c1 VARIANT); +** +** And the following statement compiled: +** +** SELECT c1 + 1, 0 FROM t1; +** +** Then this routine would return the string "VARIANT" for the second +** result column (i==1), and a NULL pointer for the first result column +** (i==0). +*/ +const char *sqlite3_column_decltype(sqlite3_stmt *, int i); + +/* +** The first parameter is a compiled SQL statement. If this statement +** is a SELECT statement, the Nth column of the returned result set +** of the SELECT is a table column then the declared type of the table +** column is returned. If the Nth column of the result set is not at table +** column, then a NULL pointer is returned. The returned string is always +** UTF-16 encoded. For example, in the database schema: +** +** CREATE TABLE t1(c1 VARINT); +** +** And the following statement compiled: +** +** SELECT c1 + 1, 0 FROM t1; +** +** Then this routine would return the string "VARIANT" for the second +** result column (i==1), and a NULL pointer for the first result column +** (i==0). +*/ +const void *sqlite3_column_decltype16(sqlite3_stmt*,int); + /* ** This routine is used to bind a 32-bit integer value to a variable ** in an SQL statement compiled by sqlite3_prepare(). See comments for @@ -765,177 +893,6 @@ int sqlite3_bind_text16(sqlite3_stmt*, int i, const void *z, int, int eCopy); */ int sqlite3_bind_blob(sqlite3_stmt*, int i, const void *z, int n, int eCopy); -/* -** Return the error code for the most recent sqlite3_* API call associated -** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent -** API call was successful. -** -** Calls to many sqlite3_* functions set the error code and string returned -** by sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16() -** (overwriting the previous values). A complete list of functions that set -** the error code and string returned by these functions follows. Note that -** calls to sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16() -** themselves do not affect the results of future invocations. -** -** sqlite3_bind_int32 -** sqlite3_bind_int64 -** sqlite3_bind_double -** sqlite3_bind_null -** sqlite3_bind_text -** sqlite3_bind_text16 -** sqlite3_bind_blob -** sqlite3_open -** sqlite3_open16 -** sqlite3_prepare -** sqlite3_prepare16 -** sqlite3_step -** sqlite3_finalize -** -** Assuming no other intervening sqlite3_* API calls are made, the error -** code returned by this function is associated with the same error as -** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16(). -*/ -int sqlite3_errcode(sqlite3 *db); - -/* -** Return a pointer to a UTF-8 encoded string describing in english the -** error condition for the most recent sqlite3_* API call. The returned -** string is always terminated by an 0x00 byte. -** -** The string "not an error" is returned when the most recent API call was -** successful. -*/ -const char *sqlite3_errmsg(sqlite3*); - -/* -** Return a pointer to a UTF-16 native byte order encoded string describing -** in english the error condition for the most recent sqlite3_* API call. -** The returned string is always terminated by a pair of 0x00 bytes. -** -** The string "not an error" is returned when the most recent API call was -** successful. -*/ -const void *sqlite3_errmsg16(sqlite3*); - -/* -** To execute an SQL query, it must first be compiled into a byte-code -** program using this routine. The first parameter "db" is an SQLite -** database handle. The second parameter "zSql" is the statement -** to be compiled, encoded as UTF-8 text. If the next parameter, "nBytes", -** is less than zero, then zSql is read up to the first nul terminator. -** If "nBytes" is not less than zero, then it is the length of the -** string zSql in bytes (not characters). -** -** *pzTail is made to point to the first byte past the end of the first -** SQL statement in zSql. This routine only compiles the first statement -** in zSql, so *pzTail is left pointing to what remains uncompiled. -** -** *ppStmt is left pointing to a compiled SQL statement that can be -** executed using sqlite3_step(). Or if there is an error, *ppStmt may be -** set to NULL. If the input text contained no SQL (if the input is and -** empty string or a comment) then *ppStmt is set to NULL. -** -** On success, SQLITE_OK is returned. Otherwise an error code is returned. -** -*/ -int sqlite3_prepare( - sqlite3 *db, /* Database handle */ - const char *zSql, /* SQL statement, UTF-8 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const char **pzTail /* OUT: Pointer to unused portion of zSql */ -); - -/* -** To execute an SQL query, it must first be compiled into a byte-code -** program using this routine. The first parameter "db" is an SQLite -** database handle. The second parameter "zSql" is the statement -** to be compiled, encoded as UTF-16 text. If the next parameter, "nBytes", -** is less than zero, then zSql is read up to the first pair of successive -** 0x00 bytes. If "nBytes" is not less than zero, then it is the length of -** the string zSql in bytes (not characters). -** -** *pzTail is made to point to the first byte past the end of the first -** SQL statement in zSql. This routine only compiles the first statement -** in zSql, so *pzTail is left pointing to what remains uncompiled. -** -** *ppStmt is left pointing to a compiled SQL statement that can be -** executed using sqlite3_step(). Or if there is an error, *ppStmt may be -** set to NULL. If the input text contained no SQL (if the input is and -** empty string or a comment) then *ppStmt is set to NULL. -** -** On success, SQLITE_OK is returned. Otherwise an error code is returned. -** -*/ -int sqlite3_prepare16( - sqlite3 *db, /* Database handle */ - const void *zSql, /* SQL statement, UTF-16 encoded */ - int nBytes, /* Length of zSql in bytes. */ - sqlite3_stmt **ppStmt, /* OUT: Statement handle */ - const void **pzTail /* OUT: Pointer to unused portion of zSql */ -); - -/* -** Return the number of columns in the result set returned by the compiled -** SQL statement. This routine returns 0 if pStmt is an SQL statement -** that does not return data (for example an UPDATE). -*/ -int sqlite3_column_count(sqlite3_stmt *pStmt); - -/* -** The first parameter is a compiled SQL statement. This function returns -** the column heading for the Nth column of that statement, where N is the -** second function parameter. The string returned is UTF-8 encoded. -*/ -const char *sqlite3_column_name(sqlite3_stmt*,int); - -/* -** The first parameter is a compiled SQL statement. This function returns -** the column heading for the Nth column of that statement, where N is the -** second function parameter. The string returned is UTF-16 encoded. -*/ -const void *sqlite3_column_name16(sqlite3_stmt*,int); - -/* -** The first parameter is a compiled SQL statement. If this statement -** is a SELECT statement, the Nth column of the returned result set -** of the SELECT is a table column then the declared type of the table -** column is returned. If the Nth column of the result set is not at table -** column, then a NULL pointer is returned. The returned string is always -** UTF-8 encoded. For example, in the database schema: -** -** CREATE TABLE t1(c1 VARIANT); -** -** And the following statement compiled: -** -** SELECT c1 + 1, 0 FROM t1; -** -** Then this routine would return the string "VARIANT" for the second -** result column (i==1), and a NULL pointer for the first result column -** (i==0). -*/ -const char *sqlite3_column_decltype(sqlite3_stmt *, int i); - -/* -** The first parameter is a compiled SQL statement. If this statement -** is a SELECT statement, the Nth column of the returned result set -** of the SELECT is a table column then the declared type of the table -** column is returned. If the Nth column of the result set is not at table -** column, then a NULL pointer is returned. The returned string is always -** UTF-16 encoded. For example, in the database schema: -** -** CREATE TABLE t1(c1 VARINT); -** -** And the following statement compiled: -** -** SELECT c1 + 1, 0 FROM t1; -** -** Then this routine would return the string "VARIANT" for the second -** result column (i==1), and a NULL pointer for the first result column -** (i==0). -*/ -const void *sqlite3_column_decltype16(sqlite3_stmt*,int); - /* ** After an SQL query has been compiled with a call to either ** sqlite3_prepare() or sqlite3_prepare16(), then this function must be @@ -970,74 +927,6 @@ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); */ int sqlite3_step(sqlite3_stmt*); - -/* -** The sqlite3_finalize() function is called to delete a compiled -** SQL statement obtained by a previous call to sqlite3_prepare() -** or sqlite3_prepare16(). If the statement was executed successfully, or -** not executed at all, then SQLITE_OK is returned. If execution of the -** statement failed then an error code is returned. -** -** This routine can be called at any point during the execution of the -** virtual machine. If the virtual machine has not completed execution -** when this routine is called, that is like encountering an error or -** an interrupt. (See sqlite3_interrupt().) Incomplete updates may be -** rolled back and transactions cancelled, depending on the circumstances, -** and the result code returned will be SQLITE_ABORT. -*/ -int sqlite3_finalize(sqlite3_stmt *pStmt); - -/* -** The sqlite3_reset() function is called to reset a compiled SQL -** statement obtained by a previous call to sqlite3_prepare() or -** sqlite3_prepare16() back to it's initial state, ready to be re-executed. -** Any SQL statement variables that had values bound to them using -** the sqlite3_bind_*() API retain their values. -*/ -int sqlite3_reset(sqlite3_stmt *pStmt); - -/* -** Open the sqlite database file "filename", where "filename" is UTF-8 -** encoded. An sqlite3* handle is returned in *ppDb, even if an error -** occurs. If the database is opened (or created) successfully, then -** SQLITE_OK is returned. Otherwise an error code is returned and the -** sqlite3_errmsg() function may be used to obtain an English language -** explanation of the error. -** -** If the database file does not exist, then a new database is created -** using UTF-8 text encoding. -** -** Whether or not an error occurs when it is opened, resources associated -** with the sqlite3* handle should be released by passing it to -** sqlite3_close() when it is no longer required. -*/ -int sqlite3_open( - const char *filename, /* Database filename (UTF-8) */ - sqlite3 **ppDb, /* OUT: SQLite db handle */ - const char **args /* Null terminated array of option strings */ -); - -/* -** Open the sqlite database file "filename", where "filename" is native -** byte order UTF-16 encoded. An sqlite3* handle is returned in *ppDb, even -** if an error occurs. If the database is opened (or created) successfully, -** then SQLITE_OK is returned. Otherwise an error code is returned and the -** sqlite3_errmsg() function may be used to obtain an English language -** explanation of the error. -** -** If the database file does not exist, then a new database is created -** using UTF-16 text encoding in the machines native byte order. -** -** Whether or not an error occurs when it is opened, resources associated -** with the sqlite3* handle should be released by passing it to -** sqlite3_close() when it is no longer required. -*/ -int sqlite3_open16( - const void *filename, /* Database filename (UTF-16) */ - sqlite3 **ppDb, /* OUT: SQLite db handle */ - const char **args /* Null terminated array of option strings */ -); - /* ** Return the number of values in the current row of the result set. ** @@ -1152,6 +1041,116 @@ long long int sqlite3_column_int(sqlite3_stmt*,int); */ double sqlite3_column_float(sqlite3_stmt*,int); +/* +** The sqlite3_finalize() function is called to delete a compiled +** SQL statement obtained by a previous call to sqlite3_prepare() +** or sqlite3_prepare16(). If the statement was executed successfully, or +** not executed at all, then SQLITE_OK is returned. If execution of the +** statement failed then an error code is returned. +** +** This routine can be called at any point during the execution of the +** virtual machine. If the virtual machine has not completed execution +** when this routine is called, that is like encountering an error or +** an interrupt. (See sqlite3_interrupt().) Incomplete updates may be +** rolled back and transactions cancelled, depending on the circumstances, +** and the result code returned will be SQLITE_ABORT. +*/ +int sqlite3_finalize(sqlite3_stmt *pStmt); + +/* +** The sqlite3_reset() function is called to reset a compiled SQL +** statement obtained by a previous call to sqlite3_prepare() or +** sqlite3_prepare16() back to it's initial state, ready to be re-executed. +** Any SQL statement variables that had values bound to them using +** the sqlite3_bind_*() API retain their values. +*/ +int sqlite3_reset(sqlite3_stmt *pStmt); + +/* +** Pointers to the following two opaque structures are used to communicate +** with the implementations of user-defined functions. +*/ +typedef struct sqlite3_context sqlite3_context; +typedef struct Mem sqlite3_value; + +/* +** The following two functions are used to add user functions or aggregates +** implemented in C to the SQL langauge interpreted by SQLite. The +** difference only between the two is that the second parameter, the +** name of the (scalar) function or aggregate, is encoded in UTF-8 for +** sqlite3_create_function() and UTF-16 for sqlite3_create_function16(). +** +** The first argument is the database handle that the new function or +** aggregate is to be added to. If a single program uses more than one +** database handle internally, then user functions or aggregates must +** be added individually to each database handle with which they will be +** used. +** +** The third parameter is the number of arguments that the function or +** aggregate takes. If this parameter is negative, then the function or +** aggregate may take any number of arguments. +** +** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are +** pointers to user implemented C functions that implement the user +** function or aggregate. A scalar function requires an implementation of +** the xFunc callback only, NULL pointers should be passed as the xStep +** and xFinal parameters. An aggregate function requires an implementation +** of xStep and xFinal, but NULL should be passed for xFunc. To delete an +** existing user function or aggregate, pass NULL for all three function +** callback. Specifying an inconstent set of callback values, such as an +** xFunc and an xFinal, or an xStep but no xFinal, SQLITE_ERROR is +** returned. +*/ +int sqlite3_create_function( + sqlite3 *, + const char *zFunctionName, + int nArg, + int eTextRep, + int iCollateArg, + void*, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*) +); +int sqlite3_create_function16( + sqlite3*, + const void *zFunctionName, + int nArg, + int eTextRep, + int iCollateArg, + void*, + void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + void (*xStep)(sqlite3_context*,int,sqlite3_value**), + void (*xFinal)(sqlite3_context*) +); + +/* +** Use the following routine to define the datatype returned by a +** user-defined function. The second argument can be one of the +** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it +** can be an integer greater than or equal to zero. When the datatype +** parameter is non-negative, the type of the result will be the +** same as the datatype-th argument. If datatype==SQLITE_NUMERIC +** then the result is always numeric. If datatype==SQLITE_TEXT then +** the result is always text. If datatype==SQLITE_ARGS then the result +** is numeric if any argument is numeric and is text otherwise. +*/ +int sqlite3_function_type( + sqlite *db, /* The database there the function is registered */ + const char *zName, /* Name of the function */ + int datatype /* The datatype for this function */ +); +#define SQLITE_NUMERIC (-1) +#define SQLITE_TEXT (-2) +#define SQLITE_ARGS (-3) + +/* +** The next routine returns the number of calls to xStep for a particular +** aggregate function instance. The current call to xStep counts so this +** routine always returns at least 1. +*/ +int sqlite3_aggregate_count(sqlite3_context*); + /* ** Return the type of the sqlite3_value* passed as the first argument. diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 0b9437ddaa..877ee1056e 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -11,7 +11,7 @@ ************************************************************************* ** A TCL Interface to SQLite ** -** $Id: tclsqlite.c,v 1.70 2004/05/26 02:04:57 danielk1977 Exp $ +** $Id: tclsqlite.c,v 1.71 2004/05/26 06:18:38 danielk1977 Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ @@ -863,7 +863,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ pFunc->pNext = pDb->pFunc; pFunc->zScript = (char*)&pFunc[1]; strcpy(pFunc->zScript, zScript); - sqlite3_create_function(pDb->db, zName, -1, tclSqlFunc, pFunc); + sqlite3_create_function(pDb->db, zName, -1, 0, 0, pFunc, tclSqlFunc, 0, 0); sqlite3_function_type(pDb->db, zName, SQLITE_NUMERIC); break; } diff --git a/src/test1.c b/src/test1.c index aa2a8209f3..b9279d9aee 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.54 2004/05/26 02:04:57 danielk1977 Exp $ +** $Id: test1.c,v 1.55 2004/05/26 06:18:38 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -408,8 +408,9 @@ static int test_create_function( return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; - sqlite3_create_function(db, "x_coalesce", -1, ifnullFunc, 0); - sqlite3_create_function(db, "x_sqlite3_exec", 1, sqlite3ExecFunc, db); + sqlite3_create_function(db, "x_coalesce", -1, 0, 0, 0, ifnullFunc, 0, 0); + sqlite3_create_function(db, "x_sqlite3_exec", 1, 0, 0, db, + sqlite3ExecFunc, 0, 0); return TCL_OK; } @@ -457,8 +458,8 @@ static int test_create_aggregate( return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; - sqlite3_create_aggregate(db, "x_count", 0, countStep, countFinalize, 0); - sqlite3_create_aggregate(db, "x_count", 1, countStep, countFinalize, 0); + sqlite3_create_function(db, "x_count", 0, 0, 0, 0, 0,countStep,countFinalize); + sqlite3_create_function(db, "x_count", 1, 0, 0, 0, 0,countStep,countFinalize); return TCL_OK; } @@ -686,7 +687,7 @@ static int test_register_func( return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; - rc = sqlite3_create_function(db, argv[2], -1, testFunc, 0); + rc = sqlite3_create_function(db, argv[2], -1, 0, 0, 0, testFunc, 0, 0); if( rc!=0 ){ Tcl_AppendResult(interp, sqlite3_error_string(rc), 0); return TCL_ERROR; @@ -1362,7 +1363,7 @@ static int test_step( rc = sqlite3_step(pStmt); if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; - Tcl_SetResult(interp, errorName(rc), 0); + Tcl_SetResult(interp, (char *)errorName(rc), 0); return TCL_OK; } diff --git a/src/vdbe.c b/src/vdbe.c index 2d9a0b0c38..f971a03088 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.331 2004/05/26 02:04:58 danielk1977 Exp $ +** $Id: vdbe.c,v 1.332 2004/05/26 06:18:38 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -574,7 +574,7 @@ const unsigned char *sqlite3_column_data(sqlite3_stmt *pStmt, int i){ ** If a translation fails because of a malloc() failure, a NULL pointer ** is returned. */ -const unsigned char *sqlite3_value_data(sqlite3_value* pVal){ +const unsigned char *sqlite3_value_data(sqlite3_value *pVal){ if( pVal->flags&MEM_Null ){ /* For a NULL return a NULL Pointer */ return 0;