/**
 * This class stores a database result.
 **/
module.exports = new Class
({
	/**
	 * Initilizes the result object.
	 **/
	initialize: function (result)
	{
		this.data = result.data;
		this.tables = result.tables;
		this.columns = result.columns;
		this.row = -1;
		
		if (this.columns)
		{
			this.columnMap = {};

			for (var i = 0; i < this.columns.length; i++)
				this.columnMap[this.columns[i].name] = i;
		}
		else
			this.columnMap = null;
	}
	
	/**
	 * Gets a value from de result.
	 *
	 * @param {String} columnName The column name
	 * @return {Object} The cell value
	 **/
	,get: function (columnName)
	{
		var columnIndex = this.columnMap[columnName];
		return this.data[this.row][columnIndex];
	}
	
	/**
	 * Resets the result iterator.
	 **/
	,reset: function ()
	{
		this.row = -1;
	}
	
	/**
	 * Moves the internal iterator to the next row.
	 **/
	,next: function ()
	{
		this.row++;
		
		if (this.row >= this.data.length)
			return false;
			
		return true;
	}
});