コード例 #1
0
ファイル: Database.cpp プロジェクト: hnefatl/Chatroom
	bool Database::_GetChatroom(Statement &s, Chatroom &Out)
	{
		Nullable<std::string> Name;
		Nullable<std::string> OwnerUsername;
		Nullable<std::string> Password;
		Nullable<std::string> Description;
		Nullable<int> ServerFamily;
		Nullable<std::string> ServerIP;
		Nullable<int> ServerPort;

		if (!s.GetString("Name", Name) || !s.GetString("OwnerUsername", OwnerUsername) || !s.GetString("Password", Password) ||
				!s.GetString("Description", Description) || !s.GetInt("ServerFamily", ServerFamily) ||
				!s.GetString("ServerIP", ServerIP) || !s.GetInt("ServerPort", ServerPort))
			return false;

		if (Name.Null || OwnerUsername.Null || ServerIP.Null || ServerFamily.Null || ServerPort.Null)
			return false;

		Net::Address Address;
		Address.Load(ServerFamily.Value, ServerIP.Value, ServerPort.Value);
		Out.Name = Name.Value;
		Out.OwnerUsername = OwnerUsername.Value;
		Out.ServerAddress = Address;
		Out.Password = Password;
		Out.Description = Description;

		return true;
	}
コード例 #2
0
ファイル: Database.cpp プロジェクト: hnefatl/Chatroom
	bool Database::_GetUser(Statement &s, User &Out)
	{
		Nullable<std::string> Username;
		Nullable<std::string> Password;

		if (!s.GetString("Username", Username) || !s.GetString("Password", Password))
			return false;

		if (Username.Null || Password.Null)
			return false;

		Out.Username = Username.Value;
		Out.Password = Password.Value;
		return true;
	}
コード例 #3
0
ファイル: Database.cpp プロジェクト: hnefatl/Chatroom
	bool Database::_GetServer(Statement &s, Server &Out)
	{
		Nullable<std::string> Name;
		Nullable<int> Family;
		Nullable<std::string> IP;
		Nullable<int> Port;

		if (!s.GetString("Name", Name) || !s.GetInt("Family", Family) || !s.GetString("IP", IP) || !s.GetInt("Port", Port))
			return false;

		if (Family.Null || IP.Null || Port.Null || Name.Null)
			return false;

		Net::Address Address;
		Address.Load(Family.Value, IP.Value, Port.Value);
		Out.Address = Address;
		Out.Name = Name.Value;

		return true;
	}
コード例 #4
0
ファイル: common.cpp プロジェクト: simonsonc/PDAL
schema::XMLSchema fetchSchema(Statement stmt, BlockPtr block)
{
    // Fetch the XML that defines the schema for this point cloud
    std::ostringstream schemaQuery;
    OCILobLocator* metadata = NULL;
    schemaQuery <<
        "DECLARE" << std::endl << "PC_TABLE VARCHAR2(32) := '" <<
            stmt->GetString(block->pc->base_table) << "';" << std::endl <<
        "PC_ID NUMBER := " << stmt->GetInteger(&(block->pc->pc_id)) <<
            ";" << std::endl <<
        "PC_COLUMN VARCHAR2(32) := '" <<
            stmt->GetString(block->pc->base_column) << "';" << std::endl <<
        "BEGIN" << std::endl <<
        std::endl <<
        "EXECUTE IMMEDIATE" << std::endl <<
        " 'SELECT T.'||PC_COLUMN||'.PC_OTHER_ATTRS.getClobVal()"
            "FROM '||pc_table||' T WHERE T.ID='||"
            "PC_ID INTO :metadata;" << std::endl <<
        "END;" << std::endl;

    Statement getSchemaStmt(
        block->m_connection->CreateStatement(schemaQuery.str().c_str()));
    getSchemaStmt->BindName(":metadata", &metadata);

    getSchemaStmt->Execute();

    char* pc_schema = getSchemaStmt->ReadCLob(metadata);
    std::string pc_schema_xml;
    if (pc_schema)
    {
        pc_schema_xml = pc_schema;
        CPLFree(pc_schema);
    }
    std::ostringstream fname;
    int cloudId = stmt->GetInteger(&(block->pc->pc_id)) ;
//     fname << "schema-" << cloudId <<".xml";
//         std::ostream* out = FileUtils::createFile(fname.str());
//         out->write(pc_schema_xml.c_str(), pc_schema_xml.size());
//         FileUtils::closeFile(out);
    return schema::Reader(pc_schema_xml).schema();
}
コード例 #5
0
pdal::Schema Reader::fetchSchema(Statement statement, sdo_pc* pc, boost::uint32_t& capacity, std::string ns_override) const
{
    log()->get(logDEBUG) << "Fetching schema from SDO_PC object" << std::endl;

    // Fetch the XML that defines the schema for this point cloud
    std::ostringstream select_schema;
    OCILobLocator* metadata = NULL;
    select_schema
            << "DECLARE" << std::endl
            << "PC_TABLE VARCHAR2(32) := '" << statement->GetString(pc->base_table) << "';" << std::endl
            << "PC_ID NUMBER := " << statement->GetInteger(&(pc->pc_id)) << ";" << std::endl
            << "PC_COLUMN VARCHAR2(32) := '" << statement->GetString(pc->base_column) << "';" << std::endl
            << "BEGIN" << std::endl
            << std::endl
            << "EXECUTE IMMEDIATE" << std::endl
            << " 'SELECT T.'||PC_COLUMN||'.PC_OTHER_ATTRS.getClobVal(), T.'||PC_COLUMN||'.PTN_PARAMS FROM '||pc_table||' T WHERE T.ID='||PC_ID INTO :metadata, :capacity;"
            << std::endl
            << "END;"
            << std::endl;
    Statement get_schema(m_connection->CreateStatement(select_schema.str().c_str()));
    get_schema->BindName(":metadata", &metadata);

    int ptn_params_length = 1024;
    char* ptn_params = (char*) malloc(sizeof(char*) * ptn_params_length);
    ptn_params[ptn_params_length-1] = '\0'; //added trailing null to fix ORA-01480
    get_schema->BindName(":capacity", ptn_params, ptn_params_length);
    get_schema->Execute();

    char* pc_schema = get_schema->ReadCLob(metadata);

    std::string write_schema_file = getOptions().getValueOrDefault<std::string>("xml_schema_dump", std::string(""));
    if (write_schema_file.size() > 0)
    {
        std::ostream* out = FileUtils::createFile(write_schema_file);
        out->write(pc_schema, strlen(pc_schema));
        FileUtils::closeFile(out);
    }


    // Fetch the block capacity from the point cloud object so we
    // can use it later.
    // PTN_PARAMS is like:
    // 'blk_capacity=1000,work_tablespace=my_work_ts'
    int block_capacity = 0;
    boost::char_separator<char> sep_space(" ");
    boost::char_separator<char> sep_equal("=");

    std::string s_cap(ptn_params);
    tokenizer parameters(s_cap, sep_space);
    for (tokenizer::iterator t = parameters.begin(); t != parameters.end(); ++t)
    {
        tokenizer parameter((*t), sep_equal);

        for (tokenizer::iterator c = parameter.begin(); c != parameter.end(); ++c)
        {
            if (boost::iequals(c->c_str(), "blk_capacity"))
            {
                tokenizer::iterator d = ++c;
                block_capacity = atoi(d->c_str());
            }
        }
    }

    if (block_capacity < 1)
    {
        std::ostringstream oss;
        oss << "Invalid block capacity for point cloud object in Oracle: " << block_capacity;
        throw pdal_error(oss.str());
    }

    capacity = block_capacity;

    std::string pc_schema_xml(pc_schema);
    if (pc_schema)
        CPLFree(pc_schema);

    if (ptn_params)
        free(ptn_params);

    Schema schema = Schema::from_xml(pc_schema_xml);

    schema::index_by_index const& dims = schema.getDimensions().get<schema::index>();

    for (schema::index_by_index::const_iterator iter = dims.begin(); iter != dims.end(); ++iter)
    {
        // For dimensions that do not have namespaces, we'll set the namespace
        // to the namespace of the current stage

        if (iter->getNamespace().size() == 0)
        {
            log()->get(logDEBUG4) << "setting namespace for dimension " << iter->getName() << " to "  << getName() << std::endl;


            Dimension d(*iter);
            if (iter->getUUID().is_nil())
            {
                d.createUUID();
            }

            if (ns_override.size() > 0)
            {
                d.setNamespace(ns_override);
            }
            else
            {
                d.setNamespace(getName());
            }
            schema.setDimension(d);
        }
    }

    return schema;
}