コード例 #1
0
int WbFabricInterfaceImpl::openConnection(const db_mgmt_ConnectionRef &conn, const grt::StringRef &password)
{
  int new_connection_id = -1;

  MYSQL mysql;

  mysql_init(&mysql);

  // Retrieves the parameters needed to perform the connection
  std::string user = conn->parameterValues().get_string("userName");
  std::string host = conn->parameterValues().get_string("hostName");
  std::string socket = conn->parameterValues().get_string("socket");
  int port = (int)conn->parameterValues().get_int("port");

  // If the port is not specified it will take the default port to perform
  // fabric connections using mysqlrpc.
  if (port <= 0)
    port = 32275;

  // Sets the options needed to connect to the fabric server.
  int proto = MYSQL_PROTOCOL_TCP;
  mysql_options(&mysql, MYSQL_OPT_PROTOCOL, &proto);

  // Sets the connection timeout
  grt::DictRef wb_options = grt::DictRef::cast_from(get_grt()->get("/wb/options/options"));
  int connect_timeout = (int)wb_options.get_int("Fabric:ConnectionTimeOut", 60);
  mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout);
  
  
  if (!mysql_real_connect(&mysql, host.c_str(), user.c_str(), password.c_str(), NULL, port, socket.c_str(),
    CLIENT_COMPRESS | CLIENT_MULTI_RESULTS))
  {
    throw std::runtime_error(mysql_error(&mysql));
  }

  // A new connection_id is created and will be returned, the actuall connection
  // will be stored here and used through the generated id.
  new_connection_id = ++_connection_id;
  _connections[new_connection_id] = mysql;


  // Changes the format of the execution results to JSON
  // This saves the burden on having to parse the output in C code
  // and allows taking advantage of the JSON loader in python
  execute(new_connection_id, "set format=json");

  return new_connection_id;
}
コード例 #2
0
ActionGenerateReport::ActionGenerateReport(grt::StringRef template_filename)
  : fname(template_filename.c_str()), has_attributes(false), has_partitioning(false) {
  dictionary = mtemplate::CreateMainDictionary();
}