diff --git a/.eslintrc.js b/.eslintrc.js index b711605b..423bf393 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1 +1,7 @@ -module.exports = { "extends": "airbnb-base" }; \ No newline at end of file +module.exports = { + "extends": "airbnb-base", + rules:{ + "linebreak-style": 0, + "no-console": 0 + } +}; \ No newline at end of file diff --git a/.gitignore b/.gitignore index 331ea9c7..0271909c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,14 @@ sandbox core oldtest .env -.vscode/ \ No newline at end of file +.vscode/ +.history + +build +build/* + +*.log +*.tmp +tmp.* +0.* +1.* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..e76658fe --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,66 @@ +project (odbc) +cmake_minimum_required(VERSION 3.10) + +message( STATUS "VOID pointer size = " ${CMAKE_SIZEOF_VOID_P} ) + +# if(CMAKE_SIZEOF_VOID_P EQUAL 8) +# # 64 bits +# elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) +# # 32 bits +# endif() + +# To set platform specific LIBS +if(LINUX) + set( LINK_LIBS ) +elseif(WIN32) + set( LINK_LIBS odbc32.lib odbccp32.lib ) +else() + set( LINK_LIBS ) +endif() + +# let us print the LINK_LIBS we set for debug purpus only +message( STATUS "LINK_LIBS = " ${LINK_LIBS} ) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(module_include_dir "${PROJECT_SOURCE_DIR}/src") +set(module_source_dir "${PROJECT_SOURCE_DIR}/src") + +# Include N-API wrappers +execute_process(COMMAND node -p "require('node-addon-api').include" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE NODE_ADDON_API_DIR + ) +string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) +string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) +include_directories(${CMAKE_JS_INC}) + +file(GLOB SOURCE_FILES + "${module_include_dir}/dynodbc.h" + "${module_include_dir}/odbc.h" + "${module_include_dir}/odbc_connection.h" + "${module_include_dir}/odbc_statement.h" + "${module_include_dir}/strptime.h" + "${module_source_dir}/dynodbc.cpp" + "${module_source_dir}/odbc.cpp" + "${module_source_dir}/odbc_connection.cpp" + "${module_source_dir}/odbc_statement.cpp" +) + +add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC} ) +target_include_directories(${PROJECT_NAME} + PUBLIC + ${PROJECT_SOURCE_DIR}/src/include + PRIVATE + ${NODE_ADDON_API_DIR} + ${CMAKE_JS_INC} +) + +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") +set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS=1 NAPI_DISABLE_CPP_EXCEPTIONS) +target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${LINK_LIBS} ) + +# Define NAPI_VERSION +add_definitions(-DNAPI_VERSION=3) diff --git a/README.md b/README.md index 8e8133c9..22efae8e 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,32 @@ When all these steps have been completed, install `node-odbc` into your Node.js ```bash npm install odbc ``` + +## Local build with CMake + +##### local build prerequisite +- [node.js](https://nodejs.org/en/) (v10 or higher) +- [CMake](https://cmake.org/) (v3.10 or higher) +- [cmake.js](https://github.com/cmake-js/cmake-js) (v6 or higher) + +```bash +# To start the build +cd node-odbc + +cmake-js build +# or +cmake-js build --debug + +# build using Visual Studio +cmake-js -G "Visual Studio 15 2017 Win64" +cmake-js -G "Visual Studio 16 2019" -A x64 +cmake-js -G "Visual Studio 16 2019" -A ARM +cmake-js -G "Visual Studio 16 2019" -A ARM64 + +# FYI: cmake-js can be installed by using +npm install -g cmake-js +``` + --- ## Important Changes in 2.0 diff --git a/src/odbc.cpp b/src/odbc.cpp index ce2c0d7d..4a2344b3 100644 --- a/src/odbc.cpp +++ b/src/odbc.cpp @@ -845,7 +845,7 @@ Napi::Array ODBC::ProcessDataForNapi(Napi::Env env, QueryData *data) { delete storedRow[j].data; } - rows.Set(i, row); + rows.Set( (uint32_t)i, row); } storedRows->clear(); diff --git a/src/odbc_connection.cpp b/src/odbc_connection.cpp index 70d4c5ed..5821ae8b 100644 --- a/src/odbc_connection.cpp +++ b/src/odbc_connection.cpp @@ -609,7 +609,7 @@ class CallProcedureAsyncWorker : public Napi::AsyncWorker { data->sqlReturnCode = ODBC::RetrieveResultSet(data); ASYNC_WORKER_CHECK_CODE_SET_ERROR_RETURN(data->sqlReturnCode, SQL_HANDLE_STMT, data->hSTMT, "QueryAsyncWorker::Execute", "ODBC::RetrieveResultSet"); - data->parameterCount = data->storedRows.size(); + data->parameterCount = (SQLSMALLINT)data->storedRows.size(); if (data->bindValueCount != (SQLSMALLINT)data->storedRows.size()) { SetError("[Node.js::odbc] The number of parameters in the procedure and the number of passes parameters is not equal."); return;