Beispiel #1
0
void read_db_torrents_sql()
{
	try
	{
		if (!m_config.m_auto_register)
		{
			Csql_result result = Csql_query(m_database, "select info_hash, @fid from @files where flags & 1").execute();
			while (Csql_row row = result.fetch_row())
			{
				m_torrents.erase(to_array<char, 20>(row[0]));
				Csql_query(m_database, "delete from @files where @fid = ?")(row[1]).execute();
			}
		}
		if (m_config.m_auto_register && !m_torrents.empty())
			return;
		Csql_result result = Csql_query(m_database, "select info_hash, @completed, @fid, ctime from @files where @fid >= ?")(m_fid_end).execute();
		// m_torrents.reserve(m_torrents.size() + result.size());
		while (Csql_row row = result.fetch_row())
		{
			m_fid_end = std::max<int>(m_fid_end, row[2].i() + 1);
			if (row[0].size() != 20 || find_torrent(row[0].s()))
				continue;
			t_torrent& file = m_torrents[to_array<char, 20>(row[0])];
			if (file.fid)
				continue;
			file.completed = row[1].i();
			file.dirty = false;
			file.fid = row[2].i();
			file.ctime = row[3].i();
		}
	}
	catch (bad_query&)
	{
	}
}
Beispiel #2
0
inline void operator<< (object::with_zone& o, const boost::unordered_map<K,V>& v)
{
    o.type = type::MAP;
    if(v.empty()) {
        o.via.map.ptr  = NULL;
        o.via.map.size = 0;
    } else {
        object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
        object_kv* const pend = p + v.size();
        o.via.map.ptr  = p;
        o.via.map.size = v.size();
        typename boost::unordered_map<K,V>::const_iterator it(v.begin());
        do {
            p->key = object(it->first, o.zone);
            p->val = object(it->second, o.zone);
            ++p;
            ++it;
        } while(p < pend);
    }
}