diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-06 22:39:41 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-06 22:39:41 +0000 |
commit | 586381f8db3497c24c11f96234f1879b34e74bc7 (patch) | |
tree | 99f7d18350289b135ef6dd5c161baba8bce668a3 /third_party/sqlite/src/test_loadext.c | |
parent | 6e3b12ff2cbbe8c481f986c8f0dd230bb50add2a (diff) | |
download | chromium_src-586381f8db3497c24c11f96234f1879b34e74bc7.zip chromium_src-586381f8db3497c24c11f96234f1879b34e74bc7.tar.gz chromium_src-586381f8db3497c24c11f96234f1879b34e74bc7.tar.bz2 |
Upgrade our sqlite to 3.6.1, with the local changes made by Gears. I'm
checking in the full sqlite tree to make upstream merges easier. This means
we'll have generated sources split out from the originals.
One important change this makes is that "BEGIN" now defaults to "BEGIN
IMMEDIATE" rather than "BEGIN DEFERRED". This doesn't affect us because we
don't use unqualified BEGIN statements.
The full CL is too big for Rietveld. I'm splitting it into 2. This one is
reviewable. The other CL is just a fresh drop of:
//depot/googleclient/gears/opensource/third_party/sqlite_google
Review URL: http://codereview.chromium.org/15067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7623 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/sqlite/src/test_loadext.c')
-rwxr-xr-x | third_party/sqlite/src/test_loadext.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/third_party/sqlite/src/test_loadext.c b/third_party/sqlite/src/test_loadext.c new file mode 100755 index 0000000..e973566 --- /dev/null +++ b/third_party/sqlite/src/test_loadext.c @@ -0,0 +1,124 @@ +/* +** 2006 June 14 +** +** 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. +** +************************************************************************* +** Test extension for testing the sqlite3_load_extension() function. +** +** $Id: test_loadext.c,v 1.3 2008/08/02 03:50:39 drh Exp $ +*/ +#include <string.h> +#include "sqlite3ext.h" +SQLITE_EXTENSION_INIT1 + +/* +** The half() SQL function returns half of its input value. +*/ +static void halfFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + sqlite3_result_double(context, 0.5*sqlite3_value_double(argv[0])); +} + +/* +** SQL functions to call the sqlite3_status function and return results. +*/ +static void statusFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + int op, mx, cur, resetFlag, rc; + if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ + op = sqlite3_value_int(argv[0]); + }else if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){ + int i; + const char *zName; + static const struct { + const char *zName; + int op; + } aOp[] = { + { "MEMORY_USED", SQLITE_STATUS_MEMORY_USED }, + { "PAGECACHE_USED", SQLITE_STATUS_PAGECACHE_USED }, + { "PAGECACHE_OVERFLOW", SQLITE_STATUS_PAGECACHE_OVERFLOW }, + { "SCRATCH_USED", SQLITE_STATUS_SCRATCH_USED }, + { "SCRATCH_OVERFLOW", SQLITE_STATUS_SCRATCH_OVERFLOW }, + { "MALLOC_SIZE", SQLITE_STATUS_MALLOC_SIZE }, + }; + int nOp = sizeof(aOp)/sizeof(aOp[0]); + zName = (const char*)sqlite3_value_text(argv[0]); + for(i=0; i<nOp; i++){ + if( strcmp(aOp[i].zName, zName)==0 ){ + op = aOp[i].op; + break; + } + } + if( i>=nOp ){ + char *zMsg = sqlite3_mprintf("unknown status property: %s", zName); + sqlite3_result_error(context, zMsg, -1); + sqlite3_free(zMsg); + return; + } + }else{ + sqlite3_result_error(context, "unknown status type", -1); + return; + } + if( argc==2 ){ + resetFlag = sqlite3_value_int(argv[1]); + }else{ + resetFlag = 0; + } + rc = sqlite3_status(op, &cur, &mx, resetFlag); + if( rc!=SQLITE_OK ){ + char *zMsg = sqlite3_mprintf("sqlite3_status(%d,...) returns %d", op, rc); + sqlite3_result_error(context, zMsg, -1); + sqlite3_free(zMsg); + return; + } + if( argc==2 ){ + sqlite3_result_int(context, mx); + }else{ + sqlite3_result_int(context, cur); + } +} + +/* +** Extension load function. +*/ +int testloadext_init( + sqlite3 *db, + char **pzErrMsg, + const sqlite3_api_routines *pApi +){ + int nErr = 0; + SQLITE_EXTENSION_INIT2(pApi); + nErr |= sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0); + nErr |= sqlite3_create_function(db, "sqlite3_status", 1, SQLITE_ANY, 0, + statusFunc, 0, 0); + nErr |= sqlite3_create_function(db, "sqlite3_status", 2, SQLITE_ANY, 0, + statusFunc, 0, 0); + return nErr ? SQLITE_ERROR : SQLITE_OK; +} + +/* +** Another extension entry point. This one always fails. +*/ +int testbrokenext_init( + sqlite3 *db, + char **pzErrMsg, + const sqlite3_api_routines *pApi +){ + char *zErr; + SQLITE_EXTENSION_INIT2(pApi); + zErr = sqlite3_mprintf("broken!"); + *pzErrMsg = zErr; + return 1; +} |