Skip to content

Commit 5f505a9

Browse files
committed
fix: enable and fix type-casting warnings
1 parent c1440bd commit 5f505a9

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

binding.gyp

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
"MACOSX_DEPLOYMENT_TARGET": "10.7",
1515
},
1616
"msvs_settings": {
17-
"VCCLCompilerTool": { "ExceptionHandling": 1 },
17+
"VCCLCompilerTool": {
18+
"ExceptionHandling": 1,
19+
"AdditionalOptions": [
20+
"/we4244",
21+
"/we4267"
22+
]
23+
},
1824
},
1925
"include_dirs": [
2026
"<!@(node -p \"require('node-addon-api').include\")"],

src/async.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <class Item, class Parent> class Async {
3434
NODE_SQLITE3_MUTEX_LOCK(&async->mutex)
3535
rows.swap(async->data);
3636
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
37-
for (unsigned int i = 0, size = rows.size(); i < size; i++) {
37+
for (size_t i = 0, size = rows.size(); i < size; i++) {
3838
async->callback(async->parent, rows[i]);
3939
}
4040
}

src/backup.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Backup::Backup(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Backup>(info)
127127
return;
128128
}
129129

130-
int length = info.Length();
130+
size_t length = info.Length();
131131

132132
if (length <= 0 || !Database::HasInstance(info[0])) {
133133
Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException();

src/database.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Napi::FunctionReference Database::constructor;
1414
Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
1515
Napi::HandleScope scope(env);
1616
// declare napi_default_method here as it is only available in Node v14.12.0+
17-
napi_property_attributes napi_default_method = static_cast<napi_property_attributes>(napi_writable | napi_configurable);
17+
napi_property_attributes napi_default_method = static_cast<napi_property_attributes>(napi_writable | napi_configurable);
1818

1919
Napi::Function t = DefineClass(env, "Database", {
2020
InstanceMethod("close", &Database::Close, napi_default_method),
@@ -565,7 +565,7 @@ void Database::UpdateCallback(Database *db, UpdateInfo* i) {
565565
Napi::String::New(env, sqlite_authorizer_string(info->type)),
566566
Napi::String::New(env, info->database.c_str()),
567567
Napi::String::New(env, info->table.c_str()),
568-
Napi::Number::New(env, info->rowid),
568+
Napi::Number::New(env, static_cast<double>(info->rowid)),
569569
};
570570
EMIT_EVENT(db->Value(), 5, argv);
571571
}

src/statement.cc

+13-11
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ template <class T> void Statement::Error(T* baton) {
9090
// { Database db, String sql, Array params, Function callback }
9191
Statement::Statement(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Statement>(info) {
9292
Napi::Env env = info.Env();
93-
int length = info.Length();
93+
size_t length = info.Length();
9494

9595
if (length <= 0 || !Database::HasInstance(info[0])) {
9696
Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException();
@@ -141,7 +141,7 @@ void Statement::Work_Prepare(napi_env e, void* data) {
141141
stmt->status = sqlite3_prepare_v2(
142142
baton->db->_handle,
143143
baton->sql.c_str(),
144-
baton->sql.size(),
144+
static_cast<int>(baton->sql.size()),
145145
&stmt->_handle,
146146
NULL
147147
);
@@ -226,7 +226,7 @@ template <class T> T* Statement::Bind(const Napi::CallbackInfo& info, int start,
226226
Napi::Env env = info.Env();
227227
Napi::HandleScope scope(env);
228228

229-
if (last < 0) last = info.Length();
229+
if (last < 0) last = static_cast<int>(info.Length());
230230
Napi::Function callback;
231231
if (last > start && info[last - 1].IsFunction()) {
232232
callback = info[last - 1].As<Napi::Function>();
@@ -302,20 +302,22 @@ bool Statement::Bind(const Parameters & parameters) {
302302

303303
switch (field->type) {
304304
case SQLITE_INTEGER: {
305-
status = sqlite3_bind_int(_handle, pos,
305+
status = sqlite3_bind_int64(_handle, pos,
306306
((Values::Integer*)field)->value);
307307
} break;
308308
case SQLITE_FLOAT: {
309309
status = sqlite3_bind_double(_handle, pos,
310310
((Values::Float*)field)->value);
311311
} break;
312312
case SQLITE_TEXT: {
313-
status = sqlite3_bind_text(_handle, pos,
313+
status = sqlite3_bind_text64(_handle, pos,
314314
((Values::Text*)field)->value.c_str(),
315-
((Values::Text*)field)->value.size(), SQLITE_TRANSIENT);
315+
((Values::Text*)field)->value.size(),
316+
SQLITE_TRANSIENT,
317+
SQLITE_UTF8);
316318
} break;
317319
case SQLITE_BLOB: {
318-
status = sqlite3_bind_blob(_handle, pos,
320+
status = sqlite3_bind_blob64(_handle, pos,
319321
((Values::Blob*)field)->value,
320322
((Values::Blob*)field)->length, SQLITE_TRANSIENT);
321323
} break;
@@ -517,7 +519,7 @@ void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) {
517519
// Fire callbacks.
518520
Napi::Function cb = baton->callback.Value();
519521
if (IS_FUNCTION(cb)) {
520-
(stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, baton->inserted_id));
522+
(stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, static_cast<double>(baton->inserted_id)));
521523
(stmt->Value()).Set( Napi::String::New(env, "changes"), Napi::Number::New(env, baton->changes));
522524

523525
Napi::Value argv[] = { env.Null() };
@@ -618,14 +620,14 @@ Napi::Value Statement::Each(const Napi::CallbackInfo& info) {
618620
Napi::Env env = info.Env();
619621
Statement* stmt = this;
620622

621-
int last = info.Length();
623+
size_t last = info.Length();
622624

623625
Napi::Function completed;
624626
if (last >= 2 && info[last - 1].IsFunction() && info[last - 2].IsFunction()) {
625627
completed = info[--last].As<Napi::Function>();
626628
}
627629

628-
EachBaton* baton = stmt->Bind<EachBaton>(info, 0, last);
630+
EachBaton* baton = stmt->Bind<EachBaton>(info, 0, static_cast<int>(last));
629631
if (baton == NULL) {
630632
Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException();
631633
return env.Null();
@@ -813,7 +815,7 @@ Napi::Value Statement::RowToJS(Napi::Env env, Row* row) {
813815

814816
switch (field->type) {
815817
case SQLITE_INTEGER: {
816-
value = Napi::Number::New(env, ((Values::Integer*)field)->value);
818+
value = Napi::Number::New(env, static_cast<double>(((Values::Integer*)field)->value));
817819
} break;
818820
case SQLITE_FLOAT: {
819821
value = Napi::Number::New(env, ((Values::Float*)field)->value);

src/statement.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ namespace node_sqlite3 {
2020

2121
namespace Values {
2222
struct Field {
23-
inline Field(unsigned short _index, unsigned short _type = SQLITE_NULL) :
23+
inline Field(int _index, unsigned short _type = SQLITE_NULL) :
2424
type(_type), index(_index) {}
2525
inline Field(const char* _name, unsigned short _type = SQLITE_NULL) :
2626
type(_type), index(0), name(_name) {}
2727

2828
unsigned short type;
29-
unsigned short index;
29+
int index;
3030
std::string name;
3131
};
3232

@@ -57,7 +57,7 @@ namespace Values {
5757
inline ~Blob() {
5858
free(value);
5959
}
60-
int length;
60+
size_t length;
6161
char* value;
6262
};
6363

0 commit comments

Comments
 (0)