diff options
author | Scott Hess <shess@chromium.org> | 2015-02-10 13:33:29 -0800 |
---|---|---|
committer | Scott Hess <shess@chromium.org> | 2015-02-10 21:37:23 +0000 |
commit | dcf12048055030a2b5858ceca5ce26294a82a6e4 (patch) | |
tree | c84f0e56702c610d82cf961829c6766d281dc98b /third_party/sqlite/src/ext/misc/fileio.c | |
parent | 22a8af1afb44b29cfcee081f492ac1f434b54201 (diff) | |
download | chromium_src-dcf12048055030a2b5858ceca5ce26294a82a6e4.zip chromium_src-dcf12048055030a2b5858ceca5ce26294a82a6e4.tar.gz chromium_src-dcf12048055030a2b5858ceca5ce26294a82a6e4.tar.bz2 |
Import SQLite 3.8.7.4.
Ran through the import script in third_party/sqlite/README.Chromium,
including the SQLite test suite. There are a few pager errors which
are because of a change required for WebDatabase support (documented
in README).
SQLite changes are at http://www.sqlite.org/changes.html , Chromium
previously used 3.7.6.3.
All patches were applied and the results reviewed to make sure
backported patches were safe to remove, and retained patches were still
covering what was necessary.
Keep fts4 disabled, and also the new fts3 virtual table and unicode61
tokenizer. Once enabled, these are very hard to disable, and there
doesn't seem to be any pressure to enable them. Other SQLITE_* flags
were reviewed for applicability, none looked essential.
Fixes to Chromium:
- In recovery.cc, pk_column now follows the documentation.
- Short garbage files now see SQLITE_NOTADB rather than
SQLITE_IOERR_SHORT_READ.
- Adjust to allow clients to use ScopedErrorIgnore without adding
dependencies.
- More-specific SQLITE_CONSTRAINT_* errors aren't necessary.
- Force recovery test to scan table rather than index.
BUG=340757
TEST=*EVERYTHING* continues to work.
R=michaeln@chromium.org
Review URL: https://codereview.chromium.org/901033002
Cr-Commit-Position: refs/heads/master@{#315646}
Diffstat (limited to 'third_party/sqlite/src/ext/misc/fileio.c')
-rw-r--r-- | third_party/sqlite/src/ext/misc/fileio.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/third_party/sqlite/src/ext/misc/fileio.c b/third_party/sqlite/src/ext/misc/fileio.c new file mode 100644 index 0000000..fbe2d03 --- /dev/null +++ b/third_party/sqlite/src/ext/misc/fileio.c @@ -0,0 +1,100 @@ +/* +** 2014-06-13 +** +** 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. +** +****************************************************************************** +** +** This SQLite extension implements SQL functions readfile() and +** writefile(). +*/ +#include "sqlite3ext.h" +SQLITE_EXTENSION_INIT1 +#include <stdio.h> + +/* +** Implementation of the "readfile(X)" SQL function. The entire content +** of the file named X is read and returned as a BLOB. NULL is returned +** if the file does not exist or is unreadable. +*/ +static void readfileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + const char *zName; + FILE *in; + long nIn; + void *pBuf; + + zName = (const char*)sqlite3_value_text(argv[0]); + if( zName==0 ) return; + in = fopen(zName, "rb"); + if( in==0 ) return; + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc( nIn ); + if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + sqlite3_result_blob(context, pBuf, nIn, sqlite3_free); + }else{ + sqlite3_free(pBuf); + } + fclose(in); +} + +/* +** Implementation of the "writefile(X,Y)" SQL function. The argument Y +** is written into file X. The number of bytes written is returned. Or +** NULL is returned if something goes wrong, such as being unable to open +** file X for writing. +*/ +static void writefileFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + FILE *out; + const char *z; + sqlite3_int64 rc; + const char *zFile; + + zFile = (const char*)sqlite3_value_text(argv[0]); + if( zFile==0 ) return; + out = fopen(zFile, "wb"); + if( out==0 ) return; + z = (const char*)sqlite3_value_blob(argv[1]); + if( z==0 ){ + rc = 0; + }else{ + rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out); + } + fclose(out); + sqlite3_result_int64(context, rc); +} + + +#ifdef _WIN32 +__declspec(dllexport) +#endif +int sqlite3_fileio_init( + sqlite3 *db, + char **pzErrMsg, + const sqlite3_api_routines *pApi +){ + int rc = SQLITE_OK; + SQLITE_EXTENSION_INIT2(pApi); + (void)pzErrMsg; /* Unused parameter */ + rc = sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0, + readfileFunc, 0, 0); + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, + writefileFunc, 0, 0); + } + return rc; +} |