package voi.db;
import java.sql.*;
import javax.swing.table.*;
import java.util.*;
import java.lang.*;
import java.lang.String;
import java.lang.Object;
import voi.routines.*;

/**
This class creates a results model which is used to display the mysql results in a tabular format

For this we need the columnnames and rows associated with them
**/
class ResultsModel extends AbstractTableModel
{
	String [] columnNames = new String[0];
	Vector dataRows;

	/** 
	This function is used to add the query results to the JTable that is used to display the results
	**/
	public void setResultSet (ResultSet results, boolean flags[], int DerivedCount)
	{
		
		AssembleQueryResults assembleQuery = new AssembleQueryResults (results, flags);
		columnNames = assembleQuery.getColumnNames ();
		dataRows = assembleQuery.getDataRows ();		
		fireTableChanged (null);
		
		/* end of getRowData Here */
	}
	
	public void setResultSet (ResultSet results)
	{

		AssembleQueryResults assembleQuery = new AssembleQueryResults (results);
		columnNames = assembleQuery.getColumnNames ();
		dataRows = assembleQuery.getDataRows ();
		fireTableChanged (null);
	}
	
	/** get the number of columns required **/
	public int getColumnCount ()
	{ 
		return columnNames.length;
	}
	
	/** get the number of rows required **/
	public int getRowCount ()
	{
		if (dataRows == null)
			return 0;
		else 
			return dataRows.size ();
	}
	
	/** get the value at a particular row and column **/
	public Object getValueAt (int row, int column)
	{
		return ((String [])(dataRows.elementAt (row)))[column];
	} 
	
	/** get the column name of a particular column **/
	public String getColumnName (int column)
	{
		if (columnNames [column] == null)
			return "No Name";
		else	
			return columnNames [column];
	}
}
			
