コード例 #1
0
ファイル: ardb.cpp プロジェクト: kouhate/ardb
	void Ardb::PrintDB(const DBID& db)
	{
		Slice empty;
		KeyObject start(empty, KV, db);
		Iterator* iter = FindValue(start);
		while (NULL != iter && iter->Valid())
		{
			Slice tmpkey = iter->Key();
			KeyObject* kk = decode_key(tmpkey, NULL);
			if (kk->db != db)
			{
				DELETE(kk);
				break;
			}
			ValueObject v;
			Buffer readbuf(const_cast<char*>(iter->Value().data()), 0, iter->Value().size());
			decode_value(readbuf, v, false);
			if (NULL != kk)
			{
				std::string str;
				DEBUG_LOG("[%d]Key=%s, Value=%s", kk->type, kk->key.data(), v.ToString(str).c_str());
			}
			DELETE(kk);
			iter->Next();
		}
		DELETE(iter);
	}
コード例 #2
0
ファイル: sort.cpp プロジェクト: ericcapricorn/ardb
	int Ardb::GetValueByPattern(const DBID& db, const Slice& pattern,
	        ValueObject& subst, ValueObject& value)
	{
		const char *p, *f;
		const char* spat;
		/* If the pattern is "#" return the substitution object itself in order
		 * to implement the "SORT ... GET #" feature. */
		spat = pattern.data();
		if (spat[0] == '#' && spat[1] == '\0')
		{
			value = subst;
			return 0;
		}

		/* If we can't find '*' in the pattern we return NULL as to GET a
		 * fixed key does not make sense. */
		p = strchr(spat, '*');
		if (!p)
		{
			return -1;
		}

		f = strstr(spat, "->");
		if (NULL != f && (uint32)(f - spat) == (pattern.size() - 2))
		{
			f = NULL;
		}
		std::string vstr;
		subst.ToString(vstr);
		std::string keystr(pattern.data(), pattern.size());
		string_replace(keystr, "*", vstr);
		if (f == NULL)
		{
			KeyObject k(keystr, KV, db);
			return GetValue(k, &value);
		}
		else
		{
			size_t pos = keystr.find("->");
			std::string field = keystr.substr(pos + 2);
			keystr = keystr.substr(0, pos);
			HashKeyObject hk(keystr, field, db);
			return GetValue(hk, &value);
		}
	}