diff --git a/binding.gyp b/binding.gyp index 20d418b3c..18f17e7b6 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": [ " class Async { NODE_SQLITE3_MUTEX_LOCK(&async->mutex) rows.swap(async->data); NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) - for (unsigned int i = 0, size = rows.size(); i < size; i++) { + for (size_t i = 0, size = rows.size(); i < size; i++) { async->callback(async->parent, rows[i]); } } diff --git a/src/backup.cc b/src/backup.cc index 9f3893b96..493a5d430 100644 --- a/src/backup.cc +++ b/src/backup.cc @@ -127,7 +127,7 @@ Backup::Backup(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) return; } - int length = info.Length(); + size_t length = info.Length(); if (length <= 0 || !Database::HasInstance(info[0])) { Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); diff --git a/src/database.cc b/src/database.cc index 15709ce3d..d0fc873ec 100644 --- a/src/database.cc +++ b/src/database.cc @@ -14,7 +14,7 @@ Napi::FunctionReference Database::constructor; Napi::Object Database::Init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); // declare napi_default_method here as it is only available in Node v14.12.0+ - napi_property_attributes napi_default_method = static_cast(napi_writable | napi_configurable); + napi_property_attributes napi_default_method = static_cast(napi_writable | napi_configurable); Napi::Function t = DefineClass(env, "Database", { InstanceMethod("close", &Database::Close, napi_default_method), @@ -565,7 +565,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 f1b835ba2..898fe57dc 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) { Napi::Env env = info.Env(); - int length = info.Length(); + size_t 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, Napi::Env 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(); @@ -302,7 +302,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, ((Values::Integer*)field)->value); } break; case SQLITE_FLOAT: { @@ -310,12 +310,14 @@ bool Statement::Bind(const Parameters & parameters) { ((Values::Float*)field)->value); } break; case SQLITE_TEXT: { - status = sqlite3_bind_text(_handle, pos, + status = sqlite3_bind_text64(_handle, pos, ((Values::Text*)field)->value.c_str(), - ((Values::Text*)field)->value.size(), SQLITE_TRANSIENT); + ((Values::Text*)field)->value.size(), + SQLITE_TRANSIENT, + SQLITE_UTF8); } break; case SQLITE_BLOB: { - status = sqlite3_bind_blob(_handle, pos, + status = sqlite3_bind_blob64(_handle, pos, ((Values::Blob*)field)->value, ((Values::Blob*)field)->length, SQLITE_TRANSIENT); } break; @@ -517,7 +519,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() }; @@ -618,14 +620,14 @@ Napi::Value Statement::Each(const Napi::CallbackInfo& info) { Napi::Env 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(); } - EachBaton* baton = stmt->Bind(info, 0, last); + EachBaton* baton = stmt->Bind(info, 0, static_cast(last)); if (baton == NULL) { Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -813,7 +815,7 @@ Napi::Value Statement::RowToJS(Napi::Env env, Row* row) { switch (field->type) { case SQLITE_INTEGER: { - value = Napi::Number::New(env, ((Values::Integer*)field)->value); + value = Napi::Number::New(env, static_cast(((Values::Integer*)field)->value)); } break; case SQLITE_FLOAT: { value = Napi::Number::New(env, ((Values::Float*)field)->value); diff --git a/src/statement.h b/src/statement.h index dec0015d1..6b413aef8 100644 --- a/src/statement.h +++ b/src/statement.h @@ -20,13 +20,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; }; @@ -57,7 +57,7 @@ namespace Values { inline ~Blob() { free(value); } - int length; + size_t length; char* value; };