Exemplo n.º 1
0
uni::CallbackType OracleClient::New(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);

  /*
  REQ_OBJECT_ARG(0, settings);

  std:string hostname, user, password, database;
  unsigned int port, minConn, maxConn, incrConn;

  OBJ_GET_STRING(settings, "hostname", hostname);
  OBJ_GET_STRING(settings, "user", user);
  OBJ_GET_STRING(settings, "password", password);
  OBJ_GET_STRING(settings, "database", database);
  OBJ_GET_NUMBER(settings, "port", port, 1521);
  OBJ_GET_NUMBER(settings, "minConn", minConn, 0);
  OBJ_GET_NUMBER(settings, "maxConn", maxConn, 1);
  OBJ_GET_NUMBER(settings, "incrConn", incrConn, 1);

  std::ostringstream connectionStr;
      connectionStr << "//" << hostname << ":" << port << "/" << database;
  */

  OracleClient *client = new OracleClient();
  client->Wrap(args.This());
  UNI_RETURN(scope, args, args.This());
}
Exemplo n.º 2
0
uni::CallbackType Connection::New(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);

  Connection *connection = new Connection();
  connection->Wrap(args.This());
  UNI_RETURN(scope, args, args.This());
}
Exemplo n.º 3
0
uni::CallbackType Connection::ExecuteSync(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  REQ_STRING_ARG(0, sql);
  REQ_ARRAY_ARG(1, values);

  String::Utf8Value sqlVal(sql);

  ExecuteBaton* baton = new ExecuteBaton(connection, *sqlVal, &values, NULL);
  if (baton->error) {
    Local<String> message = String::New(baton->error->c_str());
    delete baton;
    UNI_THROW(Exception::Error(message));
  }

  uv_work_t* req = new uv_work_t();
  req->data = baton;

  baton->connection->Ref();
  EIO_Execute(req);
  baton->connection->Unref();
  Handle<Value> argv[2];
  handleResult(baton, argv);

  if(baton->error) {
    delete baton;
    UNI_THROW(argv[0]);
  }

  delete baton;
  UNI_RETURN(scope, args, argv[1]);
}
Exemplo n.º 4
0
uni::CallbackType Connection::Execute(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  REQ_STRING_ARG(0, sql);
  REQ_ARRAY_ARG(1, values);
  REQ_FUN_ARG(2, callback);

  String::Utf8Value sqlVal(sql);

  ExecuteBaton* baton = new ExecuteBaton(connection, *sqlVal, &values, &callback);
  if (baton->error) {
    Local<String> message = String::New(baton->error->c_str());
    delete baton;
    UNI_THROW(Exception::Error(message));
  }

  uv_work_t* req = new uv_work_t();
  req->data = baton;
  uv_queue_work(uv_default_loop(), req, EIO_Execute, (uv_after_work_cb)EIO_AfterExecute);

  connection->Ref();

  UNI_RETURN(scope, args, Undefined());
}
Exemplo n.º 5
0
uni::CallbackType Connection::SetPrefetchRowCount(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
  REQ_INT_ARG(0, prefetchRowCount);
  connection->m_prefetchRowCount = prefetchRowCount;
  UNI_RETURN(scope, args, Undefined());
}
Exemplo n.º 6
0
uni::CallbackType Connection::SetAutoCommit(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
  REQ_BOOL_ARG(0, autoCommit);
  connection->m_autoCommit = autoCommit;
  UNI_RETURN(scope, args, Undefined());
}
Exemplo n.º 7
0
uni::CallbackType OracleClient::ConnectSync(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  REQ_OBJECT_ARG(0, settings);

  OracleClient* client = ObjectWrap::Unwrap<OracleClient>(args.This());
  ConnectBaton baton(client, client->m_environment, NULL);

  OBJ_GET_STRING(settings, "hostname", baton.hostname);
  OBJ_GET_STRING(settings, "user", baton.user);
  OBJ_GET_STRING(settings, "password", baton.password);
  OBJ_GET_STRING(settings, "database", baton.database);
  OBJ_GET_NUMBER(settings, "port", baton.port, 1521);

  try {
    std::ostringstream connectionStr;
    connectionStr << "//" << baton.hostname << ":" << baton.port << "/" << baton.database;
    baton.connection = baton.environment->createConnection(baton.user, baton.password, connectionStr.str());
  } catch(oracle::occi::SQLException &ex) {
    baton.error = new std::string(ex.getMessage());
    UNI_THROW(Exception::Error(NanNew<String>(baton.error->c_str())));
  } catch (const std::exception& ex) {
    UNI_THROW(Exception::Error(NanNew<String>(ex.what())));
  }

  Handle<Object> connection = uni::Deref(Connection::constructorTemplate)->GetFunction()->NewInstance();
      (node::ObjectWrap::Unwrap<Connection>(connection))->setConnection(baton.client->m_environment, baton.connection);

  UNI_RETURN(scope, args, connection);

}
Exemplo n.º 8
0
uni::CallbackType Connection::IsConnected(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  if(connection && connection->m_connection) {
    UNI_RETURN(scope, args, Boolean::New(true));
  } else {
    UNI_RETURN(scope, args, Boolean::New(false));
  }
}
Exemplo n.º 9
0
uni::CallbackType Connection::Close(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  try {
    Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());
    connection->closeConnection();

    UNI_RETURN(scope, args, Undefined());
  } catch (const exception& ex) {
    UNI_THROW(Exception::Error(String::New(ex.what())));
  }
}
Exemplo n.º 10
0
uni::CallbackType Connection::Prepare(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  REQ_STRING_ARG(0, sql);

  String::Utf8Value sqlVal(sql);

  StatementBaton* baton = new StatementBaton(connection, *sqlVal, NULL);

  Local<Object> statementHandle(uni::Deref(Statement::constructorTemplate)->GetFunction()->NewInstance());
  Statement* statement = ObjectWrap::Unwrap<Statement>(statementHandle);
  statement->setBaton(baton);

  UNI_RETURN(scope, args, statementHandle);
}
Exemplo n.º 11
0
uni::CallbackType Connection::Rollback(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  REQ_FUN_ARG(0, callback);

  RollbackBaton* baton = new RollbackBaton(connection, &callback);

  uv_work_t* req = new uv_work_t();
  req->data = baton;
  uv_queue_work(uv_default_loop(), req, EIO_Rollback, (uv_after_work_cb)EIO_AfterRollback);

  connection->Ref();

  UNI_RETURN(scope, args, Undefined());
}
Exemplo n.º 12
0
uni::CallbackType Connection::CreateReader(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);
  Connection* connection = ObjectWrap::Unwrap<Connection>(args.This());

  REQ_STRING_ARG(0, sql);
  REQ_ARRAY_ARG(1, values);

  String::Utf8Value sqlVal(sql);

  ReaderBaton* baton = new ReaderBaton(connection, *sqlVal, &values);

  Local<Object> readerHandle(uni::Deref(Reader::constructorTemplate)->GetFunction()->NewInstance());
  Reader* reader = ObjectWrap::Unwrap<Reader>(readerHandle);
  reader->setBaton(baton);

  UNI_RETURN(scope, args, readerHandle);
}
Exemplo n.º 13
0
uni::CallbackType OracleClient::Connect(const uni::FunctionCallbackInfo& args) {
  UNI_SCOPE(scope);

  REQ_OBJECT_ARG(0, settings);
  REQ_FUN_ARG(1, callback);

  OracleClient* client = ObjectWrap::Unwrap<OracleClient>(args.This());
  ConnectBaton* baton = new ConnectBaton(client, client->m_environment, &callback);

  OBJ_GET_STRING(settings, "hostname", baton->hostname);
  OBJ_GET_STRING(settings, "user", baton->user);
  OBJ_GET_STRING(settings, "password", baton->password);
  OBJ_GET_STRING(settings, "database", baton->database);
  OBJ_GET_NUMBER(settings, "port", baton->port, 1521);
  OBJ_GET_STRING(settings, "tns", baton->tns);

  client->Ref();

  uv_work_t* req = new uv_work_t();
  req->data = baton;
  uv_queue_work(uv_default_loop(), req, EIO_Connect, (uv_after_work_cb)EIO_AfterConnect);

  UNI_RETURN(scope, args, NanUndefined());
}