diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7dab5e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +build \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..7b6a8e3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,18 @@ +{ + "name": "sqlanywhere", + "version": "1.0.24", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "help": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/help/-/help-3.0.2.tgz", + "integrity": "sha1-luGQ1KCkU7icLLSwWrOOOo+f2t0=" + }, + "nan": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" + } + } +} diff --git a/package.json b/package.json index 088d5d2..04ac017 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "SQL ANYWHERE", "name": "sqlanywhere", "description": "SQL Anywhere JavaScript Driver.", - "version": "1.0.24", + "version": "2.0.1", "repository": { "url": "https://github.com/sqlanywhere/node-sqlanywhere" }, @@ -15,6 +15,6 @@ }, "dependencies": { "help": "^3.0.2", - "nan": "2.11.1" + "nan": "^2.14.0" } } diff --git a/src/h/connection.h b/src/h/connection.h index e9aeb92..46106c0 100644 --- a/src/h/connection.h +++ b/src/h/connection.h @@ -138,22 +138,14 @@ class Connection : public ObjectWrap { public: /// @internal -#if v010 - static void Init(); -#else static void Init( Isolate * ); -#endif /// @internal static NODE_API_FUNC( NewInstance ); private: /// @internal -#if v010 - Connection( const Arguments &args ); -#else Connection( const FunctionCallbackInfo &args ); -#endif /// @internal ~Connection(); diff --git a/src/h/nodever_cover.h b/src/h/nodever_cover.h index e179bde..88c069b 100644 --- a/src/h/nodever_cover.h +++ b/src/h/nodever_cover.h @@ -3,19 +3,4 @@ // *************************************************************************** #include -#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION == 10 -#define v010 1 -#define v012 0 -#elif NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION == 12 -#define v010 0 -#define v012 1 -#else -#define v010 0 -#define v012 0 -#endif - -#if v010 -#define NODE_API_FUNC( name ) Handle name ( const Arguments &args ) -#else #define NODE_API_FUNC( name ) void name ( const FunctionCallbackInfo &args ) -#endif diff --git a/src/h/sqlany_utils.h b/src/h/sqlany_utils.h index 928b1cc..c24f511 100644 --- a/src/h/sqlany_utils.h +++ b/src/h/sqlany_utils.h @@ -132,16 +132,6 @@ void getErrorMsg( int code, std::string &str ); void throwError( a_sqlany_connection *conn ); void throwError( int code ); -#if v010 -void callBack( std::string * str, - Persistent callback, - Local Result, - bool callback_required = true ); -void callBack( std::string * str, - Local callback, - Local Result, - bool callback_required = true ); -#else void callBack( std::string * str, Persistent & callback, Local & Result, @@ -154,27 +144,19 @@ void callBack( std::string * str, Persistent & callback, Persistent & Result, bool callback_required = true ); -#endif bool getBindParameters( std::vector &execData - , Handle arg + , Local arg , std::vector ¶ms , unsigned &num_rows ); -#if v010 -bool getResultSet( Local &Result - , int &rows_affected - , std::vector &colNames - , ExecuteData *execData - , std::vector &col_types ); -#else + bool getResultSet( Persistent &Result , int &rows_affected , std::vector &colNames , ExecuteData *execData , std::vector &col_types ); -#endif bool fetchResultSet( a_sqlany_stmt *sqlany_stmt , int &rows_affected diff --git a/src/h/stmt.h b/src/h/stmt.h index a4106aa..756c5d0 100644 --- a/src/h/stmt.h +++ b/src/h/stmt.h @@ -16,20 +16,14 @@ class StmtObject : public node::ObjectWrap { public: /// @internal -#if v010 - static void Init(); -#else static void Init( Isolate * ); -#endif /// @internal static NODE_API_FUNC( NewInstance ); /// @internal -#if !v010 static void CreateNewInstance( const FunctionCallbackInfo &args, Persistent &obj ); -#endif /// @internal StmtObject(); diff --git a/src/sqlanywhere.cpp b/src/sqlanywhere.cpp index df1018a..730ceff 100644 --- a/src/sqlanywhere.cpp +++ b/src/sqlanywhere.cpp @@ -3,8 +3,9 @@ // *************************************************************************** #include "nodever_cover.h" #include "sqlany_utils.h" +#include "nan.h" -#if !v010 +#if NODE_MAJOR_VERSION >= 12 using namespace v8; @@ -26,7 +27,7 @@ struct executeBaton { std::string stmt; std::vector execData; std::vector params; - + std::vector colNames; int rows_affected; std::vector col_types; @@ -93,7 +94,7 @@ void executeWork( uv_work_t *req ) getErrorMsg( JS_ERR_NOT_CONNECTED, baton->error_msg ); return; } - + a_sqlany_stmt *sqlany_stmt = NULL; if( baton->stmt_obj == NULL ) { baton->stmt_obj = new StmtObject(); @@ -112,13 +113,13 @@ void executeWork( uv_work_t *req ) return; } baton->stmt_obj->sqlany_stmt = sqlany_stmt; - + } else if( sqlany_stmt == NULL ) { baton->err = true; getErrorMsg( JS_ERR_INVALID_OBJECT, baton->error_msg ); return; } - + if( !api.sqlany_reset( sqlany_stmt ) ) { baton->err = true; getErrorMsg( baton->obj->conn, baton->error_msg ); @@ -127,7 +128,7 @@ void executeWork( uv_work_t *req ) for( unsigned int i = 0; i < baton->params.size(); i++ ) { a_sqlany_bind_param param; - + if( !api.sqlany_describe_bind_param( sqlany_stmt, i, ¶m ) ) { baton->err = true; getErrorMsg( baton->obj->conn, baton->error_msg ); @@ -146,7 +147,7 @@ void executeWork( uv_work_t *req ) if( baton->num_rows > 1 ) { api.sqlany_set_batch_size( sqlany_stmt, baton->num_rows ); } - + sacapi_bool success_execute = api.sqlany_execute( sqlany_stmt ); baton->execData[0]->clear(); @@ -155,7 +156,7 @@ void executeWork( uv_work_t *req ) getErrorMsg( baton->obj->conn, baton->error_msg ); return; } - + if( !fetchResultSet( sqlany_stmt, baton->rows_affected, baton->colNames, baton->execData[0], baton->col_types ) ) { baton->err = true; @@ -188,9 +189,9 @@ NODE_API_FUNC( StmtObject::exec ) bool callback_required = false, bind_required = false; int cbfunc_arg = -1; Local undef = Local::New( isolate, Undefined( isolate ) ); - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsArray() ) { bind_required = true; @@ -208,7 +209,7 @@ NODE_API_FUNC( StmtObject::exec ) args.GetReturnValue().SetUndefined(); return; } - + if( obj == NULL || obj->connection == NULL || obj->connection->conn == NULL || obj->sqlany_stmt == NULL ) { std::string error_msg; @@ -217,7 +218,7 @@ NODE_API_FUNC( StmtObject::exec ) args.GetReturnValue().SetUndefined(); return; } - + executeBaton *baton = new executeBaton(); baton->obj = obj->connection; baton->stmt_obj = obj; @@ -251,32 +252,32 @@ NODE_API_FUNC( StmtObject::exec ) uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; status = uv_queue_work( uv_default_loop(), req, executeWork, (uv_after_work_cb)executeAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + Persistent ResultSet; - + executeWork( req ); bool success = fillResult( baton, ResultSet ); delete baton; delete req; - + if( !success ) { args.GetReturnValue().SetUndefined(); return; } - args.GetReturnValue().Set( ResultSet ); + args.GetReturnValue().Set( ResultSet.Get(isolate) ); ResultSet.Reset(); } @@ -346,9 +347,9 @@ NODE_API_FUNC( StmtObject::getMoreResults ) bool callback_required = false; int cbfunc_arg = -1; Local undef = Local::New( isolate, Undefined( isolate ) ); - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsFunction() ) { callback_required = true; cbfunc_arg = 0; @@ -358,7 +359,7 @@ NODE_API_FUNC( StmtObject::getMoreResults ) args.GetReturnValue().SetUndefined(); return; } - + if( obj == NULL || obj->connection == NULL || obj->connection->conn == NULL || obj->sqlany_stmt == NULL ) { std::string error_msg; @@ -379,32 +380,32 @@ NODE_API_FUNC( StmtObject::getMoreResults ) uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; status = uv_queue_work( uv_default_loop(), req, getMoreResultsWork, (uv_after_work_cb)getMoreResultsAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + Persistent ResultSet; - + getMoreResultsWork( req ); bool success = fillResult( baton, ResultSet ); delete baton; delete req; - + if( !success ) { args.GetReturnValue().SetUndefined(); return; } - args.GetReturnValue().Set( ResultSet ); + args.GetReturnValue().Set( ResultSet.Get(isolate)); ResultSet.Reset(); } @@ -423,16 +424,16 @@ NODE_API_FUNC( Connection::exec ) } else if( num_args == 2 && args[1]->IsArray() ) { bind_required = true; - + } else if( num_args == 2 && args[1]->IsFunction() ) { callback_required = true; cbfunc_arg = 1; - + } else if( num_args == 3 && args[1]->IsArray() && args[2]->IsFunction() ) { callback_required = true; bind_required = true; cbfunc_arg = 2; - + } else { throwError( JS_ERR_INVALID_ARGUMENTS ); args.GetReturnValue().SetUndefined(); @@ -445,7 +446,7 @@ NODE_API_FUNC( Connection::exec ) } Connection *obj = ObjectWrap::Unwrap( args.This() ); - + if( obj == NULL || obj->conn == NULL ) { std::string error_msg; getErrorMsg( JS_ERR_INVALID_OBJECT, error_msg ); @@ -453,9 +454,9 @@ NODE_API_FUNC( Connection::exec ) args.GetReturnValue().SetUndefined(); return; } - - String::Utf8Value param0( args[0]->ToString() ); - + + Nan::Utf8String param0( args[0] ); + executeBaton *baton = new executeBaton(); baton->obj = obj; baton->callback_required = callback_required; @@ -487,10 +488,10 @@ NODE_API_FUNC( Connection::exec ) baton->execData.push_back( new ExecuteData ); baton->num_rows = 1; } - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); @@ -498,11 +499,11 @@ NODE_API_FUNC( Connection::exec ) status = uv_queue_work( uv_default_loop(), req, executeWork, (uv_after_work_cb)executeAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + Persistent ResultSet; executeWork( req ); @@ -510,7 +511,7 @@ NODE_API_FUNC( Connection::exec ) delete baton; delete req; - + if( !success ) { args.GetReturnValue().SetUndefined(); return; @@ -525,17 +526,17 @@ struct prepareBaton { bool err; std::string error_msg; bool callback_required; - + StmtObject *obj; std::string stmt; Persistent StmtObj; - + prepareBaton() { err = false; callback_required = false; obj = NULL; } - + ~prepareBaton() { obj = NULL; callback.Reset(); @@ -543,22 +544,22 @@ struct prepareBaton { } }; -void Connection::prepareWork( uv_work_t *req ) +void Connection::prepareWork( uv_work_t *req ) /*********************************************/ { prepareBaton *baton = static_cast(req->data); - if( baton->obj == NULL || baton->obj->connection == NULL || + if( baton->obj == NULL || baton->obj->connection == NULL || baton->obj->connection->conn == NULL ) { baton->err = true; getErrorMsg( JS_ERR_INVALID_OBJECT, baton->error_msg ); return; } - + scoped_lock lock( baton->obj->connection->conn_mutex ); baton->obj->sqlany_stmt = api.sqlany_prepare( baton->obj->connection->conn, baton->stmt.c_str() ); - + if( baton->obj->sqlany_stmt == NULL ) { baton->err = true; getErrorMsg( baton->obj->connection->conn, baton->error_msg ); @@ -566,14 +567,14 @@ void Connection::prepareWork( uv_work_t *req ) } } -void Connection::prepareAfter( uv_work_t *req ) +void Connection::prepareAfter( uv_work_t *req ) /**********************************************/ { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope( isolate ); prepareBaton *baton = static_cast(req->data); Local undef = Local::New( isolate, Undefined( isolate ) ); - + if( baton->err ) { callBack( &( baton->error_msg ), baton->callback, undef, baton->callback_required ); @@ -581,13 +582,13 @@ void Connection::prepareAfter( uv_work_t *req ) delete req; return; } - + if( baton->callback_required ) { Local StmtObj = Local::New( isolate, baton->StmtObj ); callBack( NULL, baton->callback, StmtObj, baton->callback_required ); baton->StmtObj.Reset(); } - + delete baton; delete req; } @@ -611,9 +612,9 @@ NODE_API_FUNC( Connection::prepare ) args.GetReturnValue().SetUndefined(); return; } - + Connection *db = ObjectWrap::Unwrap( args.This() ); - + if( db == NULL || db->conn == NULL ) { std::string error_msg; getErrorMsg( JS_ERR_NOT_CONNECTED, error_msg ); @@ -640,17 +641,17 @@ NODE_API_FUNC( Connection::prepare ) p_stmt.Reset(); return; } - - String::Utf8Value param0( args[0]->ToString() ); - + + Nan::Utf8String param0( args[0] ); + prepareBaton *baton = new prepareBaton(); baton->obj = obj; - baton->callback_required = callback_required; + baton->callback_required = callback_required; baton->stmt = std::string(*param0); - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); @@ -659,21 +660,21 @@ NODE_API_FUNC( Connection::prepare ) status = uv_queue_work( uv_default_loop(), req, prepareWork, (uv_after_work_cb)prepareAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); p_stmt.Reset(); return; } - + prepareWork( req ); bool err = baton->err; prepareAfter( req ); - + if( err ) { args.GetReturnValue().SetUndefined(); return; } - args.GetReturnValue().Set( p_stmt ); + args.GetReturnValue().Set( p_stmt.Get(isolate)); p_stmt.Reset(); } @@ -685,12 +686,12 @@ struct connectBaton { bool err; std::string error_msg; bool callback_required; - + Connection *obj; bool sqlca_connection; std::string conn_string; void *sqlca; - + connectBaton() { obj = NULL; sqlca = NULL; @@ -698,36 +699,36 @@ struct connectBaton { err = false; callback_required = false; } - + ~connectBaton() { obj = NULL; sqlca = NULL; callback.Reset(); } - + }; -void Connection::connectWork( uv_work_t *req ) +void Connection::connectWork( uv_work_t *req ) /*********************************************/ { connectBaton *baton = static_cast(req->data); scoped_lock api_lock( api_mutex ); scoped_lock lock( baton->obj->conn_mutex ); - + if( baton->obj->conn != NULL ) { baton->err = true; getErrorMsg( JS_ERR_CONNECTION_ALREADY_EXISTS, baton->error_msg ); return; } - + if( api.initialized == false) { - + if( !sqlany_initialize_interface( &api, NULL ) ) { baton->err = true; getErrorMsg( JS_ERR_INITIALIZING_DBCAPI, baton->error_msg ); return; } - + if( !api.sqlany_init( "Node.js", SQLANY_API_VERSION_4, &(baton->obj->max_api_ver) )) { // As long as the version is >= 2, we're OK. We just have to disable @@ -746,7 +747,7 @@ void Connection::connectWork( uv_work_t *req ) } } } - + if( !baton->sqlca_connection ) { baton->obj->conn = api.sqlany_new_connection(); if( !api.sqlany_connect( baton->obj->conn, baton->conn_string.c_str() ) ) { @@ -757,7 +758,7 @@ void Connection::connectWork( uv_work_t *req ) cleanAPI(); return; } - + } else { baton->obj->conn = api.sqlany_make_connection( baton->sqlca ); if( baton->obj->conn == NULL ) { @@ -765,20 +766,20 @@ void Connection::connectWork( uv_work_t *req ) cleanAPI(); return; } - } - + } + baton->obj->sqlca_connection = baton->sqlca_connection; openConnections++; } -void Connection::connectAfter( uv_work_t *req ) +void Connection::connectAfter( uv_work_t *req ) /**********************************************/ { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope( isolate ); connectBaton *baton = static_cast(req->data); Local undef = Local::New( isolate, Undefined( isolate ) ); - + if( baton->err ) { callBack( &( baton->error_msg ), baton->callback, undef, baton->callback_required ); @@ -786,9 +787,9 @@ void Connection::connectAfter( uv_work_t *req ) delete req; return; } - + callBack( NULL, baton->callback, undef, baton->callback_required ); - + delete baton; delete req; } @@ -797,10 +798,11 @@ NODE_API_FUNC( Connection::connect ) /**********************************/ { Isolate *isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope( isolate ); int num_args = args.Length(); Connection *obj; - obj = ObjectWrap::Unwrap( args.This() ); + obj = ObjectWrap::Unwrap( args.This() ); bool sqlca_connection = false; bool callback_required = false; int cbfunc_arg = -1; @@ -817,25 +819,25 @@ NODE_API_FUNC( Connection::connect ) } else if( num_args == 1 && args[0]->IsNumber() ){ sqlca_connection = true; - + } else if( num_args == 1 && args[0]->IsString() ) { sqlca_connection = false; - + } else if( num_args == 1 && args[0]->IsObject() ) { sqlca_connection = false; arg_is_string = false; arg_is_object = true; - + } else if( num_args == 2 && args[0]->IsNumber() && args[1]->IsFunction() ) { sqlca_connection = true; callback_required = true; cbfunc_arg = 1; - + } else if( num_args == 2 && args[0]->IsString() && args[1]->IsFunction() ) { sqlca_connection = false; callback_required = true; cbfunc_arg = 1; - + } else if( num_args == 2 && args[0]->IsObject() && args[1]->IsFunction() ) { sqlca_connection = false; callback_required = true; @@ -848,44 +850,44 @@ NODE_API_FUNC( Connection::connect ) args.GetReturnValue().SetUndefined(); return; } - + connectBaton *baton = new connectBaton(); baton->obj = obj; baton->callback_required = callback_required; baton->sqlca_connection = sqlca_connection; - + if( sqlca_connection ) { - baton->sqlca = (void *)(long)args[0]->NumberValue(); - + baton->sqlca = (void *)(long)args[0]->NumberValue(context).ToChecked(); + } else { Local localArg = Local::New( isolate, obj->_arg ); if( localArg->Length() > 0 ) { - String::Utf8Value param0( localArg ); + Nan::Utf8String param0( localArg ); baton->conn_string = std::string(*param0); } else { baton->conn_string = std::string(); } if( arg_is_string ) { - String::Utf8Value param0( args[0]->ToString() ); + Nan::Utf8String param0( args[0] ); baton->conn_string.append( ";" ); baton->conn_string.append(*param0); } else if( arg_is_object ) { Persistent arg_string; - HashToString( args[0]->ToObject(), arg_string ); - Local local_arg_string = + HashToString( args[0]->ToObject(context).ToLocalChecked(), arg_string ); + Local local_arg_string = Local::New( isolate, arg_string ); - String::Utf8Value param0( local_arg_string ); + Nan::Utf8String param0( local_arg_string ); baton->conn_string.append( ";" ); baton->conn_string.append(*param0); arg_string.Reset(); } baton->conn_string.append( ";CHARSET='UTF-8'" ); } - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); @@ -897,7 +899,7 @@ NODE_API_FUNC( Connection::connect ) args.GetReturnValue().SetUndefined(); return; } - + connectWork( req ); connectAfter( req ); args.GetReturnValue().SetUndefined(); @@ -905,13 +907,13 @@ NODE_API_FUNC( Connection::connect ) } // Disconnect Function -void Connection::disconnectWork( uv_work_t *req ) +void Connection::disconnectWork( uv_work_t *req ) /************************************************/ { noParamBaton *baton = static_cast(req->data); scoped_lock api_lock(api_mutex ); scoped_lock lock( baton->obj->conn_mutex ); - + if( baton->obj->conn == NULL ) { getErrorMsg( JS_ERR_NOT_CONNECTED, baton->error_msg ); return; @@ -922,16 +924,16 @@ void Connection::disconnectWork( uv_work_t *req ) if( !baton->obj->sqlca_connection ) { api.sqlany_disconnect( baton->obj->conn ); } - // Must free the connection object or there will be a memory leak + // Must free the connection object or there will be a memory leak api.sqlany_free_connection( baton->obj->conn ); baton->obj->conn = NULL; openConnections--; - if( openConnections <= 0 ) { + if( openConnections <= 0 ) { openConnections = 0; cleanAPI(); } - + return; } @@ -943,53 +945,53 @@ NODE_API_FUNC( Connection::disconnect ) int num_args = args.Length(); bool callback_required = false; int cbfunc_arg = -1; - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsFunction() ) { callback_required = true; cbfunc_arg = 0; - + } else { throwError( JS_ERR_INVALID_ARGUMENTS ); args.GetReturnValue().SetUndefined(); return; } - + Connection *obj = ObjectWrap::Unwrap( args.This() ); noParamBaton *baton = new noParamBaton(); - + baton->callback_required = callback_required; baton->obj = obj; - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; status = uv_queue_work( uv_default_loop(), req, disconnectWork, (uv_after_work_cb)noParamAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + disconnectWork( req ); noParamAfter( req ); args.GetReturnValue().SetUndefined(); return; } -void Connection::commitWork( uv_work_t *req ) +void Connection::commitWork( uv_work_t *req ) /********************************************/ { noParamBaton *baton = static_cast(req->data); scoped_lock lock( baton->obj->conn_mutex ); - + if( baton->obj->conn == NULL ) { baton->err = true; getErrorMsg( JS_ERR_NOT_CONNECTED, baton->error_msg ); @@ -1011,48 +1013,48 @@ NODE_API_FUNC( Connection::commit ) int num_args = args.Length(); bool callback_required = false; int cbfunc_arg = -1; - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsFunction() ) { callback_required = true; cbfunc_arg = 0; - + } else { throwError( JS_ERR_INVALID_ARGUMENTS ); args.GetReturnValue().SetUndefined(); return; } - + Connection *obj = ObjectWrap::Unwrap( args.This() ); - + noParamBaton *baton = new noParamBaton(); baton->obj = obj; baton->callback_required = callback_required; - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; - status = uv_queue_work( uv_default_loop(), req, commitWork, + status = uv_queue_work( uv_default_loop(), req, commitWork, (uv_after_work_cb)noParamAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + commitWork( req ); noParamAfter( req ); args.GetReturnValue().SetUndefined(); return; } -void Connection::rollbackWork( uv_work_t *req ) +void Connection::rollbackWork( uv_work_t *req ) /**********************************************/ { noParamBaton *baton = static_cast(req->data); @@ -1079,41 +1081,41 @@ NODE_API_FUNC( Connection::rollback ) int num_args = args.Length(); bool callback_required = false; int cbfunc_arg = -1; - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsFunction() ) { callback_required = true; cbfunc_arg = 0; - + } else { throwError( JS_ERR_INVALID_ARGUMENTS ); args.GetReturnValue().SetUndefined(); return; } - + Connection *obj = ObjectWrap::Unwrap( args.This() ); noParamBaton *baton = new noParamBaton(); baton->obj = obj; baton->callback_required = callback_required; - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; status = uv_queue_work( uv_default_loop(), req, rollbackWork, (uv_after_work_cb)noParamAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + rollbackWork( req ); noParamAfter( req ); args.GetReturnValue().SetUndefined(); @@ -1132,29 +1134,29 @@ struct dropBaton { bool err; std::string error_msg; bool callback_required; - - StmtObject *obj; - + + StmtObject *obj; + dropBaton() { err = false; callback_required = false; obj = NULL; } - + ~dropBaton() { obj = NULL; callback.Reset(); } }; -void StmtObject::dropAfter( uv_work_t *req ) +void StmtObject::dropAfter( uv_work_t *req ) /*******************************************/ { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope( isolate ); dropBaton *baton = static_cast(req->data); Local undef = Local::New( isolate, Undefined( isolate ) ); - + if( baton->err ) { callBack( &( baton->error_msg ), baton->callback, undef, baton->callback_required ); @@ -1162,14 +1164,14 @@ void StmtObject::dropAfter( uv_work_t *req ) delete req; return; } - + callBack( NULL, baton->callback, undef, baton->callback_required ); - + delete baton; delete req; } -void StmtObject::dropWork( uv_work_t *req ) +void StmtObject::dropWork( uv_work_t *req ) /******************************************/ { dropBaton *baton = static_cast(req->data); @@ -1187,41 +1189,41 @@ NODE_API_FUNC( StmtObject::drop ) int num_args = args.Length(); bool callback_required = false; int cbfunc_arg = -1; - + if( num_args == 0 ) { - + } else if( num_args == 1 && args[0]->IsFunction() ) { callback_required = true; cbfunc_arg = 0; - + } else { throwError( JS_ERR_INVALID_ARGUMENTS ); args.GetReturnValue().SetUndefined(); return; } - + StmtObject *obj = ObjectWrap::Unwrap( args.This() ); dropBaton *baton = new dropBaton(); baton->obj = obj; baton->callback_required = callback_required; - + uv_work_t *req = new uv_work_t(); req->data = baton; - + if( callback_required ) { Local callback = Local::Cast(args[cbfunc_arg]); baton->callback.Reset( isolate, callback ); - + int status; status = uv_queue_work( uv_default_loop(), req, dropWork, (uv_after_work_cb)dropAfter ); assert(status == 0); - + args.GetReturnValue().SetUndefined(); return; } - + dropWork( req ); dropAfter( req ); args.GetReturnValue().SetUndefined(); @@ -1232,11 +1234,7 @@ void init( Local exports ) /********************************/ { uv_mutex_init(&api_mutex); -#if v012 - Isolate *isolate = Isolate::GetCurrent(); -#else Isolate *isolate = exports->GetIsolate(); -#endif StmtObject::Init( isolate ); Connection::Init( isolate ); NODE_SET_METHOD( exports, "createConnection", Connection::NewInstance ); @@ -1244,4 +1242,4 @@ void init( Local exports ) NODE_MODULE( DRIVER_NAME, init ) -#endif // !v010 +#endif //NODE_MAJOR_VERSION >= 12 \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 319ddd6..1379d50 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -5,7 +5,7 @@ #include "sqlany_utils.h" #include "nan.h" -#if !v010 +#if NODE_MAJOR_VERSION >= 12 using namespace v8; using namespace node; @@ -17,7 +17,7 @@ void getErrorMsg( int code, std::string &str ) message << "Code: "; message << code; message << " Msg: "; - + switch( code ) { case JS_ERR_INVALID_OBJECT: message << "Invalid Object"; @@ -53,6 +53,15 @@ void getErrorMsg( int code, std::string &str ) } +v8::Local GetUtf8String(v8::Isolate *isolate, std::string msg) { + auto ret = String::NewFromUtf8(isolate, msg.c_str()); +#if NODE_MAJOR_VERSION == 14 + return ret.ToLocalChecked(); +#else + return ret; +#endif +} + void getErrorMsg( a_sqlany_connection *conn, std::string &str ) /*************************************************************/ { @@ -73,8 +82,8 @@ void throwError( a_sqlany_connection *conn ) Isolate *isolate = Isolate::GetCurrent(); std::string message; getErrorMsg( conn, message ); - isolate->ThrowException( - Exception::Error( String::NewFromUtf8( isolate, message.c_str() ) ) ); + isolate->ThrowException( + Exception::Error( GetUtf8String(isolate, message.c_str() )) ); } void throwError( int code ) @@ -82,9 +91,10 @@ void throwError( int code ) { Isolate *isolate = Isolate::GetCurrent(); std::string message; + getErrorMsg( code, message ); - isolate->ThrowException( - Exception::Error( String::NewFromUtf8( isolate, message.c_str() ) ) ); + isolate->ThrowException( + Exception::Error(GetUtf8String(isolate, message.c_str())) ); } void callBack( std::string * str, @@ -103,23 +113,19 @@ void callBack( std::string * str, throwError( JS_ERR_INVALID_ARGUMENTS ); return; } - + Local Err; if( str == NULL ) { Err = Local::New( isolate, Undefined( isolate ) ); - + } else { - Err = Exception::Error( String::NewFromUtf8( isolate, str->c_str() ) ); + Err = Exception::Error(GetUtf8String(isolate, str->c_str())); } - + int argc = 2; Local argv[2] = { Err, Result }; - -#if v012 - TryCatch try_catch; -#else + TryCatch try_catch( isolate ); -#endif Nan::Callback *cb = new Nan::Callback( local_callback ); cb->Call( argc, argv ); if( try_catch.HasCaught()) { @@ -128,7 +134,7 @@ void callBack( std::string * str, } else { if( str != NULL ) { isolate->ThrowException( - Exception::Error( String::NewFromUtf8( isolate, str->c_str() ) ) ); + Exception::Error(GetUtf8String(isolate, str->c_str()))); } } } @@ -162,81 +168,79 @@ void callBack( std::string * str, return; } Local callback = Local::Cast(arg); - + Local Err; if( str == NULL ) { Err = Local::New( isolate, Undefined( isolate ) ); - + } else { - Err = Exception::Error( String::NewFromUtf8( isolate, str->c_str() ) ); + Err = Exception::Error(GetUtf8String(isolate, str->c_str())); } - + int argc = 2; Local argv[2] = { Err, Result }; - -#if v012 - TryCatch try_catch; -#else + TryCatch try_catch( isolate ); -#endif Nan::Callback *cb = new Nan::Callback( callback ); cb->Call( argc, argv ); if( try_catch.HasCaught()) { node::FatalException( isolate, try_catch ); } - + } else { if( str != NULL ) { - isolate->ThrowException( - Exception::Error( String::NewFromUtf8( isolate, str->c_str() ) ) ); + isolate->ThrowException( + Exception::Error(GetUtf8String(isolate, str->c_str()))); } } } static bool getWideBindParameters( std::vector &execData, - Handle arg, + Local arg, std::vector & params, unsigned &num_rows ) /*********************************************************************************/ { - Handle rows = Handle::Cast( arg ); - num_rows = rows->Length(); + Isolate* isolate = Isolate::GetCurrent(); + Local context = isolate->GetCurrentContext(); + Local rows = Local::Cast( arg ); + num_rows = rows->Length(); - Handle row0 = Handle::Cast( rows->Get(0) ); - unsigned num_cols = row0->Length(); - unsigned c; + Local row0 = Local::Cast( rows->Get(context, 0).ToLocalChecked() ); + unsigned num_cols = row0->Length(); + unsigned c; - if( num_cols == 0 ) { + if( num_cols == 0 ) { // if an empty array was passed in, we still need ExecuteData ExecuteData *ex = new ExecuteData; execData.push_back( ex ); return true; - } + } - // Make sure that each array in the list has the same number and types - // of values - for( unsigned int r = 1; r < num_rows; r++ ) { - Handle row = Handle::Cast( rows->Get(r) ); + // Make sure that each array in the list has the same number and types + // of values + for( unsigned int r = 1; r < num_rows; r++ ) { + Local row = Local::Cast( rows->Get(context, r).ToLocalChecked() ); for( c = 0; c < num_cols; c++ ) { - Handle val0 = row0->Get(c); - Handle val = row->Get(c); + Local val0 = row0->Get(context, c).ToLocalChecked(); + Local val = row->Get(context, c).ToLocalChecked(); - if( ( val0->IsInt32() || val0->IsNumber() ) && + if( ( val0->IsInt32() || val0->IsNumber() ) && ( !val->IsInt32() && !val->IsNumber() && !val->IsNull() ) ) { return false; - } - if( val0->IsString() && + } + if( val0->IsString() && !val->IsString() && !val->IsNull() ) { return false; - } - if( Buffer::HasInstance( val0 ) && + } + if( Buffer::HasInstance( val0 ) && !Buffer::HasInstance( val ) && !val->IsNull() ) { return false; - } + } } - } + } - for( c = 0; c < num_cols; c++ ) { + for( c = 0; c < num_cols; c++ ) { a_sqlany_bind_param param; memset( ¶m, 0, sizeof( param ) ); @@ -253,67 +257,70 @@ static bool getWideBindParameters( std::vector &execData, param.value.is_null = is_null; param.value.is_address = false; - if( row0->Get(c)->IsInt32() || row0->Get(c)->IsNumber() ) { - param.value.type = A_DOUBLE; - param.value.buffer = (char *)( param_double ); + if( row0->Get(context, c).ToLocalChecked()->IsInt32() || row0->Get(context, c).ToLocalChecked()->IsNumber() ) { + param.value.type = A_DOUBLE; + param.value.buffer = (char *)( param_double ); - } else if( row0->Get(c)->IsString() ) { - param.value.type = A_STRING; - param.value.buffer = (char *)char_arr; - param.value.length = len; - param.value.is_address = true; + } else if( row0->Get(context, c).ToLocalChecked()->IsString() ) { + param.value.type = A_STRING; + param.value.buffer = (char *)char_arr; + param.value.length = len; + param.value.is_address = true; - } else if( Buffer::HasInstance( row0->Get(c) ) ) { - param.value.type = A_BINARY; - param.value.buffer = (char *)char_arr; - param.value.length = len; - param.value.is_address = true; - - } else if( row0->Get(c)->IsNull() ) { + } else if( Buffer::HasInstance( row0->Get(context, c).ToLocalChecked() ) ) { + param.value.type = A_BINARY; + param.value.buffer = (char *)char_arr; + param.value.length = len; + param.value.is_address = true; + + } else if( row0->Get(context, c).ToLocalChecked()->IsNull() ) { } else{ - return false; + return false; } for( unsigned int r = 0; r < num_rows; r++ ) { - Handle bind_params = Handle::Cast( rows->Get(r) ); - - is_null[r] = false; - if( bind_params->Get(c)->IsInt32() || bind_params->Get(c)->IsNumber() ) { - param_double[r] = bind_params->Get(c)->NumberValue(); - - } else if( bind_params->Get(c)->IsString() ) { - String::Utf8Value paramValue( bind_params->Get(c)->ToString() ); + Local bind_params = Local::Cast( rows->Get(context, r).ToLocalChecked()); + + is_null[r] = false; + if( bind_params->Get(context, c).ToLocalChecked()->IsInt32() || bind_params->Get(context, c).ToLocalChecked()->IsNumber() ) { + param_double[r] = bind_params->Get(context, c).ToLocalChecked()->NumberValue(context).ToChecked(); + + } else if( bind_params->Get(context, c).ToLocalChecked()->IsString() ) { + Nan::Utf8String paramValue( bind_params->Get(context, c).ToLocalChecked() ); const char* param_string = (*paramValue); len[r] = (size_t)paramValue.length(); char *param_char = new char[len[r] + 1]; char_arr[r] = param_char; memcpy( param_char, param_string, len[r] + 1 ); - - } else if( Buffer::HasInstance( bind_params->Get(c) ) ) { - len[r] = Buffer::Length( bind_params->Get(c) ); + + } else if( Buffer::HasInstance( bind_params->Get(context, c).ToLocalChecked()) ) { + len[r] = Buffer::Length( bind_params->Get(context, c).ToLocalChecked()); char *param_char = new char[len[r]]; char_arr[r] = param_char; - memcpy( param_char, Buffer::Data( bind_params->Get(c) ), len[r] ); + memcpy( param_char, Buffer::Data( bind_params->Get(context, c).ToLocalChecked()), len[r] ); - } else if( bind_params->Get(c)->IsNull() ) { + } else if( bind_params->Get(context, c).ToLocalChecked()->IsNull() ) { is_null[r] = true; - } + } } - + params.push_back( param ); - } + } - return true; + return true; } bool getBindParameters( std::vector &execData, - Handle arg, + Local arg, std::vector & params, unsigned &num_rows ) /*************************************************************************/ { - Handle bind_params = Handle::Cast( arg ); + + Isolate* isolate = Isolate::GetCurrent(); + Local context = isolate->GetCurrentContext(); + Local bind_params = Local::Cast( arg ); if( bind_params->Length() == 0 ) { // if an empty array was passed in, we still need ExecuteData @@ -322,7 +329,7 @@ bool getBindParameters( std::vector &execData, return true; } - if( bind_params->Get(0)->IsArray() ) { + if( bind_params->Get(context, 0).ToLocalChecked()->IsArray() ) { return getWideBindParameters( execData, arg, params, num_rows ); } num_rows = 1; @@ -334,68 +341,68 @@ bool getBindParameters( std::vector &execData, a_sqlany_bind_param param; memset( ¶m, 0, sizeof( param ) ); - if( bind_params->Get(i)->IsInt32() ) { + if( bind_params->Get(context, i).ToLocalChecked()->IsInt32() ) { int *param_int = new int; - *param_int = bind_params->Get(i)->Int32Value(); + *param_int = bind_params->Get(context, i).ToLocalChecked()->Int32Value(context).ToChecked(); ex->addInt( param_int ); param.value.buffer = (char *)( param_int ); param.value.type = A_VAL32; - - } else if( bind_params->Get(i)->IsNumber() ) { + + } else if( bind_params->Get(context, i).ToLocalChecked()->IsNumber() ) { double *param_double = new double; - *param_double = bind_params->Get(i)->NumberValue(); // Remove Round off Error + *param_double = bind_params->Get(context, i).ToLocalChecked()->NumberValue(context).ToChecked(); // Remove Round off Error ex->addNum( param_double ); param.value.buffer = (char *)( param_double ); param.value.type = A_DOUBLE; - - } else if( bind_params->Get(i)->IsString() ) { - String::Utf8Value paramValue( bind_params->Get(i)->ToString() ); + + } else if( bind_params->Get(context, i).ToLocalChecked()->IsString() ) { + Nan::Utf8String paramValue( bind_params->Get(context, i).ToLocalChecked() ); const char* param_string = (*paramValue); size_t *len = new size_t; *len = (size_t)paramValue.length(); - + char **char_arr = new char *; char *param_char = new char[*len + 1]; *char_arr = param_char; memcpy( param_char, param_string, ( *len ) + 1 ); ex->addStrings( char_arr, len ); - + param.value.type = A_STRING; param.value.buffer = param_char; param.value.length = len; param.value.buffer_size = *len + 1; - - } else if( Buffer::HasInstance( bind_params->Get(i) ) ) { + + } else if( Buffer::HasInstance( bind_params->Get(context, i).ToLocalChecked() ) ) { size_t *len = new size_t; - *len = Buffer::Length( bind_params->Get(i) ); + *len = Buffer::Length( bind_params->Get(context, i).ToLocalChecked() ); char **char_arr = new char *; char *param_char = new char[*len]; *char_arr = param_char; - - memcpy( param_char, Buffer::Data( bind_params->Get(i) ), *len ); + + memcpy( param_char, Buffer::Data( bind_params->Get(context, i).ToLocalChecked() ), *len ); ex->addStrings( char_arr, len ); - + param.value.type = A_BINARY; param.value.buffer = param_char; param.value.length = len; param.value.buffer_size = sizeof( param_char ); - - } else if( bind_params->Get(i)->IsNull() ) { + + } else if( bind_params->Get(context, i).ToLocalChecked()->IsNull() ) { param.value.type = A_STRING; sacapi_bool *is_null = new sacapi_bool; param.value.is_null = is_null; ex->addNull( is_null ); is_null[0] = true; - + } else{ return false; } - + params.push_back( param ); } - return true; + return true; } bool getResultSet( Persistent & Result, @@ -406,6 +413,7 @@ bool getResultSet( Persistent & Result, /*****************************************************************/ { Isolate *isolate = Isolate::GetCurrent(); + Local context = isolate->GetCurrentContext(); HandleScope scope( isolate ); int num_rows = 0; size_t num_cols = colNames.size(); @@ -414,7 +422,7 @@ bool getResultSet( Persistent & Result, Result.Reset( isolate, Integer::New( isolate, rows_affected ) ); return true; } - + if( num_cols > 0 ) { size_t count = 0; size_t count_int = 0, count_num = 0, count_string = 0; @@ -427,7 +435,7 @@ bool getResultSet( Persistent & Result, for( size_t i = 0; i < num_cols; i++ ) { switch( col_types[count] ) { case A_INVALID_TYPE: - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Null( isolate ) ); break; @@ -437,90 +445,72 @@ bool getResultSet( Persistent & Result, case A_VAL8: case A_UVAL8: if( execData->intIsNull( count_int ) ) { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Null( isolate ) ); } else { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Integer::New( isolate, execData->getInt( count_int ) ) ); } count_int++; break; - + case A_UVAL32: case A_UVAL64: case A_VAL64: case A_DOUBLE: if( execData->numIsNull( count_num ) ) { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Null( isolate ) ); } else { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Number::New( isolate, execData->getNum( count_num ) ) ); } count_num++; break; - + case A_BINARY: if( execData->stringIsNull( count_string ) ) { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Null( isolate ) ); } else { -#if v012 - Local buf = node::Buffer::New( + MaybeLocal mbuf = node::Buffer::Copy( isolate, execData->getString( count_string ), - execData->getLen( count_string ) ); - curr_row->Set( String::NewFromUtf8( isolate, - colNames[i] ), - buf ); -#else - MaybeLocal mbuf = node::Buffer::Copy( - isolate, execData->getString( count_string ), - execData->getLen( count_string ) ); + execData->getLen( count_string ) ); Local buf = mbuf.ToLocalChecked(); -#endif - curr_row->Set( String::NewFromUtf8( isolate, - colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), buf ); } count_string++; break; - - case A_STRING: + + case A_STRING: if( execData->stringIsNull( count_string ) ) { - curr_row->Set( String::NewFromUtf8( isolate, colNames[i] ), + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), Null( isolate ) ); } else { - curr_row->Set( String::NewFromUtf8( isolate, - colNames[i] ), -#if v012 - String::NewFromUtf8( isolate, - execData->getString( count_string ), - String::NewStringType::kNormalString, - (int)execData->getLen( count_string ) ) -#else + curr_row->Set(context, GetUtf8String(isolate, colNames[i]), String::NewFromUtf8( isolate, execData->getString( count_string ), NewStringType::kNormal, (int)execData->getLen( count_string ) ).ToLocalChecked() -#endif ); } count_string++; break; - + default: return false; } count++; } - ResultSet->Set( num_rows - 1, curr_row ); + ResultSet->Set(context, num_rows - 1, curr_row ); } Result.Reset( isolate, ResultSet ); } else { - Result.Reset( isolate, Local::New( isolate, + Result.Reset( isolate, Local::New( isolate, Undefined( isolate ) ) ); } - + return true; } @@ -531,21 +521,21 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, std::vector & col_types ) /*****************************************************************/ { - + a_sqlany_data_value value; int num_cols = 0; - + rows_affected = api.sqlany_affected_rows( sqlany_stmt ); num_cols = api.sqlany_num_cols( sqlany_stmt ); - - + + if( rows_affected > 0 && num_cols < 1 ) { return true; } - + rows_affected = -1; if( num_cols > 0 ) { - + for( int i = 0; i < num_cols; i++ ) { a_sqlany_column_info info; api.sqlany_get_column_info( sqlany_stmt, i, &info ); @@ -554,7 +544,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, memcpy( name, info.name, size ); colNames.push_back( name ); } - + int count_string = 0, count_num = 0, count_int = 0; while( api.sqlany_fetch_next( sqlany_stmt ) ) { @@ -564,12 +554,12 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, return false; break; } - + if( *(value.is_null) ) { col_types.push_back( A_INVALID_TYPE ); continue; } - + switch( value.type ) { case A_BINARY: { @@ -581,7 +571,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_string++; break; } - + case A_STRING: { size_t *size = new size_t; @@ -592,7 +582,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_string++; break; } - + case A_VAL64: { double *val = new double; @@ -601,7 +591,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_num++; break; } - + case A_UVAL64: { double *val = new double; @@ -610,7 +600,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_num++; break; } - + case A_VAL32: { int *val = new int; @@ -628,7 +618,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_num++; break; } - + case A_VAL16: { int *val = new int; @@ -646,7 +636,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_int++; break; } - + case A_VAL8: { int *val = new int; @@ -655,7 +645,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_int++; break; } - + case A_UVAL8: { int *val = new int; @@ -664,7 +654,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_int++; break; } - + case A_DOUBLE: { double *val = new double; @@ -673,7 +663,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, count_num++; break; } - + default: return false; } @@ -681,7 +671,7 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt, } } } - + return true; } @@ -700,7 +690,7 @@ bool cleanAPI() // Generic Baton and Callback (After) Function // Use this if the function does not have any return values and -// Does not take any parameters. +// Does not take any parameters. // Create custom Baton and Callback (After) functions otherwise void Connection::noParamAfter( uv_work_t *req ) @@ -716,9 +706,9 @@ void Connection::noParamAfter( uv_work_t *req ) baton->callback_required ); return; } - + callBack( NULL, baton->callback, undef, baton->callback_required ); - + delete baton; delete req; } @@ -755,16 +745,17 @@ void StmtObject::Init( Isolate *isolate ) /***************************************/ { HandleScope scope(isolate); + Local context = isolate->GetCurrentContext(); // Prepare constructor template Local tpl = FunctionTemplate::New( isolate, New ); - tpl->SetClassName( String::NewFromUtf8( isolate, "StmtObject" ) ); + tpl->SetClassName(GetUtf8String(isolate, "StmtObject")); tpl->InstanceTemplate()->SetInternalFieldCount( 1 ); // Prototype NODE_SET_PROTOTYPE_METHOD( tpl, "exec", exec ); NODE_SET_PROTOTYPE_METHOD( tpl, "drop", drop ); NODE_SET_PROTOTYPE_METHOD( tpl, "getMoreResults", getMoreResults ); - constructor.Reset( isolate, tpl->GetFunction() ); + constructor.Reset( isolate, tpl->GetFunction(context).ToLocalChecked() ); } void StmtObject::New( const FunctionCallbackInfo &args ) @@ -779,9 +770,11 @@ void StmtObject::New( const FunctionCallbackInfo &args ) void StmtObject::NewInstance( const FunctionCallbackInfo &args ) /*********************************************************************/ { + Isolate* isolate = Isolate::GetCurrent(); + Local context = isolate->GetCurrentContext(); Persistent obj; CreateNewInstance( args, obj ); - args.GetReturnValue().Set( obj ); + args.GetReturnValue().Set( obj.Get(isolate) ); } void StmtObject::CreateNewInstance( const FunctionCallbackInfo & args, @@ -791,7 +784,7 @@ void StmtObject::CreateNewInstance( const FunctionCallbackInfo & args, Isolate *isolate = args.GetIsolate(); HandleScope scope(isolate); const unsigned argc = 1; - Handle argv[argc] = { args[0] }; + Local argv[argc] = { args[0] }; Localcons = Local::New( isolate, constructor ); #if NODE_MAJOR_VERSION >= 10 Local env = isolate->GetCurrentContext(); @@ -829,15 +822,16 @@ void HashToString( Local obj, Persistent &ret ) { Isolate *isolate = Isolate::GetCurrent(); HandleScope scope(isolate); - Local props = obj->GetOwnPropertyNames(); - int length = props->Length(); + Local context = isolate->GetCurrentContext(); + MaybeLocal props = obj->GetOwnPropertyNames(context); + int length = props.ToLocalChecked()->Length(); std::string params = ""; bool first = true; for( int i = 0; i < length; i++ ) { - Local key = props->Get(i).As(); - Local val = obj->Get(key).As(); - String::Utf8Value key_utf8( key ); - String::Utf8Value val_utf8( val ); + Local key = props.ToLocalChecked()->Get(context, i).ToLocalChecked().As(); + Local val = obj->Get(context, key).ToLocalChecked().As(); + String::Utf8Value key_utf8( isolate, key ); + String::Utf8Value val_utf8( isolate, val ); if( !first ) { params += ";"; } @@ -846,7 +840,7 @@ void HashToString( Local obj, Persistent &ret ) params += "="; params += std::string(*val_utf8); } - ret.Reset( isolate, String::NewFromUtf8( isolate, params.c_str() ) ); + ret.Reset(isolate, GetUtf8String(isolate, params.c_str())); } #if 0 @@ -899,6 +893,7 @@ Connection::Connection( const FunctionCallbackInfo &args ) /***************************************************************/ { Isolate *isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope( isolate ); uv_mutex_init(&conn_mutex); conn = NULL; @@ -911,21 +906,21 @@ Connection::Connection( const FunctionCallbackInfo &args ) if( args.Length() == 1 ) { //CheckArgType( args[0] ); if( args[0]->IsString() ) { - Local str = args[0]->ToString(); - int string_len = str->Utf8Length(); + MaybeLocal str = args[0]->ToString(context); + int string_len = str.ToLocalChecked()->Utf8Length(isolate); char *buf = new char[string_len+1]; - str->WriteUtf8( buf ); - _arg.Reset( isolate, String::NewFromUtf8( isolate, buf ) ); + str.ToLocalChecked()->WriteUtf8(isolate, buf ); + _arg.Reset( isolate, GetUtf8String(isolate, buf)); delete [] buf; } else if( args[0]->IsObject() ) { - HashToString( args[0]->ToObject(), _arg ); + HashToString(args[0]->ToObject(context).ToLocalChecked(), _arg); } else if( !args[0]->IsUndefined() && !args[0]->IsNull() ) { throwError( JS_ERR_INVALID_ARGUMENTS ); } else { - _arg.Reset( isolate, String::NewFromUtf8( isolate, "" ) ); + _arg.Reset( isolate, GetUtf8String(isolate, "")); } } else { - _arg.Reset( isolate, String::NewFromUtf8( isolate, "" ) ); + _arg.Reset( isolate, GetUtf8String(isolate, "")); } } @@ -944,7 +939,7 @@ Connection::~Connection() conn = NULL; openConnections--; } - + cleanAPI(); }; @@ -977,11 +972,12 @@ void Connection::Init( Isolate *isolate ) /***************************************/ { HandleScope scope( isolate ); + Local context = isolate->GetCurrentContext(); // Prepare constructor template Local tpl = FunctionTemplate::New( isolate, New ); - tpl->SetClassName( String::NewFromUtf8( isolate, "Connection" ) ); + tpl->SetClassName(GetUtf8String(isolate, "Connection")); tpl->InstanceTemplate()->SetInternalFieldCount( 1 ); - + // Prototype NODE_SET_PROTOTYPE_METHOD( tpl, "exec", exec ); NODE_SET_PROTOTYPE_METHOD( tpl, "prepare", prepare ); @@ -992,7 +988,7 @@ void Connection::Init( Isolate *isolate ) NODE_SET_PROTOTYPE_METHOD( tpl, "rollback", rollback ); NODE_SET_PROTOTYPE_METHOD( tpl, "connected", connected ); - constructor.Reset( isolate, tpl->GetFunction() ); + constructor.Reset( isolate, tpl->GetFunction(context).ToLocalChecked() ); } void Connection::New( const FunctionCallbackInfo &args ) @@ -1026,7 +1022,7 @@ void Connection::NewInstance( const FunctionCallbackInfo &args ) Isolate *isolate = args.GetIsolate(); HandleScope scope( isolate ); const unsigned argc = 1; - Handle argv[argc] = { args[0] }; + Local argv[argc] = { args[0] }; Local cons = Local::New( isolate, constructor ); #if NODE_MAJOR_VERSION >= 10 Local env = isolate->GetCurrentContext(); @@ -1038,4 +1034,4 @@ void Connection::NewInstance( const FunctionCallbackInfo &args ) args.GetReturnValue().Set( instance ); } -#endif // !v010 +#endif //NODE_MAJOR_VERSION >= 12