diff --git a/binding.gyp b/binding.gyp index 1f8567082..8cef97c67 100644 --- a/binding.gyp +++ b/binding.gyp @@ -23,6 +23,8 @@ "ExceptionHandling": 1, "AdditionalOptions": [ "/guard:cf", + "/w34244", + "/we4267", "/ZH:SHA_256" ] }, diff --git a/src/async.h b/src/async.h index b1a8f9dd6..35d838149 100644 --- a/src/async.h +++ b/src/async.h @@ -34,7 +34,7 @@ template 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 c291902c9..37b494b46 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), @@ -573,7 +573,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 6adb123f3..30a2d8c01 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 ); @@ -222,11 +222,10 @@ template Values::Field* } } -template T* Statement::Bind(const Napi::CallbackInfo& info, int start, int last) { +template T* Statement::Bind(const Napi::CallbackInfo& info, size_t start, size_t last) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - if (last < 0) last = info.Length(); Napi::Function callback; if (last > start && info[last - 1].IsFunction()) { callback = info[last - 1].As(); @@ -238,16 +237,18 @@ template T* Statement::Bind(const Napi::CallbackInfo& info, int start, if (start < last) { if (info[start].IsArray()) { Napi::Array array = info[start].As(); - int length = array.Length(); + uint32_t length = array.Length(); // Note: bind parameters start with 1. - for (int i = 0, pos = 1; i < length; i++, pos++) { + int pos = 1; + for (uint32_t i = 0; i < length; i++, pos++) { baton->parameters.push_back(BindParameter((array).Get(i), pos)); } } 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. - for (int i = start, pos = 1; i < last; i++, pos++) { + int pos = 1; + for (size_t i = start; i < last; i++, pos++) { baton->parameters.push_back(BindParameter(info[i], pos)); } } @@ -292,7 +293,7 @@ bool Statement::Bind(const Parameters & parameters) { Values::Field* field = *it; if (field != NULL) { - unsigned int pos; + int pos; if (field->index > 0) { pos = field->index; } @@ -302,7 +303,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 +311,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; @@ -338,7 +341,7 @@ Napi::Value Statement::Bind(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Statement* stmt = this; - Baton* baton = stmt->Bind(info); + Baton* baton = stmt->Bind(info, 0, info.Length()); if (baton == NULL) { Napi::TypeError::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -390,7 +393,7 @@ Napi::Value Statement::Get(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Statement* stmt = this; - Baton* baton = stmt->Bind(info); + Baton* baton = stmt->Bind(info, 0, info.Length()); if (baton == NULL) { Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -462,7 +465,7 @@ Napi::Value Statement::Run(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Statement* stmt = this; - Baton* baton = stmt->Bind(info); + Baton* baton = stmt->Bind(info, 0, info.Length()); if (baton == NULL) { Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -517,7 +520,7 @@ void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) { // Fire callbacks. Napi::Function cb = baton->callback.Value(); if (!cb.IsUndefined() && cb.IsFunction()) { - (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() }; @@ -532,7 +535,7 @@ Napi::Value Statement::All(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Statement* stmt = this; - Baton* baton = stmt->Bind(info); + Baton* baton = stmt->Bind(info, 0, info.Length()); if (baton == NULL) { Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); return env.Null(); @@ -618,7 +621,7 @@ Napi::Value Statement::Each(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Statement* stmt = this; - int last = info.Length(); + auto last = info.Length(); Napi::Function completed; if (last >= 2 && info[last - 1].IsFunction() && info[last - 2].IsFunction()) { @@ -813,7 +816,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..94e93d2ac 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; }; @@ -221,7 +221,7 @@ class Statement : public Napi::ObjectWrap { void Finalize_(); template inline Values::Field* BindParameter(const Napi::Value source, T pos); - template T* Bind(const Napi::CallbackInfo& info, int start = 0, int end = -1); + template T* Bind(const Napi::CallbackInfo& info, size_t start, size_t end); bool Bind(const Parameters ¶meters); static void GetRow(Row* row, sqlite3_stmt* stmt);