Ejemplo n.º 1
0
int StructuredDatabaseTest()
{
	Table* table;
	int user_id;
	DynArray<1024> what;
	DynArray<1024> where;

	table = new Table(&database, "structured_test");
	table->Truncate();
	user_id = InsertUser(table, "dopey", "dopeypass", "online");
	InsertEvent(table, user_id, "dinner", "cheezburger", "2009-03-24 01:09:00");
	InsertEvent(table, user_id, "meeting", "important", "2009-03-24 11:12:00");

	// SELECT * FROM event WHERE user=%d AND date > 2009-03-24 01
	what.Printf("event:user:%d", user_id);
	where.Printf("date:2009-03-24 01");
	//TableSelector selector(what.buffer, where.buffer);
//	QuerySelector selector("SELECT date, note FROM event WHERE user_id=%d", user_id);
//	table->Visit(selector);

	ListTableVisitor visitor;
	table->Visit(visitor);
	
	return TEST_SUCCESS;
}
Ejemplo n.º 2
0
int TableVisitorTest()
{
	Table* table;
	ListTableVisitor ltv;
	
	table = database.GetTable("keyspace");
	table->Visit(ltv);
	
	return TEST_SUCCESS;
}
Ejemplo n.º 3
0
int bdbdump(int argc, char* argv[], bool dumpFormat)
{
	char*			slash;
	char*			filename;
	Table*			table;
	TablePrinter	tp(dumpFormat);
	bool			ret;
	DatabaseConfig	dbConfig;

	if (argc < 2)
	{
		printf("usage: bdbdump db-file\n");
		exit(1);
	}
	
	dbConfig.dir = ".";
	filename = argv[1];
	if ((slash = strrchr(filename, '/')) != NULL)
	{
		dbConfig.dir = argv[1];
		*slash = '\0';
		filename = slash + 1;
		if (chdir(dbConfig.dir) < 0)
		{
			printf("cannot find database directory!\n");
			exit(1);
		}
		dbConfig.dir = ".";
	}
	
	ret = database.Init(dbConfig);
	if (!ret)
	{
		printf("cannot initialise database!\n");
		exit(1);
	}
	
	table = new Table(&database, filename);
	table->Visit(tp);
	
	delete table;
	
	return 0;
}
Ejemplo n.º 4
0
int TableSelectorTest()
{
	Table* table;
	// select all user where name starts with 'd'
	TableSelector selector("user", "d");
	
	table = database.GetTable("test");

	// populate table with test data
	table->Set(NULL, "user:1", "dopey");
	table->Set(NULL, "user:2", "grumpy");
	table->Set(NULL, "user:3", "doc");
	table->Set(NULL, "user:4", "happy");
	table->Set(NULL, "user:5", "bashful");
	table->Set(NULL, "user:6", "sneezy");
	table->Set(NULL, "user:7", "sleepy");
	
	table->Visit(selector);
	
	return TEST_SUCCESS;
	
}