Ejemplo n.º 1
0
void ODBCStatement::UV_AfterExecuteNonQuery(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::ExecuteNonQuery\n");
  
  execute_work_data* data = (execute_work_data *)(req->data);
  
  HandleScope scope;
  
  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //First thing, let's check if the execution of the query returned any errors 
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    SQLLEN rowCount = 0;
    
    SQLRETURN ret = SQLRowCount(self->m_hSTMT, &rowCount);
    
    if (!SQL_SUCCEEDED(ret)) {
      rowCount = 0;
    }
    
    uv_mutex_lock(&ODBC::g_odbcMutex);
    SQLFreeStmt(self->m_hSTMT, SQL_CLOSE);
    uv_mutex_unlock(&ODBC::g_odbcMutex);
    
    Local<Value> args[2];

    args[0] = Local<Value>::New(Null());
    args[1] = Local<Value>::New(Number::New(rowCount));

    TryCatch try_catch;

    data->cb->Call(Context::GetCurrent()->Global(), 2, args);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  data->cb.Dispose();
  
  free(data);
  free(req);
  
  scope.Close(Undefined());
}
Ejemplo n.º 2
0
void ODBCStatement::UV_AfterExecuteDirect(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::UV_AfterExecuteDirect\n");
  
  execute_direct_work_data* data = (execute_direct_work_data *)(req->data);
  
  HandleScope scope;
  
  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //First thing, let's check if the execution of the query returned any errors 
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    Local<Value> args[3];
    bool* canFreeHandle = new bool(false);
    
    args[0] = External::New(self->m_hENV);
    args[1] = External::New(self->m_hDBC);
    args[2] = External::New(self->m_hSTMT);
    args[3] = External::New(canFreeHandle);
    
    Persistent<Object> js_result(ODBCResult::constructor_template->
                              GetFunction()->NewInstance(4, args));

    args[0] = Local<Value>::New(Null());
    args[1] = Local<Object>::New(js_result);

    TryCatch try_catch;

    data->cb->Call(Context::GetCurrent()->Global(), 2, args);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  data->cb.Dispose();
  
  free(data->sql);
  free(data);
  free(req);
  
  scope.Close(Undefined());
}
Ejemplo n.º 3
0
void ODBCStatement::UV_AfterExecuteDirect(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::UV_AfterExecuteDirect\n");

  execute_direct_work_data* data = (execute_direct_work_data *)(req->data);

  Nan::HandleScope scope;

  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //First thing, let's check if the execution of the query returned any errors
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    Local<Value> info[4];
    bool* canFreeHandle = new bool(false);

    info[0] = Nan::New<External>((void*) (intptr_t) self->m_hENV);
    info[1] = Nan::New<External>((void*) (intptr_t) self->m_hDBC);
    info[2] = Nan::New<External>((void*) (intptr_t) self->m_hSTMT);
    info[3] = Nan::New<External>((void*)canFreeHandle);

    //TODO persistent leak?
    Nan::Persistent<Object> js_result;
    js_result.Reset(Nan::New<Function>(ODBCResult::constructor)->NewInstance(4, info));

    info[0] = Nan::Null();
    info[1] = Nan::New(js_result);

    Nan::TryCatch try_catch;

    data->cb->Call(2, info);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  delete data->cb;

  free(data->sql);
  free(data);
  free(req);
}
Ejemplo n.º 4
0
void ODBCStatement::UV_AfterExecuteNonQuery(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::ExecuteNonQuery\n");
  
  execute_work_data* data = (execute_work_data *)(req->data);
  
  Nan::HandleScope scope;
  
  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //First thing, let's check if the execution of the query returned any errors 
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    SQLLEN rowCount = 0;
    
    SQLRETURN ret = SQLRowCount(self->m_hSTMT, &rowCount);
    
    if (!SQL_SUCCEEDED(ret)) {
      rowCount = 0;
    }
    
    SQLFreeStmt(self->m_hSTMT, SQL_CLOSE);
    
    Local<Value> info[2];

    info[0] = Nan::Null();
    info[1] = Nan::New<Number>(rowCount);

    Nan::TryCatch try_catch;
    
    data->cb->Call(Nan::GetCurrentContext()->Global(), 2, info);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  delete data->cb;
  
  free(data);
  free(req);
}
Ejemplo n.º 5
0
void ODBCStatement::UV_AfterBind(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::UV_AfterBind\n");
  
  bind_work_data* data = (bind_work_data *)(req->data);
  
  HandleScope scope;
  
  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //Check if there were errors 
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    Local<Value> args[2];

    args[0] = Local<Value>::New(Null());
    args[1] = Local<Value>::New(True());

    TryCatch try_catch;

    data->cb->Call(Context::GetCurrent()->Global(), 2, args);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  data->cb.Dispose();
  
  free(data);
  free(req);
  
  scope.Close(Undefined());
}
Ejemplo n.º 6
0
void ODBCStatement::UV_AfterBind(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::UV_AfterBind\n");

  bind_work_data* data = (bind_work_data *)(req->data);

  Nan::HandleScope scope;

  //an easy reference to the statment object
  ODBCStatement* self = data->stmt->self();

  //Check if there were errors
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      self->m_hSTMT,
      data->cb);
  }
  else {
    Local<Value> info[2];

    info[0] = Nan::Null();
    info[1] = Nan::True();

    Nan::TryCatch try_catch;

    data->cb->Call( 2, info);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  self->Unref();
  delete data->cb;

  free(data);
  free(req);
}
Ejemplo n.º 7
0
void ODBCStatement::UV_AfterExecute(uv_work_t* req, int status) {
  DEBUG_PRINTF("ODBCStatement::UV_AfterExecute\n");
  
  execute_work_data* data = (execute_work_data *)(req->data);
  Nan::HandleScope scope;
  int outParamCount = 0; // Non-zero tells its a SP with OUT param
  Local<Array> sp_result = Nan::New<Array>();
  
  //an easy reference to the statment object
  ODBCStatement* stmt = data->stmt->self();

  if (SQL_SUCCEEDED( data->result )) {
    for(int i = 0; i < stmt->paramCount; i++) { // For stored Procedure CALL
      if(stmt->params[i].paramtype % 2 == 0) {
        sp_result->Set(Nan::New(outParamCount), ODBC::GetOutputParameter(stmt->params[i]));
        outParamCount++;
      }
    }
  }
  if( stmt->paramCount ) {
    FREE_PARAMS( stmt->params, stmt->paramCount ) ;
  }
  
  //First thing, let's check if the execution of the query returned any errors 
  if(data->result == SQL_ERROR) {
    ODBC::CallbackSQLError(
      SQL_HANDLE_STMT,
      stmt->m_hSTMT,
      data->cb);
  }
  else {
    Local<Value> info[4];
    bool* canFreeHandle = new bool(false);
    
    info[0] = Nan::New<External>((void*) (intptr_t) stmt->m_hENV);
    info[1] = Nan::New<External>((void*) (intptr_t) stmt->m_hDBC);
    info[2] = Nan::New<External>((void*) (intptr_t) stmt->m_hSTMT);
    info[3] = Nan::New<External>((void*)canFreeHandle);
    
    Local<Object> js_result = Nan::New<Function>(ODBCResult::constructor)->NewInstance(4, info);

    info[0] = Nan::Null();
    info[1] = js_result;

    if(outParamCount) {
        info[2] = sp_result; // Must a CALL stmt
    }
    else info[2] = Nan::Null();

    Nan::TryCatch try_catch;

    data->cb->Call(3, info);

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }
  }

  stmt->Unref();
  delete data->cb;
  
  free(data);
  free(req);
}