예제 #1
0
int InsertUser(Table* table, const char* nick, const char* password, const char* status)
{
	int user_id;
	ByteArray<1024> key;
	ByteArray<1024> value;
	int nread;
	
	// this should be an atomic Incr operation
	table->Get(NULL, "user:id", value);
	user_id = strntol(value.buffer, value.length, &nread);
	user_id++;
	value.Printf("%d", user_id);
	table->Set(NULL, "user:id", value);
	
	key.Printf("user:%d", user_id);
	value.Printf("nick:%s:password:%s:status:%s", nick, password, status);
	table->Set(NULL, key, value);
	
	// nick is indexed, we have to make a reverse reference
	key.Printf("user:nick:%s", nick);
	value.Printf("%d", user_id);
	table->Set(NULL, key, value);

	return user_id;
}
예제 #2
0
void InsertEvent(Table* table, int user_id, const char* name, const char* note, const char* date)
{
	ByteArray<1024> key;
	ByteArray<1024> value;

	key.Printf("event:user:%d:%s", user_id, name);
	value.Printf("date:%s:note:%s", date, note);
	table->Set(NULL, key, value);
}
예제 #3
0
	bool ParseQuery(const char* query)
	{
		const char SELECT[] = "SELECT";
		const char FROM[] = "FROM";
		const char WHERE[] = "WHERE";
		const char* p;
		const char* start;
		int len;
		
		if (strncmp(query, SELECT, sizeof(SELECT) - 1))
			return false;
		
		p = query + sizeof(SELECT) - 1;
		p = SkipWhitespace(p);
		if (!p)
			return false;
		
		p = ParseQueryKeys(p);
		
		if (strncmp(p, FROM, sizeof(FROM) - 1))
			return false;
		p = p + sizeof(FROM) - 1;
		p = SkipWhitespace(p);
		start = p;
		p = SkipKey(start, &len);
		if (!len)
			return false;
		
		keyhint.Printf("%.*s", len, start);

		if (!strncmp(p, WHERE, sizeof(WHERE) - 1))
		{
			p = p + sizeof(WHERE) - 1;
			p = SkipWhitespace(p);
			p = ParseConditions(p);
		}
		
		return true;
	}