Exemple #1
0
TEST(mapcat, mapcat)
{
  auto v = std::vector<std::vector<int>> { { 1, 2 }, { 3 }, { 4, 5, 6 } };

  auto res = into(std::vector<int> {}, mapcat([](int x) { return x * 2; }), v);
  EXPECT_EQ(res, (std::vector<int> { 2, 4, 6, 8, 10, 12 }));
}
Exemple #2
0
const std::pair<bool, std::string> Item::drop(const std::vector<std::string>& arguments, Entity* item) {
	//drop X in/into/... Y
	//drop X Y
	unsigned int size = arguments.size();
	if (size > 2) {
		//get the name
		std::string into((size > 3) ? arguments[3] : arguments[2]);

		if (Utilities::compareTo(this->name, into)) {
			//its me
			return storeItem(item);
		} else {
			//it's not me, get the item into store if opened
			if (opened) {
				Entity* itemInto = getEntity(into);
				if (itemInto != nullptr) {
					return itemInto->drop(arguments, item);
				}
			}
			//I ask because if is not opened, don't know why I'm asking this item so probably is a mistake due to a misunderstanding and not because the item is closed
			std::pair<bool, std::string> result;
			result.first = false;
			result.second = "Drop where?";
			return result;
		}

	} else if (!opened) {
		std::pair<bool, std::string> result;
		result.first = false;
		result.second = "Can't drop here, is closed";
		return result;
	} else {
		return storeItem(item);
	}
}
vector<ClassificationObjectPtr>
DatabaseSubsystem::getClassificationObjectsByFilename(const string& filename)
{
    // FIXME: This is erroneous if files with the same name exist in 
    // different dirs. But we don't want the user to mess with
    // full path names. Suggestions?

    RWLock::ScopedLock lock(_dbLock);

    vector<ClassificationObjectPtr> result;
    Session session = getSession();
    session.begin();
    session << "SELECT cof.object_id, co.type "
            << "FROM classification_object_file cof "
            << "JOIN classification_object co USING (object_id) "
            << "WHERE (cof.input_file LIKE ?) "
            << "OR (cof.input_file LIKE '%/' || ?) "
            << "OR (cof.input_file LIKE '%\\' || ?)",
            use(filename),
            use(filename),
            use(filename),
            into(result),
            now;
    for (vector<ClassificationObjectPtr>::iterator it = result.begin();
        it != result.end(); ++it)
    {
        getClassificationObjectDescrIDs(session, *it);
        getClassificationObjectLabelIDs(session, *it);
    }
    session.commit();
    return result;
}
Exemple #4
0
void object::test<5>()
{
	int id = 1;
	int MAX_RECORD = 100;

	st << utf("insert into some_table(id) values(:id)"), use(id);
	ensure("no row", !se.last_exec());
	
	se << utf(L"begin");
	for (; id <= MAX_RECORD; ++id)
	{
		st.reset(true);
		st.exec();
		ensure("row", !se.last_exec());
	}
	se << utf(L"commit");

	int id2;
	st << utf(L"select id from some_table"), into(id2);

	for (id = 1; st.exec(); ++id)
	{
		ensure("row", se.last_exec());
		ensure_equals("id", id2, id);
	}
	ensure_equals("MAX_RECORD", id - 1, MAX_RECORD);
	ensure_equals("MAX_RECORD", id2, MAX_RECORD);
}
Exemple #5
0
uint64_t
OfferFrame::countObjects(soci::session& sess)
{
    uint64_t count = 0;
    sess << "SELECT COUNT(*) FROM offers;", into(count);
    return count;
}
void DatabaseSubsystem::getClassificationObjectDescrIDs(Session& session,
    ClassificationObjectPtr& clObj)
{
    session << "SELECT descr_id FROM classification_object_data "
               "WHERE object_id = ?",
               use(clObj->objectID),
               into(clObj->descrIDs),
               now;
}
void DatabaseSubsystem::getClassificationObjectLabelIDs(Session& session,
    ClassificationObjectPtr& clObj)
{
    session << "SELECT label_id FROM classification_object_label "
               "WHERE object_id = ?",
               use(clObj->objectID),
               into(clObj->labelIDs),
               now;
}
vector<LabelPtr> DatabaseSubsystem::getLabels()
{
    RWLock::ScopedLock lock(_dbLock);

    vector<LabelPtr> result;
    Session session = getSession();
    session << "SELECT * FROM label", into(result), now;
    return result;
}
void object::test<1>()
{
	int rows;
	ensure( "no active txn", !se.active_txn() );
	{
		transaction t(se);
		ensure_equals( "this active txn", se.active_txn(), &t );
		
		record r1(1, utf(L"Dima"), 566.24);
		r1.insert(se);

		se << utf(L"select count(*) from some_table"), into(rows);
		ensure_equals("row inserted", rows, 1);
	}	
	ensure( "no active txn", !se.active_txn() );
	se << utf(L"select count(*) from some_table"), into(rows);
	ensure_equals("rollback", rows, 0);
}
Exemple #10
0
TEST(partition, reduce_nested_deals_with_empty_sequence_properly)
{
    auto v = std::vector<std::vector<int> > {{{}, {1, 2, 3}, {}}};
    auto res = into(
                   std::vector<std::vector<int>> {},
                   comp(cat, transducer<int, std::vector<int>> {partition(2u)}),
                   v);
    EXPECT_EQ(res, (std::vector<std::vector<int> > {{1, 2}, {3}}));
}
Exemple #11
0
TEST(partition, defining_early_termination_with_completion)
{
    auto v = std::vector<int> {{1, 2, 3, 4, 5}};
    auto res = into(
                   std::vector<std::vector<int>> {},
                   comp(take(3), partition(2u)),
                   v);
    EXPECT_EQ(res, (std::vector<std::vector<int> > {{1, 2}, {3}}));
}
Exemple #12
0
TEST(partition, partition_flushing)
{
    auto v = std::vector<int> { 1, 2, 3, 4, 5 };

    auto res = into(std::vector<std::vector<int> > {}, partition(2u), v);
    EXPECT_EQ(res, (std::vector<std::vector<int> > {
        {1, 2}, {3, 4}, {5}
    }));
}
vector<LabelPtr> DatabaseSubsystem::getLabelsByText(const string& text)
{
    RWLock::ScopedLock lock(_dbLock);

    vector<LabelPtr> result;
    Session session = getSession();
    session << "SELECT * FROM label WHERE label_text = ?", 
               use(text), into(result), now;
    return result;
}
Exemple #14
0
void main_into()
{
	enable(TRUE, GAD_PAUSE_BUTTON, TAG_END);
	enable(FALSE, GAD_STEPOVER_BUTTON, GAD_STEPINTO_BUTTON, GAD_STEPOUT_BUTTON, TAG_END);
	
	if (1) //hasfunctioncontext)
	{
		into();
	}
}
Exemple #15
0
TEST(eager, reversed)
{
  auto v = std::vector<int> { 1, 2, 3, 6, 12 };
  auto times2 = [](int x) { return x * 2; };
  auto div3 = [](int x) { return x % 3 == 0; };

  auto r = into(std::vector<int>{},
                comp(map(times2), reversed, filter(div3)), v);
  EXPECT_EQ(r, (decltype (r) { 24, 12, 6 }));
}
void DatabaseSubsystem::getAvailableFeatures(Session& session,
    const map<int, int>& clObjMap, FeatureSet& featureSet)
{
    int ddType;
    string featureName;
    double featureParam1, featureParam2, featureParam3;

    featureSet.clear();

    ostringstream clObjIDs;
    for (map<int, int>::const_iterator itr = clObjMap.begin();
         itr != clObjMap.end(); ++itr)
    {
        if (itr != clObjMap.begin()) {
            clObjIDs << ",";
        }
        clObjIDs << itr->first;
    }

    Statement stmt = (session <<
        "SELECT DISTINCT "
        "  data_descriptor.type, data_feature.feature_name, "
        "  data_feature.feature_param1, data_feature.feature_param2, "
        "  data_feature.feature_param3  "
        "FROM data_feature INNER JOIN data_descriptor "
        "ON (data_feature.descr_id = data_descriptor.descr_id) "
        "WHERE data_descriptor.descr_id IN ("
        "  SELECT descr_id FROM classification_object_data WHERE object_id IN ("
        << clObjIDs.str()
        << "))",
        range(0, 1),
        into(ddType), into(featureName), into(featureParam1), 
        into(featureParam2), into(featureParam3));

    while (!stmt.done()) {
        if (stmt.execute() == 1) {
            featureSet.add(FeatureDescriptor(featureName,
                (DataDescriptor::Type) ddType, featureParam1, featureParam2, 
                featureParam3));
        }
    }
}
vector<DataDescriptorPtr> DatabaseSubsystem::getDataDescriptors(int processID)
{
    RWLock::ScopedLock lock(_dbLock);

    vector<DataDescriptorPtr> result;
    getSession() <<
        "SELECT * FROM data_descriptor WHERE process_id = ? ",
        use(processID), into(result),
        now;
    return result;
}
bool
OfferFrame::exists(Database& db, LedgerKey const& key)
{
    std::string actIDStrKey = PubKeyUtils::toStrKey(key.offer().sellerID);
    int exists = 0;
    auto timer = db.getSelectTimer("offer-exists");
    db.getSession() << "SELECT EXISTS (SELECT NULL FROM offers "
                       "WHERE sellerid=:id AND offerid=:s)",
        use(actIDStrKey), use(key.offer().offerID), into(exists);
    return exists != 0;
}
vector<LabelPtr> DatabaseSubsystem::getLabelsForResponse(blissart::ResponsePtr r)
{
    RWLock::ScopedLock lock(_dbLock);

    vector<LabelPtr> result;
    Session session = getSession();
    session << "SELECT * FROM label WHERE label_id "
               "IN (SELECT label_id FROM response_label WHERE response_id = ?)",
               use(r->responseID), into(result), now;
    return result;
}
Exemple #20
0
TEST(eager, sorted)
{
  auto v = std::vector<int> { 6, 2, 1, 12, 3 };
  auto times2 = [](int x) { return x * 2; };
  auto div3 = [](int x) { return x % 3 == 0; };

  // Does not use `into_vector` because travis uses an outdated
  // version of GCC in which that triggers a link-time bug
  auto r = into(std::vector<int>{},
                comp(map(times2), sorted, filter(div3)), v);
  EXPECT_EQ(r, (decltype (r) { 6, 12, 24 }));
}
ProcessPtr DatabaseSubsystem::getProcess(int processID)
{
    RWLock::ScopedLock lock(_dbLock);

    ProcessPtr result;
    Session session = getSession();
    session << "SELECT * FROM process WHERE process_id = ?",
               use(processID), into(result), now;
    if (!result.isNull())
        getProcessParams(session, result);
    return result;
}
vector<FeaturePtr> DatabaseSubsystem::getFeatures(int descrID)
{
    RWLock::ScopedLock lock(_dbLock);

    vector<FeaturePtr> result;
    getSession() <<
        "SELECT * FROM data_feature WHERE descr_id = ?",
        use(descrID),
        into(result),
        now;
    return result;
}
DataDescriptorPtr DatabaseSubsystem::getDataDescriptor(int descrID)
{
    RWLock::ScopedLock lock(_dbLock);

    DataDescriptorPtr result;
    Session session = getSession();
    session <<
        "SELECT * FROM data_descriptor WHERE descr_id = ?",
        use(descrID), into(result),
        now;
    return result;
}
	std::string Databases::Create(std::string origin, std::string name)
	{
		if (Exists(origin, name))
		{
			return Path(origin,name);
		}
		static Logger* logger = Logger::Get("Database.Databases");

		Statement select(this->session->GetSession());
		Poco::UInt32 seq = 0;
		select << "SELECT seq FROM sqlite_sequence WHERE name='Databases'", into(seq);
		select.execute();

		++seq;

		std::string filename = Poco::format("%016u.db",(unsigned int)seq);
		logger->Debug("creating new db: %s",filename.c_str());

		Statement select2(this->session->GetSession());
		select2 << "INSERT INTO Databases (origin, name, path) VALUES (:origin,:name,:path)", use(origin), use(name), use(filename);
		select2.execute();

		Statement select5(this->session->GetSession());
		select5 << "SELECT origin from Origins where origin = :origin", use(origin);
		Poco::Int32 count = select5.execute();
		if (count == 0)
		{
			Statement select(this->session->GetSession());
			select << "INSERT INTO Origins (origin,quota) values (:origin,1720462881547374560)", use(origin), now;
		}

		// create the DB file
		std::string dbdir = FileUtils::Join(datadir.c_str(),origin.c_str(),NULL);
		if (!FileUtils::IsDirectory(dbdir))
		{
			logger->Debug("creating new db dir: %s",dbdir.c_str());
			FileUtils::CreateDirectory(dbdir);
		}
		std::string fullpath = FileUtils::Join(dbdir.c_str(),filename.c_str(),NULL);
		logger->Debug("path to new db : %s",fullpath.c_str());

		DBSession s(fullpath);

		// create the metadata table for WebKit
		Statement select3(s.GetSession());
		select3 << "CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL)", now;

		Statement select4(s.GetSession());
		select4 << "insert into __WebKitDatabaseInfoTable__ values ('WebKitDatabaseVersionKey','1.0')", now;

		return fullpath;
	}
MailUserFilterPtr MailUserFilterRepository::select(const MailUserFilter& obj)
{
	soci::row row;
	MailUserFilterPtr mailuserfilter(new MailUserFilter);
	dataBase << "SELECT  mail_user_filter.filter_id as MailUserFilter_filter_id, mail_user_filter.sys_userid as MailUserFilter_sys_userid, mail_user_filter.sys_groupid as MailUserFilter_sys_groupid, mail_user_filter.sys_perm_user as MailUserFilter_sys_perm_user, mail_user_filter.sys_perm_group as MailUserFilter_sys_perm_group, mail_user_filter.sys_perm_other as MailUserFilter_sys_perm_other, mail_user_filter.mailuser_id as MailUserFilter_mailuser_id, mail_user_filter.rulename as MailUserFilter_rulename, mail_user_filter.source as MailUserFilter_source, mail_user_filter.searchterm as MailUserFilter_searchterm, mail_user_filter.op as MailUserFilter_op, mail_user_filter.action as MailUserFilter_action, mail_user_filter.target as MailUserFilter_target, mail_user_filter.active as MailUserFilter_active"
	" FROM mail_user_filter "
	"WHERE mail_user_filter.filter_id = :MailUserFilter_filter_id", into(row), use(obj);
	if(!dataBase.got_data())
		mailuserfilter.reset();
	else
		type_conversion<MailUserFilter>::from_base(row, i_ok, *mailuserfilter);
	return mailuserfilter;
}
MailboxPtr MailboxRepository::select(const Mailbox& obj)
{
	soci::row row;
	MailboxPtr mailbox(new Mailbox);
	dataBase << "SELECT  mailbox.username as Mailbox_username, mailbox.password as Mailbox_password, mailbox.name as Mailbox_name, mailbox.home as Mailbox_home, mailbox.maildir as Mailbox_maildir, mailbox.quota as Mailbox_quota, mailbox.domain as Mailbox_domain, mailbox.create_date as Mailbox_create_date, mailbox.change_date as Mailbox_change_date, mailbox.active as Mailbox_active, mailbox.passwd_expire as Mailbox_passwd_expire, mailbox.uid as Mailbox_uid, mailbox.gid as Mailbox_gid, mailbox.id_mentor as Mailbox_id_mentor, mailbox.tipo_conta as Mailbox_tipo_conta, mailbox.assina as Mailbox_assina, mailbox.matricula as Mailbox_matricula"
	" FROM mailbox "
	"WHERE mailbox.username = :Mailbox_username", into(row), use(obj);
	if(!dataBase.got_data())
		mailbox.reset();
	else
		type_conversion<Mailbox>::from_base(row, i_ok, *mailbox);
	return mailbox;
}
vector<ProcessPtr> DatabaseSubsystem::getProcesses()
{
    RWLock::ScopedLock lock(_dbLock);

    vector<ProcessPtr> result;
    Session session = getSession();
    session << "SELECT * FROM process", into(result), now;
    for (vector<ProcessPtr>::const_iterator it = result.begin();
        it != result.end(); it++) {
        getProcessParams(session, *it);
    }
    return result;
}
ServerPtr ServerRepository::select(const Server& obj)
{
	soci::row row;
	ServerPtr server(new Server);
	dataBase << "SELECT  server.server_id as Server_server_id, server.sys_userid as Server_sys_userid, server.sys_groupid as Server_sys_groupid, server.sys_perm_user as Server_sys_perm_user, server.sys_perm_group as Server_sys_perm_group, server.sys_perm_other as Server_sys_perm_other, server.server_name as Server_server_name, server.mail_server as Server_mail_server, server.web_server as Server_web_server, server.dns_server as Server_dns_server, server.file_server as Server_file_server, server.db_server as Server_db_server, server.vserver_server as Server_vserver_server, server.proxy_server as Server_proxy_server, server.firewall_server as Server_firewall_server, server.config as Server_config, server.updated as Server_updated, server.mirror_server_id as Server_mirror_server_id, server.dbversion as Server_dbversion, server.active as Server_active"
	" FROM server "
	"WHERE server.server_id = :Server_server_id", into(row), use(obj);
	if(!dataBase.got_data())
		server.reset();
	else
		type_conversion<Server>::from_base(row, i_ok, *server);
	return server;
}
ApsInstancesPtr ApsInstancesRepository::select(const ApsInstances& obj)
{
	soci::row row;
	ApsInstancesPtr apsinstances(new ApsInstances);
	dataBase << "SELECT  aps_instances.id as ApsInstances_id, aps_instances.sys_userid as ApsInstances_sys_userid, aps_instances.sys_groupid as ApsInstances_sys_groupid, aps_instances.sys_perm_user as ApsInstances_sys_perm_user, aps_instances.sys_perm_group as ApsInstances_sys_perm_group, aps_instances.sys_perm_other as ApsInstances_sys_perm_other, aps_instances.server_id as ApsInstances_server_id, aps_instances.customer_id as ApsInstances_customer_id, aps_instances.package_id as ApsInstances_package_id, aps_instances.instance_status as ApsInstances_instance_status"
	" FROM aps_instances "
	"WHERE aps_instances.id = :ApsInstances_id", into(row), use(obj);
	if(!dataBase.got_data())
		apsinstances.reset();
	else
		type_conversion<ApsInstances>::from_base(row, i_ok, *apsinstances);
	return apsinstances;
}
vector<DataDescriptorPtr> 
DatabaseSubsystem::getDataDescriptors(ClassificationObjectPtr clo)
{
    RWLock::ScopedLock lock(_dbLock);

    vector<DataDescriptorPtr> result;
    getSession() <<
        "SELECT * FROM data_descriptor WHERE descr_id "
        "IN (SELECT descr_id FROM classification_object_data WHERE object_id = ?)",
        use(clo->objectID), into(result),
        now;
    return result;
}