diff --git a/binding.gyp b/binding.gyp index 20d418b3..18f17e7b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,7 +14,13 @@ "MACOSX_DEPLOYMENT_TARGET": "10.7", }, "msvs_settings": { - "VCCLCompilerTool": { "ExceptionHandling": 1 }, + "VCCLCompilerTool": { + "ExceptionHandling": 1, + "AdditionalOptions": [ + "/we4244", + "/we4267" + ] + }, }, "include_dirs": [ "(napi_writable | napi_configurable); + auto napi_default_method = static_cast(napi_writable | napi_configurable); auto t = DefineClass(env, "Database", { InstanceMethod("close", &Database::Close, napi_default_method), @@ -352,7 +352,7 @@ Napi::Value Database::Configure(const Napi::CallbackInfo& info) { REQUIRE_ARGUMENTS(2); Napi::Function handle; - if (info[0].StrictEquals( Napi::String::New(env, "trace"))) { + if (info[0].StrictEquals( Napi::String::New(env, "trace"))) { auto* baton = new Baton(db, handle); db->Schedule(RegisterTraceCallback, baton); } @@ -561,7 +561,7 @@ void Database::UpdateCallback(Database *db, UpdateInfo* i) { Napi::String::New(env, sqlite_authorizer_string(info->type)), Napi::String::New(env, info->database.c_str()), Napi::String::New(env, info->table.c_str()), - Napi::Number::New(env, info->rowid), + Napi::Number::New(env, static_cast(info->rowid)), }; EMIT_EVENT(db->Value(), 5, argv); } diff --git a/src/statement.cc b/src/statement.cc index 2d6daa41..0d3f3a75 100644 --- a/src/statement.cc +++ b/src/statement.cc @@ -90,7 +90,7 @@ template void Statement::Error(T* baton) { // { Database db, String sql, Array params, Function callback } Statement::Statement(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { auto env = info.Env(); - int length = info.Length(); + auto length = info.Length(); if (length <= 0 || !Database::HasInstance(info[0])) { Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); @@ -141,7 +141,7 @@ void Statement::Work_Prepare(napi_env e, void* data) { stmt->status = sqlite3_prepare_v2( baton->db->_handle, baton->sql.c_str(), - baton->sql.size(), + static_cast(baton->sql.size()), &stmt->_handle, NULL ); @@ -226,7 +226,7 @@ template T* Statement::Bind(const Napi::CallbackInfo& info, int start, auto env = info.Env(); Napi::HandleScope scope(env); - if (last < 0) last = info.Length(); + if (last < 0) last = static_cast(info.Length()); Napi::Function callback; if (last > start && info[last - 1].IsFunction()) { callback = info[last - 1].As(); @@ -244,7 +244,7 @@ template T* Statement::Bind(const Napi::CallbackInfo& info, int start, baton->parameters.emplace_back(BindParameter((array).Get(i), i + 1)); } } - else if (!info[start].IsObject() || OtherInstanceOf(info[start].As(), "RegExp") + else if (!info[start].IsObject() || OtherInstanceOf(info[start].As(), "RegExp") || OtherInstanceOf(info[start].As(), "Date") || info[start].IsBuffer()) { // Parameters directly in array. // Note: bind parameters start with 1. @@ -300,7 +300,7 @@ bool Statement::Bind(const Parameters & parameters) { switch (field->type) { case SQLITE_INTEGER: { - status = sqlite3_bind_int(_handle, pos, + status = sqlite3_bind_int64(_handle, pos, (static_cast(field.get()))->value); } break; case SQLITE_FLOAT: { @@ -308,12 +308,14 @@ bool Statement::Bind(const Parameters & parameters) { (static_cast(field.get()))->value); } break; case SQLITE_TEXT: { - status = sqlite3_bind_text(_handle, pos, + status = sqlite3_bind_text64(_handle, pos, (static_cast(field.get()))->value.c_str(), - (static_cast(field.get()))->value.size(), SQLITE_TRANSIENT); + (static_cast(field.get()))->value.size(), + SQLITE_TRANSIENT, + SQLITE_UTF8); } break; case SQLITE_BLOB: { - status = sqlite3_bind_blob(_handle, pos, + status = sqlite3_bind_blob64(_handle, pos, (static_cast(field.get()))->value, (static_cast(field.get()))->length, SQLITE_TRANSIENT); } break; @@ -514,7 +516,7 @@ void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) { // Fire callbacks. Napi::Function cb = baton->callback.Value(); if (IS_FUNCTION(cb)) { - (stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, baton->inserted_id)); + (stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, static_cast(baton->inserted_id))); (stmt->Value()).Set( Napi::String::New(env, "changes"), Napi::Number::New(env, baton->changes)); Napi::Value argv[] = { env.Null() }; @@ -614,14 +616,14 @@ Napi::Value Statement::Each(const Napi::CallbackInfo& info) { auto env = info.Env(); Statement* stmt = this; - int last = info.Length(); + size_t last = info.Length(); Napi::Function completed; if (last >= 2 && info[last - 1].IsFunction() && info[last - 2].IsFunction()) { completed = info[--last].As(); } - auto baton = stmt->Bind(info, 0, last); + auto baton = stmt->Bind(info, 0, static_cast(last)); if (baton == NULL) { Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -800,17 +802,17 @@ Napi::Value Statement::RowToJS(Napi::Env env, Row* row) { switch (field->type) { case SQLITE_INTEGER: { - value = Napi::Number::New(env, (static_cast(field.get()))->value); + value = Napi::Number::New(env, static_cast((static_cast(field.get()))->value)); } break; case SQLITE_FLOAT: { value = Napi::Number::New(env, (static_cast(field.get()))->value); } break; case SQLITE_TEXT: { - value = Napi::String::New(env, (static_cast(field.get()))->value.c_str(), + value = Napi::String::New(env, (static_cast(field.get()))->value.c_str(), (static_cast(field.get()))->value.size()); } break; case SQLITE_BLOB: { - value = Napi::Buffer::Copy(env, (static_cast(field.get()))->value, + value = Napi::Buffer::Copy(env, (static_cast(field.get()))->value, (static_cast(field.get()))->length); } break; case SQLITE_NULL: { diff --git a/src/statement.h b/src/statement.h index 397593e3..caf70f42 100644 --- a/src/statement.h +++ b/src/statement.h @@ -19,13 +19,13 @@ namespace node_sqlite3 { namespace Values { struct Field { - inline Field(unsigned short _index, unsigned short _type = SQLITE_NULL) : + inline Field(int _index, unsigned short _type = SQLITE_NULL) : type(_type), index(_index) {} inline Field(const char* _name, unsigned short _type = SQLITE_NULL) : type(_type), index(0), name(_name) {} unsigned short type; - unsigned short index; + int index; std::string name; virtual ~Field() = default; @@ -62,7 +62,7 @@ namespace Values { inline virtual ~Blob() override { delete[] value; } - int length; + size_t length; char* value; };