Skip to content

Commit

Permalink
upgraded sqlite to v3.26.0 and enabled SQLITE_DBCONFIG_DEFENSIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Dec 15, 2018
1 parent 3e73334 commit 8f3122e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion deps/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# 3. node-gyp links the two resulting binaries to generate better_sqlite3.node.
# ===

VERSION="3250200"
VERSION="3260000"
YEAR="2018"

# TODO: SQLITE_ENABLE_GEOPOLY (determine if the emitted warnings are safe or not)
Expand Down
Binary file modified deps/sqlite3.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Your amalgamation directory should contain `sqlite3.c` and `sqlite3.h`. Any desi

# Bundled configuration

By default, this distribution currently uses SQLite3 **version 3.25.2** with the following [compilation options](https://www.sqlite.org/compile.html):
By default, this distribution currently uses SQLite3 **version 3.26.0** with the following [compilation options](https://www.sqlite.org/compile.html):

```
SQLITE_THREADSAFE=0
Expand Down
70 changes: 36 additions & 34 deletions src/better_sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ void Database::JS_new (v8::FunctionCallbackInfo <v8 :: Value> const & info)
sqlite3_limit(db_handle, SQLITE_LIMIT_SQL_LENGTH, MAX_STRING_SIZE);
int status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, NULL);
assert(status == SQLITE_OK); ((void)status);
status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_DEFENSIVE, 1);
assert(status == SQLITE_OK); ((void)status);

v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ;
Database* db = new Database(db_handle);
Expand All @@ -417,17 +419,17 @@ void Database::JS_new (v8::FunctionCallbackInfo <v8 :: Value> const & info)

info.GetReturnValue().Set(info.This());
}
#line 126 "./src/objects/database.lzz"
#line 128 "./src/objects/database.lzz"
void Database::JS_prepare (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 126 "./src/objects/database.lzz"
#line 128 "./src/objects/database.lzz"
{
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a string" ) ; v8 :: Local < v8 :: String > source = v8 :: Local < v8 :: String > :: Cast ( info [ 0 ] ) ;
v8::MaybeLocal<v8::Object> maybe_statement = Statement::New( info . GetIsolate ( ) , info.This(), source);
if (!maybe_statement.IsEmpty()) info.GetReturnValue().Set(maybe_statement.ToLocalChecked());
}
#line 132 "./src/objects/database.lzz"
#line 134 "./src/objects/database.lzz"
void Database::JS_exec (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 132 "./src/objects/database.lzz"
#line 134 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a string" ) ; v8 :: Local < v8 :: String > source = v8 :: Local < v8 :: String > :: Cast ( info [ 0 ] ) ;
Expand All @@ -440,15 +442,15 @@ void Database::JS_exec (v8::FunctionCallbackInfo <v8 :: Value> const & info)
if (status == SQLITE_OK) info.GetReturnValue().Set(info.This());
else db->ThrowDatabaseError();
}
#line 145 "./src/objects/database.lzz"
#line 147 "./src/objects/database.lzz"
void Database::JS_pragma (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 145 "./src/objects/database.lzz"
#line 147 "./src/objects/database.lzz"
{
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsBoolean ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a boolean" ) ; node :: ObjectWrap :: Unwrap < Database > ( info . This ( ) ) -> pragma_mode = v8 :: Local < v8 :: Boolean > :: Cast ( info [ 0 ] ) -> Value ( ) ;
}
#line 149 "./src/objects/database.lzz"
#line 151 "./src/objects/database.lzz"
void Database::JS_checkpoint (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 149 "./src/objects/database.lzz"
#line 151 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( ! db -> open ) return ThrowTypeError ( "The database connection is not open" ) ;
Expand Down Expand Up @@ -490,9 +492,9 @@ void Database::JS_checkpoint (v8::FunctionCallbackInfo <v8 :: Value> const & inf
}
if (!threw_error) info.GetReturnValue().Set(info.This());
}
#line 191 "./src/objects/database.lzz"
#line 193 "./src/objects/database.lzz"
void Database::JS_function (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 191 "./src/objects/database.lzz"
#line 193 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" ) ; v8 :: Local < v8 :: Function > fn = v8 :: Local < v8 :: Function > :: Cast ( info [ 0 ] ) ;
Expand All @@ -513,9 +515,9 @@ void Database::JS_function (v8::FunctionCallbackInfo <v8 :: Value> const & info)
}
info.GetReturnValue().Set(info.This());
}
#line 212 "./src/objects/database.lzz"
#line 214 "./src/objects/database.lzz"
void Database::JS_aggregate (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 212 "./src/objects/database.lzz"
#line 214 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( info . Length ( ) <= ( 0 ) ) return ThrowTypeError ( "Expected a " "first" " argument" ) ; v8 :: Local < v8 :: Value > start = info [ 0 ] ;
Expand All @@ -541,9 +543,9 @@ void Database::JS_aggregate (v8::FunctionCallbackInfo <v8 :: Value> const & info
}
info.GetReturnValue().Set(info.This());
}
#line 238 "./src/objects/database.lzz"
#line 240 "./src/objects/database.lzz"
void Database::JS_loadExtension (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 238 "./src/objects/database.lzz"
#line 240 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a string" ) ; v8 :: Local < v8 :: String > filenameString = v8 :: Local < v8 :: String > :: Cast ( info [ 0 ] ) ;
Expand All @@ -556,9 +558,9 @@ void Database::JS_loadExtension (v8::FunctionCallbackInfo <v8 :: Value> const &
else ThrowSqliteError(db->db_handle, error, status);
sqlite3_free(error);
}
#line 251 "./src/objects/database.lzz"
#line 253 "./src/objects/database.lzz"
void Database::JS_close (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 251 "./src/objects/database.lzz"
#line 253 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if (db->open) {
Expand All @@ -568,32 +570,32 @@ void Database::JS_close (v8::FunctionCallbackInfo <v8 :: Value> const & info)
}
info.GetReturnValue().Set(info.This());
}
#line 261 "./src/objects/database.lzz"
#line 263 "./src/objects/database.lzz"
void Database::JS_defaultSafeIntegers (v8::FunctionCallbackInfo <v8 :: Value> const & info)
#line 261 "./src/objects/database.lzz"
#line 263 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
if ( db -> busy ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
if (info.Length() == 0) db->safe_ints = true;
else { if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsBoolean ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a boolean" ) ; db -> safe_ints = v8 :: Local < v8 :: Boolean > :: Cast ( info [ 0 ] ) -> Value ( ) ; }
info.GetReturnValue().Set(info.This());
}
#line 269 "./src/objects/database.lzz"
#line 271 "./src/objects/database.lzz"
void Database::JS_open (v8::Local <v8 :: String> _, v8::PropertyCallbackInfo <v8 :: Value> const & info)
#line 269 "./src/objects/database.lzz"
#line 271 "./src/objects/database.lzz"
{
info.GetReturnValue().Set( node :: ObjectWrap :: Unwrap <Database>(info.This())->open);
}
#line 273 "./src/objects/database.lzz"
#line 275 "./src/objects/database.lzz"
void Database::JS_inTransaction (v8::Local <v8 :: String> _, v8::PropertyCallbackInfo <v8 :: Value> const & info)
#line 273 "./src/objects/database.lzz"
#line 275 "./src/objects/database.lzz"
{
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
info.GetReturnValue().Set(db->open && !static_cast<bool>(sqlite3_get_autocommit(db->db_handle)));
}
#line 278 "./src/objects/database.lzz"
#line 280 "./src/objects/database.lzz"
void Database::CloseHandles ()
#line 278 "./src/objects/database.lzz"
#line 280 "./src/objects/database.lzz"
{
if (open) {
open = false;
Expand All @@ -603,16 +605,16 @@ void Database::CloseHandles ()
assert(status == SQLITE_OK); ((void)status);
}
}
#line 288 "./src/objects/database.lzz"
#line 290 "./src/objects/database.lzz"
void Database::ThrowSqliteError (sqlite3 * db_handle)
#line 288 "./src/objects/database.lzz"
#line 290 "./src/objects/database.lzz"
{
assert(db_handle != NULL);
ThrowSqliteError(db_handle, sqlite3_errmsg(db_handle), sqlite3_extended_errcode(db_handle));
}
#line 292 "./src/objects/database.lzz"
#line 294 "./src/objects/database.lzz"
void Database::ThrowSqliteError (sqlite3 * db_handle, char const * message, int code)
#line 292 "./src/objects/database.lzz"
#line 294 "./src/objects/database.lzz"
{
assert(db_handle != NULL);
assert(message != NULL);
Expand All @@ -621,20 +623,20 @@ void Database::ThrowSqliteError (sqlite3 * db_handle, char const * message, int
v8::Local<v8::Value> args[2] = { StringFromUtf8(isolate, message, -1), CS::Code(isolate, code) };
isolate->ThrowException(v8::Local<v8::Function>::New(isolate, SqliteError)->NewInstance( isolate -> GetCurrentContext ( ) , 2, args).ToLocalChecked());
}
#line 301 "./src/objects/database.lzz"
#line 303 "./src/objects/database.lzz"
void Database::AtExit (void * _)
#line 301 "./src/objects/database.lzz"
#line 303 "./src/objects/database.lzz"
{
for (Database* db : dbs) db->CloseHandles();
dbs.clear();
}
#line 306 "./src/objects/database.lzz"
#line 308 "./src/objects/database.lzz"
std::set <Database*, Database::CompareDatabase> Database::dbs;
#line 307 "./src/objects/database.lzz"
#line 309 "./src/objects/database.lzz"
v8::Persistent <v8::Function> Database::SqliteError;
#line 308 "./src/objects/database.lzz"
#line 310 "./src/objects/database.lzz"
int const Database::MAX_BUFFER_SIZE;
#line 309 "./src/objects/database.lzz"
#line 311 "./src/objects/database.lzz"
int const Database::MAX_STRING_SIZE;
#line 6 "./src/objects/statement.lzz"
v8::MaybeLocal <v8::Object> Statement::New (v8::Isolate * isolate, v8::Local <v8::Object> database, v8::Local <v8::String> source)
Expand Down
52 changes: 26 additions & 26 deletions src/better_sqlite3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,57 +252,57 @@ class Database : public node::ObjectWrap
static void Init (v8::Isolate * isolate, v8::Local <v8 :: Object> exports, v8::Local <v8 :: Object> module);
#line 86 "./src/objects/database.lzz"
static void JS_new (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 126 "./src/objects/database.lzz"
#line 128 "./src/objects/database.lzz"
static void JS_prepare (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 132 "./src/objects/database.lzz"
#line 134 "./src/objects/database.lzz"
static void JS_exec (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 145 "./src/objects/database.lzz"
#line 147 "./src/objects/database.lzz"
static void JS_pragma (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 149 "./src/objects/database.lzz"
#line 151 "./src/objects/database.lzz"
static void JS_checkpoint (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 191 "./src/objects/database.lzz"
#line 193 "./src/objects/database.lzz"
static void JS_function (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 212 "./src/objects/database.lzz"
#line 214 "./src/objects/database.lzz"
static void JS_aggregate (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 238 "./src/objects/database.lzz"
#line 240 "./src/objects/database.lzz"
static void JS_loadExtension (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 251 "./src/objects/database.lzz"
#line 253 "./src/objects/database.lzz"
static void JS_close (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 261 "./src/objects/database.lzz"
#line 263 "./src/objects/database.lzz"
static void JS_defaultSafeIntegers (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 269 "./src/objects/database.lzz"
#line 271 "./src/objects/database.lzz"
static void JS_open (v8::Local <v8 :: String> _, v8::PropertyCallbackInfo <v8 :: Value> const & info);
#line 273 "./src/objects/database.lzz"
#line 275 "./src/objects/database.lzz"
static void JS_inTransaction (v8::Local <v8 :: String> _, v8::PropertyCallbackInfo <v8 :: Value> const & info);
#line 278 "./src/objects/database.lzz"
#line 280 "./src/objects/database.lzz"
void CloseHandles ();
#line 288 "./src/objects/database.lzz"
#line 290 "./src/objects/database.lzz"
static void ThrowSqliteError (sqlite3 * db_handle);
#line 292 "./src/objects/database.lzz"
#line 294 "./src/objects/database.lzz"
static void ThrowSqliteError (sqlite3 * db_handle, char const * message, int code);
#line 301 "./src/objects/database.lzz"
#line 303 "./src/objects/database.lzz"
static void AtExit (void * _);
#line 306 "./src/objects/database.lzz"
#line 308 "./src/objects/database.lzz"
static std::set <Database*, Database::CompareDatabase> dbs;
#line 307 "./src/objects/database.lzz"
#line 309 "./src/objects/database.lzz"
static v8::Persistent <v8::Function> SqliteError;
#line 308 "./src/objects/database.lzz"
#line 310 "./src/objects/database.lzz"
static int const MAX_BUFFER_SIZE = node::Buffer::kMaxLength > INT_MAX ? INT_MAX : static_cast<int>(node::Buffer::kMaxLength);
#line 309 "./src/objects/database.lzz"
static int const MAX_STRING_SIZE = v8::String::kMaxLength > INT_MAX ? INT_MAX : static_cast<int>(v8::String::kMaxLength);
#line 311 "./src/objects/database.lzz"
static int const MAX_STRING_SIZE = v8::String::kMaxLength > INT_MAX ? INT_MAX : static_cast<int>(v8::String::kMaxLength);
#line 313 "./src/objects/database.lzz"
sqlite3 * const db_handle;
#line 312 "./src/objects/database.lzz"
#line 314 "./src/objects/database.lzz"
bool open;
#line 313 "./src/objects/database.lzz"
#line 315 "./src/objects/database.lzz"
bool busy;
#line 314 "./src/objects/database.lzz"
#line 316 "./src/objects/database.lzz"
bool pragma_mode;
#line 315 "./src/objects/database.lzz"
#line 317 "./src/objects/database.lzz"
bool safe_ints;
#line 316 "./src/objects/database.lzz"
#line 318 "./src/objects/database.lzz"
bool was_js_error;
#line 317 "./src/objects/database.lzz"
#line 319 "./src/objects/database.lzz"
std::set <Statement*, Database::CompareStatement> stmts;
};
#line 1 "./src/objects/statement.lzz"
Expand Down
2 changes: 2 additions & 0 deletions src/objects/database.lzz
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private:
sqlite3_limit(db_handle, SQLITE_LIMIT_SQL_LENGTH, MAX_STRING_SIZE);
int status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, NULL);
assert(status == SQLITE_OK); ((void)status);
status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_DEFENSIVE, 1);
assert(status == SQLITE_OK); ((void)status);

UseContext;
Database* db = new Database(db_handle);
Expand Down

0 comments on commit 8f3122e

Please sign in to comment.