diff --git a/.gitignore b/.gitignore index 1197bbe86..07656be63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,37 @@ -*.dylib -*.so -*.o -*.lo -*.Makefile -*.target.gyp.mk -lib/binding -build -out -Release -Debug +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/ + +# Dependency directory node_modules -.deps -Makefile.gyp -gyp-mac-tool -.dirstamp -npm-debug.log -test/support/big.db -test/tmp -test/nw/app.nw + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Project specific +lib/binding .DS_Store -.idea diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 733dbe72a..000000000 --- a/.npmignore +++ /dev/null @@ -1,12 +0,0 @@ -.gitignore -.npmignore -node_modules -lib/binding -build -test -benchmark -configure -Makefile -scripts -.travis.yml -examples diff --git a/LICENSE.md b/LICENSE.md index dfc771ddc..d20384405 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,12 +1,4 @@ -This project is a fork of node-sqlite3 (https://github.com/mapbox/node-sqlite3). -As such, copyright for portions of this project are held by MapBox as part of -node-sqlite3, under "The BSD-3-Clause License". All other copyright for this -project are held by Joshua Wise, under "The MIT License". - - - -The MIT License -=============== +The MIT License (MIT) Copyright (c) 2016 Joshua Wise @@ -17,44 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - - - -The BSD-3-Clause License -=============== - -Copyright (c) MapBox -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, this - list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. -- Neither the name "MapBox" nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 69da97254..c21338308 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# sqlite3-plus +# better-sqlite3 *You want [Node](http://nodejs.org/)?* @@ -6,23 +6,21 @@ *You want your life to be* **easy?** -##### **Well you're in luck because sqlite3-plus is here!!!!** +##### **Well you're in luck because better-sqlite3 is here!!!!** ## Installation ```bash -npm install --save sqlite3-plus +npm install --save better-sqlite3 ``` ## Usage ```js -var sql = require('sqlite3-plus').verbose(); -var db = new sql.Database(':memory:'); +var Database = require('better-sqlite3'); +var db = new Database('foobar.db', {memory: true, wal: false}); ``` -The `statement.pluck()` method will return the wrong data if the specified column's position in the table changes (by dropping and recreating the table). - ## Features - Full transaction support @@ -30,22 +28,6 @@ The `statement.pluck()` method will return the wrong data if the specified colum - Big test suite - Written in modern C++ and tested for memory leaks -# Contributors - -* [Konstantin Käfer](https://github.com/kkaefer) -* [Dane Springmeyer](https://github.com/springmeyer) -* [Will White](https://github.com/willwhite) -* [Orlando Vazquez](https://github.com/orlandov) -* [Artem Kustikov](https://github.com/artiz) -* [Eric Fredricksen](https://github.com/grumdrig) -* [John Wright](https://github.com/mrjjwright) -* [Ryan Dahl](https://github.com/ry) -* [Tom MacWright](https://github.com/tmcw) -* [Carter Thaxton](https://github.com/carter-thaxton) -* [Audrius Kažukauskas](https://github.com/audriusk) -* [Johannes Schauer](https://github.com/pyneo) -* [Mithgol](https://github.com/Mithgol) - # License -[BSD and MIT licensed](https://github.com/JoshuaWise/node-sqlite3-plus/blob/master/LICENSE.md). +[MIT](https://github.com/JoshuaWise/better-sqlite3/blob/master/LICENSE.md). diff --git a/TODO b/TODO index d0a9190ee..c5532b9ee 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,13 @@ ---------- Polish ---------- -investigate BEGIN IMMEDIATE as an alternative to mutexes -(if we dont need sqlite3_last_insert_rowid or sqlite3_changes, do we get a performance boost?) - use SQLITE_ENABLE_API_ARMOR compilation option while developing +add db method for setting pragma on both connections, synchronously + +think of a way to deal with 64bit integers + ---------- Package ---------- deal with ./test/ and .travis.yml +compare tests with node-sqlite3 ---------- Executable ---------- diff --git a/binding.gyp b/binding.gyp index bd26af4ea..f0b7b233d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,8 +1,8 @@ { - "includes": [ "deps/common-sqlite.gypi" ], + "includes": [ "deps/common.gypi" ], "targets": [ { - "target_name": "sqlite3_plus", + "target_name": "better_sqlite3", "include_dirs": [" in ' + name; - err.stack += '\n' + filter(error).slice(1).join('\n'); - err.__augmented = true; - } - throw err; - } - }; - } - return old.apply(this, arguments); - }; -} -exports.extendTrace = extendTrace; - - -function filter(error) { - return error.stack.split('\n').filter(function(line) { - return line.indexOf(__filename) < 0; - }); -} diff --git a/package.json b/package.json index 9d700a097..7847122ea 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,13 @@ { - "name": "sqlite3-plus", - "description": "Simple and expressive SQLite3 bindings for Node.js, with full transaction support.", - "version": "4.0.0", - "homepage": "http://github.com/JoshuaWise/node-sqlite3-plus", + "name": "better-sqlite3", + "version": "0.5.0", + "description": "Simple and expressive SQLite3 bindings for Node.js, with full transaction support", + "homepage": "http://github.com/JoshuaWise/better-sqlite3", "author": "Joshua Wise ", - "contributors": [ - "MapBox", - "Konstantin Käfer ", - "Dane Springmeyer ", - "Will White ", - "Orlando Vazquez ", - "Artem Kustikov ", - "Eric Fredricksen ", - "John Wright ", - "Ryan Dahl ", - "Tom MacWright ", - "Carter Thaxton ", - "Audrius Kažukauskas ", - "Johannes Schauer ", - "Nathan Rajlich ", - "AJ ONeal ", - "Mithgol", - "Ben Noordhuis " - ], "gypfile": true, "repository": { "type": "git", - "url": "git://github.com/JoshuaWise/node-sqlite3-plus.git" + "url": "git://github.com/JoshuaWise/better-sqlite3.git" }, "dependencies": { "bindings": "^1.2.1", @@ -34,20 +15,19 @@ "to-descriptor": "^1.0.1" }, "devDependencies": { - "mocha": "~2.3.3" + "chai": "^3.5.0", + "mocha": "^3.0.2" }, "scripts": { "install": "node-gyp rebuild", - "pretest": "node test/support/createdb.js", - "test": "$(npm bin)/mocha -R spec --timeout 480000" + "test": "$(npm bin)/mocha --timeout 5000 --slow 5000" }, - "license": "(MIT OR BSD-3-Clause)", + "license": "MIT", "keywords": [ "sql", "sqlite", "sqlite3", "database", "transactions" - ], - "main": "./lib/sqlite3-plus.js" + ] } diff --git a/src/sqlite3_plus.cc b/src/better_sqlite3.cc similarity index 85% rename from src/sqlite3_plus.cc rename to src/better_sqlite3.cc index 6fce9ad3d..1784cb20e 100644 --- a/src/sqlite3_plus.cc +++ b/src/better_sqlite3.cc @@ -10,4 +10,4 @@ NAN_MODULE_INIT(RegisterModule) { Statement::Init(); Transaction::Init(); } -NODE_MODULE(sqlite3_plus, RegisterModule); +NODE_MODULE(better_sqlite3, RegisterModule); diff --git a/src/binder/binder.h b/src/binder/binder.h index 52210df65..877d542df 100644 --- a/src/binder/binder.h +++ b/src/binder/binder.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_BINDER_H -#define NODE_SQLITE3_PLUS_BINDER_H +#ifndef BETTER_SQLITE3_BINDER_H +#define BETTER_SQLITE3_BINDER_H #include #include diff --git a/src/multi-binder/multi-binder.h b/src/multi-binder/multi-binder.h index af06211a3..34e20ddbf 100644 --- a/src/multi-binder/multi-binder.h +++ b/src/multi-binder/multi-binder.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_MULTIBINDER_H -#define NODE_SQLITE3_PLUS_MULTIBINDER_H +#ifndef BETTER_SQLITE3_MULTIBINDER_H +#define BETTER_SQLITE3_MULTIBINDER_H #include #include diff --git a/src/objects/database/database.cc b/src/objects/database/database.cc index 7e500d5b3..a1a013243 100644 --- a/src/objects/database/database.cc +++ b/src/objects/database/database.cc @@ -57,6 +57,7 @@ NAN_MODULE_INIT(Database::Init) { Nan::GetFunction(t).ToLocalChecked()); } +// Returns an SQLite3 result code. int Database::CloseHandles() { delete t_handles; int status1 = sqlite3_close(read_handle); diff --git a/src/objects/database/database.h b/src/objects/database/database.h index 07f67f424..233451a21 100644 --- a/src/objects/database/database.h +++ b/src/objects/database/database.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_DATABASE_H -#define NODE_SQLITE3_PLUS_DATABASE_H +#ifndef BETTER_SQLITE3_DATABASE_H +#define BETTER_SQLITE3_DATABASE_H // Dependencies #include diff --git a/src/objects/statement/build-bind-map.cc b/src/objects/statement/build-bind-map.cc deleted file mode 100644 index 0a86873ca..000000000 --- a/src/objects/statement/build-bind-map.cc +++ /dev/null @@ -1,12 +0,0 @@ -void Statement::BuildBindMap() { - int param_count = sqlite3_bind_parameter_count(st_handle); - v8::Local cons = v8::Local::Cast(db->handle()->GetHiddenValue(NEW_INTERNAL_STRING_FAST("NullFactory"))); - v8::Local namedParams = Nan::NewInstance(cons).ToLocalChecked(); - for (int i=1; i<=param_count; ++i) { - const char* name = sqlite3_bind_parameter_name(st_handle, i); - if (name != NULL) { - Nan::ForceSet(namedParams, NEW_INTERNAL_STRING8(name + 1), Nan::New((double)i)); - } - } - handle()->SetHiddenValue(NEW_INTERNAL_STRING_FAST("bindMap"), namedParams); -} diff --git a/src/objects/statement/statement.cc b/src/objects/statement/statement.cc index 63db4ba34..18e767fd1 100644 --- a/src/objects/statement/statement.cc +++ b/src/objects/statement/statement.cc @@ -18,7 +18,7 @@ #include "get.cc" #include "all.cc" #include "each.cc" -#include "build-bind-map.cc" +#include "util.cc" Statement::Statement() : Nan::ObjectWrap(), st_handle(NULL), @@ -47,9 +47,7 @@ void Statement::Init() { } CONSTRUCTOR(Statement::constructor); -bool Statement::Compare::operator() (const Statement* a, const Statement* b) { - return a->id < b->id; -} +// Returns true if the handles have not been previously closed. bool Statement::CloseHandles() { if (st_handle) { sqlite3_clear_bindings(st_handle); @@ -59,13 +57,3 @@ bool Statement::CloseHandles() { } return false; } -bool Statement::CloseIfPossible() { - if (!(state & BUSY)) { - CloseHandles(); - return true; - } - return false; -} -void Statement::EraseFromSet() { - db->stmts.erase(this); -} diff --git a/src/objects/statement/statement.h b/src/objects/statement/statement.h index 6abdd5d2e..e2fc0e68c 100644 --- a/src/objects/statement/statement.h +++ b/src/objects/statement/statement.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_STATEMENT_H -#define NODE_SQLITE3_PLUS_STATEMENT_H +#ifndef BETTER_SQLITE3_STATEMENT_H +#define BETTER_SQLITE3_STATEMENT_H // Dependencies #include diff --git a/src/objects/statement/util.cc b/src/objects/statement/util.cc new file mode 100644 index 000000000..4b143393c --- /dev/null +++ b/src/objects/statement/util.cc @@ -0,0 +1,34 @@ +// Used by std::set to organize the pointers it holds. +bool Statement::Compare::operator() (const Statement* a, const Statement* b) { + return a->id < b->id; +} + +// Closes all associated sqlite3 handles if the statement is not busy. +// Returns false if the transaction is busy. +bool Statement::CloseIfPossible() { + if (!(state & BUSY)) { + CloseHandles(); + return true; + } + return false; +} + +// Removes itself from its database's associated std::set. +void Statement::EraseFromSet() { + db->stmts.erase(this); +} + +// Builds a JavaScript object that maps the statement's parameter names +// with the parameter index of each one. +void Statement::BuildBindMap() { + int param_count = sqlite3_bind_parameter_count(st_handle); + v8::Local cons = v8::Local::Cast(db->handle()->GetHiddenValue(NEW_INTERNAL_STRING_FAST("NullFactory"))); + v8::Local namedParams = Nan::NewInstance(cons).ToLocalChecked(); + for (int i=1; i<=param_count; ++i) { + const char* name = sqlite3_bind_parameter_name(st_handle, i); + if (name != NULL) { + Nan::ForceSet(namedParams, NEW_INTERNAL_STRING8(name + 1), Nan::New((double)i)); + } + } + handle()->SetHiddenValue(NEW_INTERNAL_STRING_FAST("bindMap"), namedParams); +} diff --git a/src/objects/transaction/transaction.cc b/src/objects/transaction/transaction.cc index d6a4e0551..cd33a9a59 100644 --- a/src/objects/transaction/transaction.cc +++ b/src/objects/transaction/transaction.cc @@ -10,7 +10,7 @@ #include "busy.cc" #include "bind.cc" #include "run.cc" -#include "build-bind-map.cc" +#include "util.cc" Transaction::Transaction() : Nan::ObjectWrap(), handles(NULL), @@ -35,9 +35,7 @@ void Transaction::Init() { } CONSTRUCTOR(Transaction::constructor); -bool Transaction::Compare::operator() (const Transaction* a, const Transaction* b) { - return a->id < b->id; -} +// Returns true if the handles have not been previously closed. bool Transaction::CloseHandles() { if (handles) { for (unsigned int i=0; itranss.erase(this); -} diff --git a/src/objects/transaction/transaction.h b/src/objects/transaction/transaction.h index 61d64c15d..806811553 100644 --- a/src/objects/transaction/transaction.h +++ b/src/objects/transaction/transaction.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_TRANSACTION_H -#define NODE_SQLITE3_PLUS_TRANSACTION_H +#ifndef BETTER_SQLITE3_TRANSACTION_H +#define BETTER_SQLITE3_TRANSACTION_H // Dependencies #include diff --git a/src/objects/transaction/build-bind-map.cc b/src/objects/transaction/util.cc similarity index 53% rename from src/objects/transaction/build-bind-map.cc rename to src/objects/transaction/util.cc index 217ceb0de..1f8bfb911 100644 --- a/src/objects/transaction/build-bind-map.cc +++ b/src/objects/transaction/util.cc @@ -1,3 +1,26 @@ +// Used by std::set to organize the pointers it holds. +bool Transaction::Compare::operator() (const Transaction* a, const Transaction* b) { + return a->id < b->id; +} + +// Closes all associated sqlite3 handles if the transaction is not busy. +// Returns false if the transaction is busy. +bool Transaction::CloseIfPossible() { + if (!(state & BUSY)) { + CloseHandles(); + return true; + } + return false; +} + +// Removes itself from its database's associated std::set. +void Transaction::EraseFromSet() { + db->transs.erase(this); +} + +// Builds a JavaScript array that has an object for each sqlite3_stmt handle +// that has bind parameters. Each object maps the handle's parameter names +// to their respective parameter index. void Transaction::BuildBindMap() { v8::Local cons = v8::Local::Cast(db->handle()->GetHiddenValue(NEW_INTERNAL_STRING_FAST("NullFactory"))); v8::Local array = Nan::New(); @@ -16,4 +39,4 @@ void Transaction::BuildBindMap() { } } handle()->SetHiddenValue(NEW_INTERNAL_STRING_FAST("bindMap"), array); -} +} \ No newline at end of file diff --git a/src/util/data.h b/src/util/data.h index 0597ecd75..d0ed76359 100644 --- a/src/util/data.h +++ b/src/util/data.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_DATA_H -#define NODE_SQLITE3_PLUS_DATA_H +#ifndef BETTER_SQLITE3_DATA_H +#define BETTER_SQLITE3_DATA_H #include #include diff --git a/src/util/list.h b/src/util/list.h index 23a059e44..fe9c01f7b 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -1,6 +1,8 @@ -#ifndef NODE_SQLITE3_PLUS_LIST_H -#define NODE_SQLITE3_PLUS_LIST_H +#ifndef BETTER_SQLITE3_LIST_H +#define BETTER_SQLITE3_LIST_H +// This class is effectively a queue. +// Flushing happens in a first-in-first-out order. template class List { private: diff --git a/src/util/macros.h b/src/util/macros.h index b7720db84..bb19a6140 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_MACROS_H -#define NODE_SQLITE3_PLUS_MACROS_H +#ifndef BETTER_SQLITE3_MACROS_H +#define BETTER_SQLITE3_MACROS_H #include #include diff --git a/src/util/strlcpy.h b/src/util/strlcpy.h index 889dcaa1d..39f4c055c 100644 --- a/src/util/strlcpy.h +++ b/src/util/strlcpy.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_STRLCPY_H -#define NODE_SQLITE3_PLUS_STRLCPY_H +#ifndef BETTER_SQLITE3_STRLCPY_H +#define BETTER_SQLITE3_STRLCPY_H /* * Copyright (c) 1998 Todd C. Miller diff --git a/src/util/transaction-handles.h b/src/util/transaction-handles.h index d950ef76b..d934fde55 100644 --- a/src/util/transaction-handles.h +++ b/src/util/transaction-handles.h @@ -1,8 +1,11 @@ -#ifndef NODE_SQLITE3_PLUS_TRANSACTION_HANDLES_H -#define NODE_SQLITE3_PLUS_TRANSACTION_HANDLES_H +#ifndef BETTER_SQLITE3_TRANSACTION_HANDLES_H +#define BETTER_SQLITE3_TRANSACTION_HANDLES_H #include +// A simple construct for holding three sqlite3_stmt pointers. +// After construction, if statusOut is SQLITE_OK, the three pointers +// can be used to start, commit, and rollback transactions. class TransactionHandles { public: TransactionHandles(sqlite3* db_handle, int* statusOut) diff --git a/src/workers/database-workers/close.h b/src/workers/database-workers/close.h index 3ce40c00e..bd4cd8bdb 100644 --- a/src/workers/database-workers/close.h +++ b/src/workers/database-workers/close.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_CLOSE_H -#define NODE_SQLITE3_PLUS_WORKER_CLOSE_H +#ifndef BETTER_SQLITE3_WORKER_CLOSE_H +#define BETTER_SQLITE3_WORKER_CLOSE_H #include class Database; diff --git a/src/workers/database-workers/open.h b/src/workers/database-workers/open.h index 6ed91db5e..6fa9749b0 100644 --- a/src/workers/database-workers/open.h +++ b/src/workers/database-workers/open.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_OPEN_H -#define NODE_SQLITE3_PLUS_WORKER_OPEN_H +#ifndef BETTER_SQLITE3_WORKER_OPEN_H +#define BETTER_SQLITE3_WORKER_OPEN_H #include class Database; diff --git a/src/workers/query-worker.h b/src/workers/query-worker.h index d7815d568..a2b982993 100644 --- a/src/workers/query-worker.h +++ b/src/workers/query-worker.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_QUERY_WORKER_H -#define NODE_SQLITE3_PLUS_WORKER_QUERY_WORKER_H +#ifndef BETTER_SQLITE3_WORKER_QUERY_H +#define BETTER_SQLITE3_WORKER_QUERY_H #include #include diff --git a/src/workers/statement-workers/all.h b/src/workers/statement-workers/all.h index 7b6cd9eac..45fda5610 100644 --- a/src/workers/statement-workers/all.h +++ b/src/workers/statement-workers/all.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_ALL_H -#define NODE_SQLITE3_PLUS_WORKER_ALL_H +#ifndef BETTER_SQLITE3_WORKER_ALL_H +#define BETTER_SQLITE3_WORKER_ALL_H #include #include diff --git a/src/workers/statement-workers/each.h b/src/workers/statement-workers/each.h index 9eb7cbb39..de59fa967 100644 --- a/src/workers/statement-workers/each.h +++ b/src/workers/statement-workers/each.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_EACH_H -#define NODE_SQLITE3_PLUS_WORKER_EACH_H +#ifndef BETTER_SQLITE3_WORKER_EACH_H +#define BETTER_SQLITE3_WORKER_EACH_H #include #include diff --git a/src/workers/statement-workers/get.h b/src/workers/statement-workers/get.h index a3296b722..f2913cc0c 100644 --- a/src/workers/statement-workers/get.h +++ b/src/workers/statement-workers/get.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_GET_H -#define NODE_SQLITE3_PLUS_WORKER_GET_H +#ifndef BETTER_SQLITE3_WORKER_GET_H +#define BETTER_SQLITE3_WORKER_GET_H #include #include diff --git a/src/workers/statement-workers/run.h b/src/workers/statement-workers/run.h index 3473ba878..e4dbf7377 100644 --- a/src/workers/statement-workers/run.h +++ b/src/workers/statement-workers/run.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_RUN_H -#define NODE_SQLITE3_PLUS_WORKER_RUN_H +#ifndef BETTER_SQLITE3_WORKER_RUN_H +#define BETTER_SQLITE3_WORKER_RUN_H #include #include diff --git a/src/workers/transaction-worker.h b/src/workers/transaction-worker.h index 4294a135c..d7b7c9c96 100644 --- a/src/workers/transaction-worker.h +++ b/src/workers/transaction-worker.h @@ -1,5 +1,5 @@ -#ifndef NODE_SQLITE3_PLUS_WORKER_TRANSACTION_WORKER_H -#define NODE_SQLITE3_PLUS_WORKER_TRANSACTION_WORKER_H +#ifndef BETTER_SQLITE3_WORKER_TRANSACTION_H +#define BETTER_SQLITE3_WORKER_TRANSACTION_H #include #include diff --git a/test/affected.test.js b/test/affected.test.js deleted file mode 100644 index f0bf192e6..000000000 --- a/test/affected.test.js +++ /dev/null @@ -1,32 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('query properties', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:'); - db.run("CREATE TABLE foo (id INT, txt TEXT)", done); - }); - - it('should return the correct lastID', function(done) { - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)"); - var j = 1; - for (var i = 0; i < 1000; i++) { - stmt.run(i, "demo", function(err) { - if (err) throw err; - // Relies on SQLite's row numbering to be gapless and starting - // from 1. - assert.equal(j++, this.lastID); - }); - } - db.wait(done); - }); - - it('should return the correct changes count', function(done) { - db.run("UPDATE foo SET id = id + 1 WHERE id % 2 = 0", function(err) { - if (err) throw err; - assert.equal(500, this.changes); - done(); - }); - }); -}); diff --git a/test/blob.test.js b/test/blob.test.js deleted file mode 100644 index 5c2b0d857..000000000 --- a/test/blob.test.js +++ /dev/null @@ -1,54 +0,0 @@ -var sqlite3 = require('..'), - fs = require('fs'), - assert = require('assert'), - Buffer = require('buffer').Buffer; - -// lots of elmo -var elmo = fs.readFileSync(__dirname + '/support/elmo.png'); - -describe('blob', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:'); - db.run("CREATE TABLE elmos (id INT, image BLOB)", done); - }); - - var total = 10; - var inserted = 0; - var retrieved = 0; - - - it('should insert blobs', function(done) { - for (var i = 0; i < total; i++) { - db.run('INSERT INTO elmos (id, image) VALUES (?, ?)', i, elmo, function(err) { - if (err) throw err; - inserted++; - }); - } - db.wait(function() { - assert.equal(inserted, total); - done(); - }); - }); - - it('should retrieve the blobs', function(done) { - db.all('SELECT id, image FROM elmos ORDER BY id', function(err, rows) { - if (err) throw err; - for (var i = 0; i < rows.length; i++) { - assert.ok(Buffer.isBuffer(rows[i].image)); - assert.ok(elmo.length, rows[i].image); - - for (var j = 0; j < elmo.length; j++) { - if (elmo[j] !== rows[i].image[j]) { - assert.ok(false, "Wrong byte"); - } - } - - retrieved++; - } - - assert.equal(retrieved, total); - done(); - }); - }); -}); diff --git a/test/cache.test.js b/test/cache.test.js deleted file mode 100644 index 9866dbf97..000000000 --- a/test/cache.test.js +++ /dev/null @@ -1,42 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var helper = require('./support/helper'); - -describe('cache', function() { - before(function() { - helper.ensureExists('test/tmp'); - }); - - it('should cache Database objects while opening', function(done) { - var filename = 'test/tmp/test_cache.db'; - helper.deleteFile(filename); - var opened1 = false, opened2 = false; - var db1 = new sqlite3.cached.Database(filename, function(err) { - if (err) throw err; - opened1 = true; - if (opened1 && opened2) done(); - }); - var db2 = new sqlite3.cached.Database(filename, function(err) { - if (err) throw err; - opened2 = true; - if (opened1 && opened2) done(); - }); - assert.equal(db1, db2); - }); - - it('should cache Database objects after they are open', function(done) { - var filename = 'test/tmp/test_cache2.db'; - helper.deleteFile(filename); - var db1, db2; - db1 = new sqlite3.cached.Database(filename, function(err) { - if (err) throw err; - process.nextTick(function() { - db2 = new sqlite3.cached.Database(filename, function(err) { - done(); - - }); - assert.equal(db1, db2); - }); - }); - }); -}); diff --git a/test/constants.test.js b/test/constants.test.js deleted file mode 100644 index 126d10141..000000000 --- a/test/constants.test.js +++ /dev/null @@ -1,40 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('constants', function() { - it('should have the right OPEN_* flags', function() { - assert.ok(sqlite3.OPEN_READONLY === 1); - assert.ok(sqlite3.OPEN_READWRITE === 2); - assert.ok(sqlite3.OPEN_CREATE === 4); - }); - - it('should have the right error flags', function() { - assert.ok(sqlite3.OK === 0); - assert.ok(sqlite3.ERROR === 1); - assert.ok(sqlite3.INTERNAL === 2); - assert.ok(sqlite3.PERM === 3); - assert.ok(sqlite3.ABORT === 4); - assert.ok(sqlite3.BUSY === 5); - assert.ok(sqlite3.LOCKED === 6); - assert.ok(sqlite3.NOMEM === 7); - assert.ok(sqlite3.READONLY === 8); - assert.ok(sqlite3.INTERRUPT === 9); - assert.ok(sqlite3.IOERR === 10); - assert.ok(sqlite3.CORRUPT === 11); - assert.ok(sqlite3.NOTFOUND === 12); - assert.ok(sqlite3.FULL === 13); - assert.ok(sqlite3.CANTOPEN === 14); - assert.ok(sqlite3.PROTOCOL === 15); - assert.ok(sqlite3.EMPTY === 16); - assert.ok(sqlite3.SCHEMA === 17); - assert.ok(sqlite3.TOOBIG === 18); - assert.ok(sqlite3.CONSTRAINT === 19); - assert.ok(sqlite3.MISMATCH === 20); - assert.ok(sqlite3.MISUSE === 21); - assert.ok(sqlite3.NOLFS === 22); - assert.ok(sqlite3.AUTH === 23); - assert.ok(sqlite3.FORMAT === 24); - assert.ok(sqlite3.RANGE === 25); - assert.ok(sqlite3.NOTADB === 26); - }); -}); diff --git a/test/database_fail.test.js b/test/database_fail.test.js deleted file mode 100644 index 35589ece5..000000000 --- a/test/database_fail.test.js +++ /dev/null @@ -1,153 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('error handling', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('throw when calling Database() without new', function() { - assert.throws(function() { - sqlite3.Database(':memory:'); - }, (/Use the new operator to create new Database objects/)); - - assert.throws(function() { - sqlite3.Statement(); - }, (/Use the new operator to create new Statement objects/)); - }); - - it('should error when calling Database#get on a missing table', function(done) { - db.get('SELECT id, txt FROM foo', function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#all prepare fail', function(done) { - db.all('SELECT id, txt FROM foo', function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#run prepare fail', function(done) { - db.run('SELECT id, txt FROM foo', function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#each prepare fail', function(done) { - db.each('SELECT id, txt FROM foo', function(err, row) { - assert.ok(false, "this should not be called"); - }, function(err, num) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#each prepare fail without completion handler', function(done) { - db.each('SELECT id, txt FROM foo', function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#get prepare fail with param binding', function(done) { - db.get('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#all prepare fail with param binding', function(done) { - db.all('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#run prepare fail with param binding', function(done) { - db.run('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#each prepare fail with param binding', function(done) { - db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) { - assert.ok(false, "this should not be called"); - }, function(err, num) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); - - it('Database#each prepare fail with param binding without completion handler', function(done) { - db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) { - if (err) { - assert.equal(err.message, 'SQLITE_ERROR: no such table: foo'); - assert.equal(err.errno, sqlite3.ERROR); - assert.equal(err.code, 'SQLITE_ERROR'); - done(); - } else { - done(new Error('Completed query without error, but expected error')); - } - }); - }); -}); diff --git a/test/each.test.js b/test/each.test.js deleted file mode 100644 index 02729c64e..000000000 --- a/test/each.test.js +++ /dev/null @@ -1,38 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('each', function() { - var db; - before(function(done) { - db = new sqlite3.Database('test/support/big.db', sqlite3.OPEN_READONLY, done); - }); - - it('retrieve 100,000 rows with Statement#each', function(done) { - var total = 100000; - var retrieved = 0; - - db.each('SELECT id, txt FROM foo LIMIT 0, ?', total, function(err, row) { - if (err) throw err; - retrieved++; - }); - - db.wait(function() { - assert.equal(retrieved, total, "Only retrieved " + retrieved + " out of " + total + " rows."); - done(); - }); - }); - - it('Statement#each with complete callback', function(done) { - var total = 10000; - var retrieved = 0; - - db.each('SELECT id, txt FROM foo LIMIT 0, ?', total, function(err, row) { - if (err) throw err; - retrieved++; - }, function(err, num) { - assert.equal(retrieved, num); - assert.equal(retrieved, total, "Only retrieved " + retrieved + " out of " + total + " rows."); - done(); - }); - }); -}); diff --git a/test/exec.test.js b/test/exec.test.js deleted file mode 100644 index e3d55329a..000000000 --- a/test/exec.test.js +++ /dev/null @@ -1,39 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var fs = require('fs'); - -describe('exec', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('Database#exec', function(done) { - var sql = fs.readFileSync('test/support/script.sql', 'utf8'); - db.exec(sql, done); - }); - - it('retrieve database structure', function(done) { - db.all("SELECT type, name FROM sqlite_master ORDER BY type, name", function(err, rows) { - if (err) throw err; - assert.deepEqual(rows, [ - { type: 'index', name: 'grid_key_lookup' }, - { type: 'index', name: 'grid_utfgrid_lookup' }, - { type: 'index', name: 'images_id' }, - { type: 'index', name: 'keymap_lookup' }, - { type: 'index', name: 'map_index' }, - { type: 'index', name: 'name' }, - { type: 'table', name: 'grid_key' }, - { type: 'table', name: 'grid_utfgrid' }, - { type: 'table', name: 'images' }, - { type: 'table', name: 'keymap' }, - { type: 'table', name: 'map' }, - { type: 'table', name: 'metadata' }, - { type: 'view', name: 'grid_data' }, - { type: 'view', name: 'grids' }, - { type: 'view', name: 'tiles' } - ]); - done(); - }); - }); -}); diff --git a/test/extension.test.js b/test/extension.test.js deleted file mode 100644 index 36c350fa4..000000000 --- a/test/extension.test.js +++ /dev/null @@ -1,26 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var exists = require('fs').existsSync || require('path').existsSync; - -/* - -// disabled because this is not a generically safe test to run on all systems - -var spatialite_ext = '/usr/local/lib/libspatialite.dylib'; - -describe('loadExtension', function(done) { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - if (exists(spatialite_ext)) { - it('libspatialite', function(done) { - db.loadExtension(spatialite_ext, done); - }); - } else { - it('libspatialite'); - } -}); - -*/ \ No newline at end of file diff --git a/test/fts-content.test.js b/test/fts-content.test.js deleted file mode 100644 index c7095a9cd..000000000 --- a/test/fts-content.test.js +++ /dev/null @@ -1,13 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('fts', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('should create a new fts4 table', function(done) { - db.exec('CREATE VIRTUAL TABLE t1 USING fts4(content="", a, b, c);', done); - }); -}); diff --git a/test/issue-108.test.js b/test/issue-108.test.js deleted file mode 100644 index 2ea69a30c..000000000 --- a/test/issue-108.test.js +++ /dev/null @@ -1,28 +0,0 @@ -var sqlite3 = require('..'), - assert = require('assert'); - -describe('buffer', function() { - var db; - // before(function() { - // }); - - it('should insert blobs', function(done) { - db = new sqlite3.Database(':memory:'); - db.serialize(function () { - - db.run("CREATE TABLE lorem (info BLOB)"); - var stmt = db.prepare("INSERT INTO lorem VALUES (?)"); - - stmt.on('error', function (err) { - throw err; - }); - - var buff = new Buffer(2); - stmt.run('a'); - stmt.finalize(); - }); - - db.close(done); - - }); -}); diff --git a/test/json.test.js b/test/json.test.js deleted file mode 100644 index 6d7d32dac..000000000 --- a/test/json.test.js +++ /dev/null @@ -1,22 +0,0 @@ -var sqlite3 = require('..'); - -if( process.env.NODE_SQLITE3_JSON1 === 'no' ){ - describe('json', function() { - it( - 'skips JSON tests when --sqlite=/usr (or similar) is tested', - function(){} - ); - }); -} else { - describe('json', function() { - var db; - - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('should select JSON', function(done) { - db.run('SELECT json(?)', JSON.stringify({ok:true}), done); - }); - }); -} diff --git a/test/map.test.js b/test/map.test.js deleted file mode 100644 index db190a7c2..000000000 --- a/test/map.test.js +++ /dev/null @@ -1,63 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('map', function() { - it('test Database#map() with two columns', function(done) { - var count = 10; - var inserted = 0; - - var db = new sqlite3.Database(':memory:'); - db.serialize(function() { - db.run("CREATE TABLE foo (id INT, value TEXT)"); - - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)"); - for (var i = 5; i < count; i++) { - stmt.run(i, 'Value for ' + i, function(err) { - if (err) throw err; - inserted++; - }); - } - stmt.finalize(); - - db.map("SELECT * FROM foo", function(err, map) { - if (err) throw err; - assert.deepEqual(map, { 5: 'Value for 5', 6: 'Value for 6', 7: 'Value for 7', 8: 'Value for 8', 9: 'Value for 9' }); - assert.equal(inserted, 5); - done(); - }); - }); - }); - - it('test Database#map() with three columns', function(done) { - var db = new sqlite3.Database(':memory:'); - - var count = 10; - var inserted = 0; - - db.serialize(function() { - db.run("CREATE TABLE foo (id INT, value TEXT, other TEXT)"); - - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?, ?)"); - for (var i = 5; i < count; i++) { - stmt.run(i, 'Value for ' + i, null, function(err) { - if (err) throw err; - inserted++; - }); - } - stmt.finalize(); - - db.map("SELECT * FROM foo", function(err, map) { - if (err) throw err; - assert.deepEqual(map, { - 5: { id: 5, value: 'Value for 5', other: null }, - 6: { id: 6, value: 'Value for 6', other: null }, - 7: { id: 7, value: 'Value for 7', other: null }, - 8: { id: 8, value: 'Value for 8', other: null }, - 9: { id: 9, value: 'Value for 9', other: null } - }); - assert.equal(inserted, 5); - done(); - }); - }); - }); -}); diff --git a/test/named_columns.test.js b/test/named_columns.test.js deleted file mode 100644 index 9973bfcee..000000000 --- a/test/named_columns.test.js +++ /dev/null @@ -1,38 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('named columns', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (txt TEXT, num INT)", done); - }); - - it('should insert a value', function(done) { - db.run("INSERT INTO foo VALUES($text, $id)", { - $id: 1, - $text: "Lorem Ipsum" - }, done); - }); - - it('should retrieve the values', function(done) { - db.get("SELECT txt, num FROM foo ORDER BY num", function(err, row) { - if (err) throw err; - assert.equal(row.txt, "Lorem Ipsum"); - assert.equal(row.num, 1); - done(); - }); - }); - - it('should be able to retrieve rowid of last inserted value', function(done) { - db.get("SELECT last_insert_rowid() as last_id FROM foo", function(err, row) { - if (err) throw err; - assert.equal(row.last_id, 1); - done(); - }); - }); - -}); diff --git a/test/named_params.test.js b/test/named_params.test.js deleted file mode 100644 index c03f2dd75..000000000 --- a/test/named_params.test.js +++ /dev/null @@ -1,69 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('named parameters', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (txt TEXT, num INT)", done); - }); - - it('should insert a value with $ placeholders', function(done) { - db.run("INSERT INTO foo VALUES($text, $id)", { - $id: 1, - $text: "Lorem Ipsum" - }, done); - }); - - it('should insert a value with : placeholders', function(done) { - db.run("INSERT INTO foo VALUES(:text, :id)", { - ':id': 2, - ':text': "Dolor Sit Amet" - }, done); - }); - - it('should insert a value with @ placeholders', function(done) { - db.run("INSERT INTO foo VALUES(@txt, @id)", { - "@id": 3, - "@txt": "Consectetur Adipiscing Elit" - }, done); - }); - - it('should insert a value with @ placeholders using an array', function(done) { - db.run("INSERT INTO foo VALUES(@txt, @id)", [ 'Sed Do Eiusmod', 4 ], done); - }); - - it('should insert a value with indexed placeholders', function(done) { - db.run("INSERT INTO foo VALUES(?2, ?4)", - [ null, 'Tempor Incididunt', null, 5 ], done); - }); - - it('should insert a value with autoindexed placeholders', function(done) { - db.run("INSERT INTO foo VALUES(?, ?)", { - 2: 6, - 1: "Ut Labore Et Dolore" - }, done); - }); - - it('should retrieve all inserted values', function(done) { - db.all("SELECT txt, num FROM foo ORDER BY num", function(err, rows) { - if (err) throw err; - assert.equal(rows[0].txt, "Lorem Ipsum"); - assert.equal(rows[0].num, 1); - assert.equal(rows[1].txt, "Dolor Sit Amet"); - assert.equal(rows[1].num, 2); - assert.equal(rows[2].txt, "Consectetur Adipiscing Elit"); - assert.equal(rows[2].num, 3); - assert.equal(rows[3].txt, "Sed Do Eiusmod"); - assert.equal(rows[3].num, 4); - assert.equal(rows[4].txt, "Tempor Incididunt"); - assert.equal(rows[4].num, 5); - assert.equal(rows[5].txt, "Ut Labore Et Dolore"); - assert.equal(rows[5].num, 6); - done(); - }); - }); -}); diff --git a/test/null_error.test.js b/test/null_error.test.js deleted file mode 100644 index 8c34d9bf8..000000000 --- a/test/null_error.test.js +++ /dev/null @@ -1,41 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var helper = require('./support/helper'); - -describe('null error', function() { - var filename = 'test/tmp/test_sqlite_ok_error.db'; - var db; - - before(function(done) { - helper.ensureExists('test/tmp'); - helper.deleteFile(filename); - db = new sqlite3.Database(filename, done); - }); - - it('should create a table', function(done) { - db.run("CREATE TABLE febp_data (leacode TEXT, leaname TEXT, state TEXT, postcode TEXT, fips TEXT, titleistim TEXT, ideastim TEXT, ideapool TEXT, ideapoolname TEXT, localebasis TEXT, localetype2 TEXT, version TEXT, leacount_2006 TEXT, ppexpend_2005 TEXT, ppexpend_2006 TEXT, ppexpend_2007 TEXT, ppexpend_2008 TEXT, ppexpendrank_2006 TEXT, ppexpendrank_2007 TEXT, ppexpendrank_2008 TEXT, rankppexpend_2005 TEXT, opbud_2004 TEXT, opbud_2006 TEXT, opbud_2007 TEXT, opbud_2008 TEXT, titlei_2004 TEXT, titlei_2006 TEXT, titlei_2007 TEXT, titlei_2008 TEXT, titlei_2009 TEXT, titlei_2010 TEXT, idea_2004 TEXT, idea_2005 TEXT, idea_2006 TEXT, idea_2007 TEXT, idea_2008 TEXT, idea_2009 TEXT, ideaest_2010 TEXT, impact_2007 TEXT, impact_2008 TEXT, impact_2009 TEXT, impact_2010 TEXT, fedrev_2006 TEXT, fedrev_2007 TEXT, fedrev_2008 TEXT, schonut_2006 TEXT, schonut_2007 TEXT, schomeal_2006 TEXT, schomeal_2007 TEXT, schoco_2006 TEXT, schocom_2007 TEXT, medicaid_2006 TEXT, medicaid_2007 TEXT, medicaid_2008 TEXT, cenpov_2004 TEXT, cenpov_2007 TEXT, cenpov_2008 TEXT, rankcenpov_2004 TEXT, rankcenpov_2007 TEXT, rankcenpov_2008 TEXT, enroll_2006 TEXT, enroll_2007 TEXT, enroll_2008 TEXT, white_2006 TEXT, white_2007 TEXT, white_2008 TEXT, afam_2006 TEXT, afam_2007 TEXT, afam_2008 TEXT, amin_2006 TEXT, amin_2007 TEXT, amin_2008 TEXT, asian_2006 TEXT, asian_2007 TEXT, asian_2008 TEXT, hisp_2006 TEXT, hisp_2007 TEXT, hisp_2008 TEXT, frpl_2006 TEXT, frpl_2007 TEXT, frpl_2008 TEXT, ell_2006 TEXT, ell_2007 TEXT, ell_2008 TEXT, sped_2006 TEXT, sped_2007 TEXT, sped_2008 TEXT, state4read_2005 TEXT, state4read_2006 TEXT, state4read_2007 TEXT, state4read_2008 TEXT, state4read_2009 TEXT, state4math_2005 TEXT, state4math_2006 TEXT, state4math_2007 TEXT, state4math_2008 TEXT, state4math_2009 TEXT, minor_2007 TEXT, minor_2008 TEXT, state8math_2006 TEXT, state8math_2007 TEXT, state8math_2008 TEXT, state8math_2009 TEXT, state8read_2006 TEXT, state8read_2007 TEXT, state8read_2008 TEXT, state8read_2009 TEXT, statehsmath_2006 TEXT, statehsmath_2007 TEXT, statehsmath_2008 TEXT, statehsmath_2009 TEXT, statehsread_2006 TEXT, statehsread_2007 TEXT, statehsread_2008 TEXT, statehsread_2009 TEXT)", done); - }); - - it('should insert rows with lots of null values', function(done) { - var stmt = db.prepare('INSERT INTO febp_data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', function(err) { - if (err) throw err; - - for (var i = 0; i < 100; i++) { - stmt.run([ '100005', 'Albertville City School District', 'ALABAMA', 'AL', '1', '856031', '753000', 'NULL', 'NULL', '6-Small Town', 'Town', 21, '130', '6624', '7140', '8731', '8520', '102', '88', '100', '94', '23352000', '27280000', '30106000', '33028000', '768478', '845886', '782696', '1096819', '1279663', '1168521', '561522', '657649', '684366', '687531', '710543', '727276', '726647', 'N/A', 'N/A', 'N/A', 'N/A', '986', '977', '1006', '1080250', '1202325', '1009962', '1109310', '70287', '93015', '14693.56', '13634.58', 'N/A', '0.230', '0.301', '0.268882175', '73', '26', '29', '3718', '3747', '3790', '2663', '2615', '2575', '75', '82', '89', '3', '2', '6', '11', '9', '8', '955', '1028', '1102', '1991', '2061', '2146', '649', '729', '770', '443', '278', '267', '0.860', '0.86', '0.8474', '0.84', '0.8235', '0.810', '0.84', '0.7729', '0.75', '0.7843', '1121', '1205', '0.74', '0.6862', '0.72', '0.7317', '0.78', '0.7766', '0.79', '0.7387', '0.84', '0.9255', '0.86', '0.9302', '0.88', '0.9308', '0.84', '0.8605' ]); - } - - stmt.finalize(function(err) { - if (err) throw err; - done(); - }); - }); - }); - - it('should have created the database', function() { - assert.fileExists(filename); - }); - - after(function() { - helper.deleteFile(filename); - }); -}); diff --git a/test/nw/.gitignore b/test/nw/.gitignore deleted file mode 100644 index 107e60536..000000000 --- a/test/nw/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node-webkit.app -node-webkit-v0.8.4-osx-ia32.zip -node_modules \ No newline at end of file diff --git a/test/nw/Makefile b/test/nw/Makefile deleted file mode 100755 index 9c8223301..000000000 --- a/test/nw/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -NODE_WEBKIT_VERSION=0.8.4 - -all: app.nw - -node_modules/sqlite3: - npm install https://github.com/mapbox/node-sqlite3/tarball/master --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) - -rebuild: - cd node_modules/sqlite3 && ./node_modules/.bin/node-pre-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) - -node-webkit-v$(NODE_WEBKIT_VERSION)-osx-ia32.zip: - wget https://s3.amazonaws.com/node-webkit/v$(NODE_WEBKIT_VERSION)/node-webkit-v$(NODE_WEBKIT_VERSION)-osx-ia32.zip - -./node-webkit.app: node-webkit-v$(NODE_WEBKIT_VERSION)-osx-ia32.zip - unzip -o node-webkit-v$(NODE_WEBKIT_VERSION)-osx-ia32.zip - -app.nw: ./node-webkit.app Makefile package.json index.html node_modules/sqlite3 - zip app.nw index.html package.json node_modules - -test: ./node-webkit.app app.nw - ./node-webkit.app/Contents/MacOS/node-webkit app.nw - -package: ./node-webkit.app Makefile package.json index.html node_modules/sqlite3 - rm -rf node-sqlite-test.app - cp -r ./node-webkit.app node-sqlite-test.app - mkdir ./node-sqlite-test.app/Contents/Resources/app.nw/ - cp package.json ./node-sqlite-test.app/Contents/Resources/app.nw/ - cp index.html ./node-sqlite-test.app/Contents/Resources/app.nw/ - cp -r node_modules/ ./node-sqlite-test.app/Contents/Resources/app.nw/ - ./node-sqlite-test.app/Contents/MacOS/node-webkit - -clean: - rm -rf ./node_modules/sqlite3 - rm -f ./app.nw - rm -rf node-sqlite-test.app - rm -f credits.html - rm -f nwsnapshot - -.PHONY: test diff --git a/test/nw/index.html b/test/nw/index.html deleted file mode 100644 index 9a1bb906c..000000000 --- a/test/nw/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Hello World! - - -

Hello World!

- Using node-sqlite3: - . - - \ No newline at end of file diff --git a/test/nw/package.json b/test/nw/package.json deleted file mode 100644 index d1b4aeef2..000000000 --- a/test/nw/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "nw-demo", - "main": "index.html", - "window": { - "toolbar": false, - "width": 800, - "height": 600 - } -} \ No newline at end of file diff --git a/test/open_close.test.js b/test/open_close.test.js deleted file mode 100644 index 649e21789..000000000 --- a/test/open_close.test.js +++ /dev/null @@ -1,129 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var fs = require('fs'); -var helper = require('./support/helper'); - -describe('open/close', function() { - before(function() { - helper.ensureExists('test/tmp'); - }); - - describe('open and close non-existant database', function() { - before(function() { - helper.deleteFile('test/tmp/test_create.db'); - }); - - var db; - it('should open the database', function(done) { - db = new sqlite3.Database('test/tmp/test_create.db', done); - }); - - it('should close the database', function(done) { - db.close(done); - }); - - it('should have created the file', function() { - assert.fileExists('test/tmp/test_create.db'); - }); - - after(function() { - helper.deleteFile('test/tmp/test_create.db'); - }); - }); - - it('should not be unable to open an inaccessible database', function(done) { - // NOTE: test assumes that the user is not allowed to create new files - // in /usr/bin. - var db = new sqlite3.Database('/test/tmp/directory-does-not-exist/test.db', function(err) { - if (err && err.errno === sqlite3.CANTOPEN) { - done(); - } else if (err) { - done(err); - } else { - done('Opened database that should be inaccessible'); - } - }); - }); - - - describe('creating database without create flag', function() { - before(function() { - helper.deleteFile('test/tmp/test_readonly.db'); - }); - - it('should fail to open the database', function(done) { - new sqlite3.Database('tmp/test_readonly.db', sqlite3.OPEN_READONLY, function(err) { - if (err && err.errno === sqlite3.CANTOPEN) { - done(); - } else if (err) { - done(err); - } else { - done('Created database without create flag'); - } - }); - }); - - it('should not have created the file', function() { - assert.fileDoesNotExist('test/tmp/test_readonly.db'); - }); - - after(function() { - helper.deleteFile('test/tmp/test_readonly.db'); - }); - }); - - describe('open and close memory database queuing', function() { - var db; - it('should open the database', function(done) { - db = new sqlite3.Database(':memory:', done); - }); - - it('should close the database', function(done) { - db.close(done); - }); - - it('shouldn\'t close the database again', function(done) { - db.close(function(err) { - assert.ok(err, 'No error object received on second close'); - assert.ok(err.errno === sqlite3.MISUSE); - done(); - }); - }); - }); - - describe('closing with unfinalized statements', function(done) { - var completed = false; - var completedSecond = false; - var closed = false; - - var db; - before(function() { - db = new sqlite3.Database(':memory:', done); - }); - - it('should create a table', function(done) { - db.run("CREATE TABLE foo (id INT, num INT)", done); - }); - - var stmt; - it('should prepare/run a statement', function(done) { - stmt = db.prepare('INSERT INTO foo VALUES (?, ?)'); - stmt.run(1, 2, done); - }); - - it('should fail to close the database', function(done) { - db.close(function(err) { - assert.ok(err.message, - "SQLITE_BUSY: unable to close due to unfinalised statements"); - done(); - }); - }); - - it('should succeed to close the database after finalizing', function(done) { - stmt.run(3, 4, function() { - stmt.finalize(); - db.close(done); - }); - }); - }); -}); diff --git a/test/other_objects.test.js b/test/other_objects.test.js deleted file mode 100644 index 155951791..000000000 --- a/test/other_objects.test.js +++ /dev/null @@ -1,89 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('data types', function() { - var db; - before(function(done) { - db = new sqlite3.Database(':memory:'); - db.run("CREATE TABLE txt_table (txt TEXT)"); - db.run("CREATE TABLE int_table (int INTEGER)"); - db.run("CREATE TABLE flt_table (flt FLOAT)"); - db.wait(done); - }); - - beforeEach(function(done) { - db.exec('DELETE FROM txt_table; DELETE FROM int_table; DELETE FROM flt_table;', done); - }); - - it('should serialize Date()', function(done) { - var date = new Date(); - db.run("INSERT INTO int_table VALUES(?)", date, function (err) { - if (err) throw err; - db.get("SELECT int FROM int_table", function(err, row) { - if (err) throw err; - assert.equal(row.int, +date); - done(); - }); - }); - }); - - it('should serialize RegExp()', function(done) { - var regexp = /^f\noo/; - db.run("INSERT INTO txt_table VALUES(?)", regexp, function (err) { - if (err) throw err; - db.get("SELECT txt FROM txt_table", function(err, row) { - if (err) throw err; - assert.equal(row.txt, String(regexp)); - done(); - }); - }); - }); - - [ - 4294967296.249, - Math.PI, - 3924729304762836.5, - new Date().valueOf(), - 912667.394828365, - 2.3948728634826374e+83, - 9.293476892934982e+300, - Infinity, - -9.293476892934982e+300, - -2.3948728634826374e+83, - -Infinity - ].forEach(function(flt) { - it('should serialize float ' + flt, function(done) { - db.run("INSERT INTO flt_table VALUES(?)", flt, function (err) { - if (err) throw err; - db.get("SELECT flt FROM flt_table", function(err, row) { - if (err) throw err; - assert.equal(row.flt, flt); - done(); - }); - }); - }); - }); - - [ - 4294967299, - 3924729304762836, - new Date().valueOf(), - 2.3948728634826374e+83, - 9.293476892934982e+300, - Infinity, - -9.293476892934982e+300, - -2.3948728634826374e+83, - -Infinity - ].forEach(function(integer) { - it('should serialize integer ' + integer, function(done) { - db.run("INSERT INTO int_table VALUES(?)", integer, function (err) { - if (err) throw err; - db.get("SELECT int AS integer FROM int_table", function(err, row) { - if (err) throw err; - assert.equal(row.integer, integer); - done(); - }); - }); - }); - }); -}); diff --git a/test/parallel_insert.test.js b/test/parallel_insert.test.js deleted file mode 100644 index fc3829bc0..000000000 --- a/test/parallel_insert.test.js +++ /dev/null @@ -1,44 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); -var helper = require('./support/helper'); - -describe('parallel', function() { - var db; - before(function(done) { - helper.deleteFile('test/tmp/test_parallel_inserts.db'); - helper.ensureExists('test/tmp'); - db = new sqlite3.Database('test/tmp/test_parallel_inserts.db', done); - }); - - var columns = []; - for (var i = 0; i < 128; i++) { - columns.push('id' + i); - } - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (" + columns + ")", done); - }); - - it('should insert in parallel', function(done) { - for (var i = 0; i < 1000; i++) { - for (var values = [], j = 0; j < columns.length; j++) { - values.push(i * j); - } - db.run("INSERT INTO foo VALUES (" + values + ")"); - } - - db.wait(done); - }); - - it('should close the database', function(done) { - db.close(done); - }); - - it('should verify that the database exists', function() { - assert.fileExists('test/tmp/test_parallel_inserts.db'); - }); - - after(function() { - helper.deleteFile('test/tmp/test_parallel_inserts.db'); - }); -}); diff --git a/test/prepare.test.js b/test/prepare.test.js deleted file mode 100644 index c32db72a4..000000000 --- a/test/prepare.test.js +++ /dev/null @@ -1,427 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('prepare', function() { - describe('invalid SQL', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var stmt; - it('should fail preparing a statement with invalid SQL', function(done) { - stmt = db.prepare('CRATE TALE foo text bar)', function(err, statement) { - if (err && err.errno == sqlite3.ERROR && - err.message === 'SQLITE_ERROR: near "CRATE": syntax error') { - done(); - } - else throw err; - }); - }); - - after(function(done) { db.close(done); }); - }); - - describe('simple prepared statement', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - it('should prepare, run and finalize the statement', function(done) { - db.prepare("CREATE TABLE foo (text bar)") - .run() - .finalize(done); - }); - - after(function(done) { db.close(done); }); - }); - - describe('inserting and retrieving rows', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var inserted = 0; - var retrieved = 0; - - // We insert and retrieve that many rows. - var count = 1000; - - it('should create the table', function(done) { - db.prepare("CREATE TABLE foo (txt text, num int, flt float, blb blob)").run().finalize(done); - }); - - it('should insert ' + count + ' rows', function(done) { - for (var i = 0; i < count; i++) { - db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)").run( - 'String ' + i, - i, - i * Math.PI, - // null (SQLite sets this implicitly) - function(err) { - if (err) throw err; - inserted++; - } - ).finalize(function(err) { - if (err) throw err; - if (inserted == count) done(); - }); - } - }); - - it('should prepare a statement and run it ' + (count + 5) + ' times', function(done) { - var stmt = db.prepare("SELECT txt, num, flt, blb FROM foo ORDER BY num", function(err) { - if (err) throw err; - assert.equal(stmt.sql, 'SELECT txt, num, flt, blb FROM foo ORDER BY num'); - }); - - for (var i = 0; i < count + 5; i++) (function(i) { - stmt.get(function(err, row) { - if (err) throw err; - - if (retrieved >= 1000) { - assert.equal(row, undefined); - } else { - assert.equal(row.txt, 'String ' + i); - assert.equal(row.num, i); - assert.equal(row.flt, i * Math.PI); - assert.equal(row.blb, null); - } - - retrieved++; - }); - })(i); - - stmt.finalize(done); - }); - - it('should have retrieved ' + (count + 5) + ' rows', function() { - assert.equal(count + 5, retrieved, "Didn't retrieve all rows"); - }); - - - after(function(done) { db.close(done); }); - }); - - describe('inserting with accidental undefined', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var inserted = 0; - var retrieved = 0; - - it('should create the table', function(done) { - db.prepare("CREATE TABLE foo (num int)").run().finalize(done); - }); - - it('should insert two rows', function(done) { - db.prepare('INSERT INTO foo VALUES(4)').run(function(err) { - if (err) throw err; - inserted++; - }).run(undefined, function (err) { - // The second time we pass undefined as a parameter. This is - // a mistake, but it should either throw an error or be ignored, - // not silently fail to run the statement. - if (err) throw err; - inserted++; - }).finalize(function(err) { - if (err) throw err; - if (inserted == 2) done(); - }); - }); - - it('should retrieve the data', function(done) { - var stmt = db.prepare("SELECT num FROM foo", function(err) { - if (err) throw err; - }); - - for (var i = 0; i < 2; i++) (function(i) { - stmt.get(function(err, row) { - if (err) throw err; - assert(row); - assert.equal(row.num, 4); - retrieved++; - }); - })(i); - - stmt.finalize(done); - }); - - it('should have retrieved two rows', function() { - assert.equal(2, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('retrieving reset() function', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - var retrieved = 0; - - it('should retrieve the same row over and over again', function(done) { - var stmt = db.prepare("SELECT txt, num, flt, blb FROM foo ORDER BY num"); - for (var i = 0; i < 10; i++) { - stmt.reset(); - stmt.get(function(err, row) { - if (err) throw err; - assert.equal(row.txt, 'String 0'); - assert.equal(row.num, 0); - assert.equal(row.flt, 0.0); - assert.equal(row.blb, null); - retrieved++; - }); - } - stmt.finalize(done); - }); - - it('should have retrieved 10 rows', function() { - assert.equal(10, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('multiple get() parameter binding', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - var retrieved = 0; - - it('should retrieve particular rows', function(done) { - var stmt = db.prepare("SELECT txt, num, flt, blb FROM foo WHERE num = ?"); - - for (var i = 0; i < 10; i++) (function(i) { - stmt.get(i * 10 + 1, function(err, row) { - if (err) throw err; - var val = i * 10 + 1; - assert.equal(row.txt, 'String ' + val); - assert.equal(row.num, val); - assert.equal(row.flt, val * Math.PI); - assert.equal(row.blb, null); - retrieved++; - }); - })(i); - - stmt.finalize(done); - }); - - it('should have retrieved 10 rows', function() { - assert.equal(10, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('prepare() parameter binding', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - var retrieved = 0; - - it('should retrieve particular rows', function(done) { - db.prepare("SELECT txt, num, flt, blb FROM foo WHERE num = ? AND txt = ?", 10, 'String 10') - .get(function(err, row) { - if (err) throw err; - assert.equal(row.txt, 'String 10'); - assert.equal(row.num, 10); - assert.equal(row.flt, 10 * Math.PI); - assert.equal(row.blb, null); - retrieved++; - }) - .finalize(done); - }); - - it('should have retrieved 1 row', function() { - assert.equal(1, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('all()', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - var retrieved = 0; - var count = 1000; - - it('should retrieve particular rows', function(done) { - db.prepare("SELECT txt, num, flt, blb FROM foo WHERE num < ? ORDER BY num", count) - .all(function(err, rows) { - if (err) throw err; - for (var i = 0; i < rows.length; i++) { - assert.equal(rows[i].txt, 'String ' + i); - assert.equal(rows[i].num, i); - assert.equal(rows[i].flt, i * Math.PI); - assert.equal(rows[i].blb, null); - retrieved++; - } - }) - .finalize(done); - }); - - it('should have retrieved all rows', function() { - assert.equal(count, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('all()', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - it('should retrieve particular rows', function(done) { - db.prepare("SELECT txt, num, flt, blb FROM foo WHERE num > 5000") - .all(function(err, rows) { - if (err) throw err; - assert.ok(rows.length === 0); - }) - .finalize(done); - }); - - after(function(done) { db.close(done); }); - }); - - describe('high concurrency', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - function randomString() { - var str = ''; - for (var i = Math.random() * 300; i > 0; i--) { - str += String.fromCharCode(Math.floor(Math.random() * 256)); - } - return str; - } - - // Generate random data. - var data = []; - var length = Math.floor(Math.random() * 1000) + 200; - for (var i = 0; i < length; i++) { - data.push([ randomString(), i, i * Math.random(), null ]); - } - - var inserted = 0; - var retrieved = 0; - - it('should create the table', function(done) { - db.prepare("CREATE TABLE foo (txt text, num int, flt float, blb blob)").run().finalize(done); - }); - - it('should insert all values', function(done) { - for (var i = 0; i < data.length; i++) { - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)"); - stmt.run(data[i][0], data[i][1], data[i][2], data[i][3], function(err) { - if (err) throw err; - inserted++; - }).finalize(function(err) { - if (err) throw err; - if (inserted == data.length) done(); - }); - } - }); - - it('should retrieve all values', function(done) { - db.prepare("SELECT txt, num, flt, blb FROM foo") - .all(function(err, rows) { - if (err) throw err; - - for (var i = 0; i < rows.length; i++) { - assert.ok(data[rows[i].num] !== true); - - assert.equal(rows[i].txt, data[rows[i].num][0]); - assert.equal(rows[i].num, data[rows[i].num][1]); - assert.equal(rows[i].flt, data[rows[i].num][2]); - assert.equal(rows[i].blb, data[rows[i].num][3]); - - // Mark the data row as already retrieved. - data[rows[i].num] = true; - retrieved++; - - } - - assert.equal(retrieved, data.length); - assert.equal(retrieved, inserted); - }) - .finalize(done); - }); - - after(function(done) { db.close(done); }); - }); - - - describe('test Database#get()', function() { - var db; - before(function(done) { db = new sqlite3.Database('test/support/prepare.db', sqlite3.OPEN_READONLY, done); }); - - var retrieved = 0; - - it('should get a row', function(done) { - db.get("SELECT txt, num, flt, blb FROM foo WHERE num = ? AND txt = ?", 10, 'String 10', function(err, row) { - if (err) throw err; - assert.equal(row.txt, 'String 10'); - assert.equal(row.num, 10); - assert.equal(row.flt, 10 * Math.PI); - assert.equal(row.blb, null); - retrieved++; - done(); - }); - }); - - it('should have retrieved all rows', function() { - assert.equal(1, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); - }); - - describe('Database#run() and Database#all()', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var inserted = 0; - var retrieved = 0; - - // We insert and retrieve that many rows. - var count = 1000; - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (txt text, num int, flt float, blb blob)", done); - }); - - it('should insert ' + count + ' rows', function(done) { - for (var i = 0; i < count; i++) { - db.run("INSERT INTO foo VALUES(?, ?, ?, ?)", - 'String ' + i, - i, - i * Math.PI, - // null (SQLite sets this implicitly) - function(err) { - if (err) throw err; - inserted++; - if (inserted == count) done(); - } - ); - } - }); - - it('should retrieve all rows', function(done) { - db.all("SELECT txt, num, flt, blb FROM foo ORDER BY num", function(err, rows) { - if (err) throw err; - for (var i = 0; i < rows.length; i++) { - assert.equal(rows[i].txt, 'String ' + i); - assert.equal(rows[i].num, i); - assert.equal(rows[i].flt, i * Math.PI); - assert.equal(rows[i].blb, null); - retrieved++; - } - - assert.equal(retrieved, count); - assert.equal(retrieved, inserted); - - done(); - }); - }); - - after(function(done) { db.close(done); }); - }); -}); diff --git a/test/profile.test.js b/test/profile.test.js deleted file mode 100644 index 6545f09c9..000000000 --- a/test/profile.test.js +++ /dev/null @@ -1,57 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('profiling', function() { - var create = false; - var select = false; - - var db; - before(function(done) { - db = new sqlite3.Database(':memory:', done); - - db.on('profile', function(sql, nsecs) { - assert.ok(typeof nsecs === "number"); - if (sql.match(/^SELECT/)) { - assert.ok(!select); - assert.equal(sql, "SELECT * FROM foo"); - console.log('profile select'); - select = true; - } - else if (sql.match(/^CREATE/)) { - assert.ok(!create); - assert.equal(sql, "CREATE TABLE foo (id int)"); - create = true; - } - else { - assert.ok(false); - } - }); - }); - - it('should profile a create table', function(done) { - assert.ok(!create); - db.run("CREATE TABLE foo (id int)", function(err) { - if (err) throw err; - setImmediate(function() { - assert.ok(create); - done(); - }); - }); - }); - - - it('should profile a select', function(done) { - assert.ok(!select); - db.run("SELECT * FROM foo", function(err) { - if (err) throw err; - setImmediate(function() { - assert.ok(select); - done(); - }, 0); - }); - }); - - after(function(done) { - db.close(done); - }); -}); diff --git a/test/rerun.test.js b/test/rerun.test.js deleted file mode 100644 index e98562ec6..000000000 --- a/test/rerun.test.js +++ /dev/null @@ -1,50 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('rerunning statements', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var count = 10; - var inserted = 0; - var retrieved = 0; - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (id int)", done); - }); - - it('should insert repeatedly, reusing the same statement', function(done) { - var stmt = db.prepare("INSERT INTO foo VALUES(?)"); - for (var i = 5; i < count; i++) { - stmt.run(i, function(err) { - if (err) throw err; - inserted++; - }); - } - stmt.finalize(done); - }); - - it('should retrieve repeatedly, resuing the same statement', function(done) { - var collected = []; - var stmt = db.prepare("SELECT id FROM foo WHERE id = ?"); - for (var i = 0; i < count; i++) { - stmt.get(i, function(err, row) { - if (err) throw err; - if (row) collected.push(row); - }); - } - stmt.finalize(function(err) { - if (err) throw err; - retrieved += collected.length; - assert.deepEqual(collected, [ { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }, { id: 9 } ]); - done(); - }); - }); - - it('should have inserted and retrieved the right amount', function() { - assert.equal(inserted, 5); - assert.equal(retrieved, 5); - }); - - after(function(done) { db.close(done); }); -}); diff --git a/test/scheduling.test.js b/test/scheduling.test.js deleted file mode 100644 index e00a8cf51..000000000 --- a/test/scheduling.test.js +++ /dev/null @@ -1,44 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('scheduling', function() { - it('scheduling after the database was closed', function(done) { - var db = new sqlite3.Database(':memory:'); - db.on('error', function(err) { - assert.ok(err.message && err.message.indexOf("SQLITE_MISUSE: Database handle is closed") > -1); - done(); - }); - - db.close(); - db.run("CREATE TABLE foo (id int)"); - }); - - - it('scheduling a query with callback after the database was closed', function(done) { - var db = new sqlite3.Database(':memory:'); - db.on('error', function(err) { - assert.ok(false, 'Event was accidentally triggered'); - }); - - db.close(); - db.run("CREATE TABLE foo (id int)", function(err) { - assert.ok(err.message && err.message.indexOf("SQLITE_MISUSE: Database handle is closed") > -1); - done(); - }); - }); - - it('running a query after the database was closed', function(done) { - var db = new sqlite3.Database(':memory:'); - - var stmt = db.prepare("SELECT * FROM sqlite_master", function(err) { - if (err) throw err; - db.close(function(err) { - assert.ok(err); - assert.ok(err.message && err.message.indexOf("SQLITE_BUSY: unable to close due to") > -1); - - // Running a statement now should not fail. - stmt.run(done); - }); - }); - }); -}); diff --git a/test/serialization.test.js b/test/serialization.test.js deleted file mode 100644 index ccc586734..000000000 --- a/test/serialization.test.js +++ /dev/null @@ -1,104 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - - -describe('serialize() and parallelize()', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var inserted1 = 0; - var inserted2 = 0; - var retrieved = 0; - - var count = 1000; - - it('should toggle', function(done) { - db.serialize(); - db.run("CREATE TABLE foo (txt text, num int, flt float, blb blob)"); - db.parallelize(done); - }); - - it('should insert rows', function() { - var stmt1 = db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)"); - var stmt2 = db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)"); - for (var i = 0; i < count; i++) { - // Interleaved inserts with two statements. - stmt1.run('String ' + i, i, i * Math.PI, function(err) { - if (err) throw err; - inserted1++; - }); - i++; - stmt2.run('String ' + i, i, i * Math.PI, function(err) { - if (err) throw err; - inserted2++; - }); - } - stmt1.finalize(); - stmt2.finalize(); - }); - - it('should have inserted all the rows after synchronizing with serialize()', function(done) { - db.serialize(); - db.all("SELECT txt, num, flt, blb FROM foo ORDER BY num", function(err, rows) { - if (err) throw err; - for (var i = 0; i < rows.length; i++) { - assert.equal(rows[i].txt, 'String ' + i); - assert.equal(rows[i].num, i); - assert.equal(rows[i].flt, i * Math.PI); - assert.equal(rows[i].blb, null); - retrieved++; - } - - assert.equal(count, inserted1 + inserted2, "Didn't insert all rows"); - assert.equal(count, retrieved, "Didn't retrieve all rows"); - done(); - }); - }); - - after(function(done) { db.close(done); }); -}); - -describe('serialize(fn)', function() { - var db; - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - var inserted = 0; - var retrieved = 0; - - var count = 1000; - - it('should call the callback', function(done) { - db.serialize(function() { - db.run("CREATE TABLE foo (txt text, num int, flt float, blb blob)"); - - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?, ?, ?)"); - for (var i = 0; i < count; i++) { - stmt.run('String ' + i, i, i * Math.PI, function(err) { - if (err) throw err; - inserted++; - }); - } - stmt.finalize(); - - db.all("SELECT txt, num, flt, blb FROM foo ORDER BY num", function(err, rows) { - if (err) throw err; - for (var i = 0; i < rows.length; i++) { - assert.equal(rows[i].txt, 'String ' + i); - assert.equal(rows[i].num, i); - assert.equal(rows[i].flt, i * Math.PI); - assert.equal(rows[i].blb, null); - retrieved++; - } - done(); - }); - }); - }); - - - it('should have inserted and retrieved all rows', function() { - assert.equal(count, inserted, "Didn't insert all rows"); - assert.equal(count, retrieved, "Didn't retrieve all rows"); - }); - - after(function(done) { db.close(done); }); -}); diff --git a/test/support/createdb.js b/test/support/createdb.js deleted file mode 100755 index bd34dbb10..000000000 --- a/test/support/createdb.js +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env node - -var existsSync = require('fs').existsSync || require('path').existsSync; -var path = require('path'); - -var sqlite3 = require('../../lib/sqlite3-plus'); - -var count = 1000000; -var db_path = path.join(__dirname,'big.db'); - -function randomString() { - var str = ''; - var chars = 'abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY0123456789 '; - for (var i = Math.random() * 100; i > 0; i--) { - str += chars[Math.floor(Math.random() * chars.length)]; - } - return str; -}; - - -if (existsSync(db_path)) { - console.log('okay: database already created (' + db_path + ')'); -} else { - console.log("Creating test database... This may take several minutes."); - var db = new sqlite3.Database(db_path); - db.serialize(function() { - db.run("CREATE TABLE foo (id INT, txt TEXT)"); - db.run("BEGIN TRANSACTION"); - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)"); - for (var i = 0; i < count; i++) { - stmt.run(i, randomString()); - } - stmt.finalize(); - db.run("COMMIT TRANSACTION"); - }); -} diff --git a/test/support/elmo.png b/test/support/elmo.png deleted file mode 100644 index 37000d470..000000000 Binary files a/test/support/elmo.png and /dev/null differ diff --git a/test/support/helper.js b/test/support/helper.js deleted file mode 100644 index 10dc20c70..000000000 --- a/test/support/helper.js +++ /dev/null @@ -1,37 +0,0 @@ -var assert = require('assert'); -var fs = require('fs'); -var pathExists = require('fs').existsSync || require('path').existsSync; - -exports.deleteFile = function(name) { - try { - fs.unlinkSync(name); - } catch(err) { - if (err.errno !== process.ENOENT && err.code !== 'ENOENT' && err.syscall !== 'unlink') { - throw err; - } - } -}; - -exports.ensureExists = function(name,cb) { - if (!pathExists(name)) { - fs.mkdirSync(name); - }; -} - -assert.fileDoesNotExist = function(name) { - try { - fs.statSync(name); - } catch(err) { - if (err.errno !== process.ENOENT && err.code !== 'ENOENT' && err.syscall !== 'unlink') { - throw err; - } - } -}; - -assert.fileExists = function(name) { - try { - fs.statSync(name); - } catch(err) { - throw err; - } -}; \ No newline at end of file diff --git a/test/support/prepare.db b/test/support/prepare.db deleted file mode 100644 index 660234cc0..000000000 Binary files a/test/support/prepare.db and /dev/null differ diff --git a/test/support/script.sql b/test/support/script.sql deleted file mode 100644 index 8a345ed67..000000000 --- a/test/support/script.sql +++ /dev/null @@ -1,70 +0,0 @@ -CREATE TABLE IF NOT EXISTS map ( - zoom_level INTEGER, - tile_column INTEGER, - tile_row INTEGER, - tile_id TEXT, - grid_id TEXT -); - -CREATE TABLE IF NOT EXISTS grid_key ( - grid_id TEXT, - key_name TEXT -); - -CREATE TABLE IF NOT EXISTS keymap ( - key_name TEXT, - key_json TEXT -); - -CREATE TABLE IF NOT EXISTS grid_utfgrid ( - grid_id TEXT, - grid_utfgrid TEXT -); - -CREATE TABLE IF NOT EXISTS images ( - tile_data blob, - tile_id text -); - -CREATE TABLE IF NOT EXISTS metadata ( - name text, - value text -); - - -CREATE UNIQUE INDEX IF NOT EXISTS map_index ON map (zoom_level, tile_column, tile_row); -CREATE UNIQUE INDEX IF NOT EXISTS grid_key_lookup ON grid_key (grid_id, key_name); -CREATE UNIQUE INDEX IF NOT EXISTS keymap_lookup ON keymap (key_name); -CREATE UNIQUE INDEX IF NOT EXISTS grid_utfgrid_lookup ON grid_utfgrid (grid_id); -CREATE UNIQUE INDEX IF NOT EXISTS images_id ON images (tile_id); -CREATE UNIQUE INDEX IF NOT EXISTS name ON metadata (name); - - -CREATE VIEW IF NOT EXISTS tiles AS - SELECT - map.zoom_level AS zoom_level, - map.tile_column AS tile_column, - map.tile_row AS tile_row, - images.tile_data AS tile_data - FROM map - JOIN images ON images.tile_id = map.tile_id; - -CREATE VIEW IF NOT EXISTS grids AS - SELECT - map.zoom_level AS zoom_level, - map.tile_column AS tile_column, - map.tile_row AS tile_row, - grid_utfgrid.grid_utfgrid AS grid - FROM map - JOIN grid_utfgrid ON grid_utfgrid.grid_id = map.grid_id; - -CREATE VIEW IF NOT EXISTS grid_data AS - SELECT - map.zoom_level AS zoom_level, - map.tile_column AS tile_column, - map.tile_row AS tile_row, - keymap.key_name AS key_name, - keymap.key_json AS key_json - FROM map - JOIN grid_key ON map.grid_id = grid_key.grid_id - JOIN keymap ON grid_key.key_name = keymap.key_name; diff --git a/test/trace.test.js b/test/trace.test.js deleted file mode 100644 index 3f790bd8f..000000000 --- a/test/trace.test.js +++ /dev/null @@ -1,67 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('tracing', function() { - it('Database tracing', function(done) { - var db = new sqlite3.Database(':memory:'); - var create = false; - var select = false; - - db.on('trace', function(sql) { - if (sql.match(/^SELECT/)) { - assert.ok(!select); - assert.equal(sql, "SELECT * FROM foo"); - select = true; - } - else if (sql.match(/^CREATE/)) { - assert.ok(!create); - assert.equal(sql, "CREATE TABLE foo (id int)"); - create = true; - } - else { - assert.ok(false); - } - }); - - db.serialize(function() { - db.run("CREATE TABLE foo (id int)"); - db.run("SELECT * FROM foo"); - }); - - db.close(function(err) { - if (err) throw err; - assert.ok(create); - assert.ok(select); - done(); - }); - }); - - - it('test disabling tracing #1', function(done) { - var db = new sqlite3.Database(':memory:'); - - db.on('trace', function(sql) {}); - db.removeAllListeners('trace'); - db._events['trace'] = function(sql) { - assert.ok(false); - }; - - db.run("CREATE TABLE foo (id int)"); - db.close(done); - }); - - - it('test disabling tracing #2', function(done) { - var db = new sqlite3.Database(':memory:'); - - var trace = function(sql) {}; - db.on('trace', trace); - db.removeListener('trace', trace); - db._events['trace'] = function(sql) { - assert.ok(false); - }; - - db.run("CREATE TABLE foo (id int)"); - db.close(done); - }); -}); diff --git a/test/unicode.test.js b/test/unicode.test.js deleted file mode 100644 index b76ca4289..000000000 --- a/test/unicode.test.js +++ /dev/null @@ -1,114 +0,0 @@ -var sqlite3 = require('..'); -var assert = require('assert'); - -describe('unicode', function() { - var first_values = [], - trailing_values = [], - chars = [], - subranges = new Array(2), - len = subranges.length, - db, - i; - - before(function(done) { db = new sqlite3.Database(':memory:', done); }); - - for (i = 0x20; i < 0x80; i++) { - first_values.push(i); - } - - for (i = 0xc2; i < 0xf0; i++) { - first_values.push(i); - } - - for (i = 0x80; i < 0xc0; i++) { - trailing_values.push(i); - } - - for (i = 0; i < len; i++) { - subranges[i] = []; - } - - for (i = 0xa0; i < 0xc0; i++) { - subranges[0].push(i); - } - - for (i = 0x80; i < 0xa0; i++) { - subranges[1].push(i); - } - - function random_choice(arr) { - return arr[Math.random() * arr.length | 0]; - } - - function random_utf8() { - var first = random_choice(first_values); - - if (first < 0x80) { - return String.fromCharCode(first); - } else if (first < 0xe0) { - return String.fromCharCode((first & 0x1f) << 0x6 | random_choice(trailing_values) & 0x3f); - } else if (first == 0xe0) { - return String.fromCharCode(((first & 0xf) << 0xc) | ((random_choice(subranges[0]) & 0x3f) << 6) | random_choice(trailing_values) & 0x3f); - } else if (first == 0xed) { - return String.fromCharCode(((first & 0xf) << 0xc) | ((random_choice(subranges[1]) & 0x3f) << 6) | random_choice(trailing_values) & 0x3f); - } else if (first < 0xf0) { - return String.fromCharCode(((first & 0xf) << 0xc) | ((random_choice(trailing_values) & 0x3f) << 6) | random_choice(trailing_values) & 0x3f); - } - } - - function randomString() { - var str = '', - i; - - for (i = Math.random() * 300; i > 0; i--) { - str += random_utf8(); - } - - return str; - } - - - // Generate random data. - var data = []; - var length = Math.floor(Math.random() * 1000) + 200; - for (var i = 0; i < length; i++) { - data.push(randomString()); - } - - var inserted = 0; - var retrieved = 0; - - it('should create the table', function(done) { - db.run("CREATE TABLE foo (id int, txt text)", done); - }); - - it('should insert all values', function(done) { - var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)"); - for (var i = 0; i < data.length; i++) { - stmt.run(i, data[i], function(err) { - if (err) throw err; - inserted++; - }); - } - stmt.finalize(done); - }); - - it('should retrieve all values', function(done) { - db.all("SELECT txt FROM foo ORDER BY id", function(err, rows) { - if (err) throw err; - - for (var i = 0; i < rows.length; i++) { - assert.equal(rows[i].txt, data[i]); - retrieved++; - } - done(); - }); - }); - - it('should have inserted and retrieved the correct amount', function() { - assert.equal(inserted, length); - assert.equal(retrieved, length); - }); - - after(function(done) { db.close(done); }); -});