/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2005, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.dbc.result;
/** An ISO-9075:2003 (SQL) table. This is equivalent to a relation in the
* relational model. */
abstract class Relation extends Object with Iterable[Tuple] {
/** The statement that generated this relation. */
def statement: scala.dbc.statement.Relation;
/** A JDBC result containing this relation. */
protected def sqlResult: java.sql.ResultSet;
/** A JDBC metadata object attached to the relation. */
protected def sqlMetadata: java.sql.ResultSetMetaData = sqlResult.getMetaData();
/** Metadata about all fields in a tuple of the relation. */
def metadata: List[FieldMetadata] =
for (val count <- List.range(1, sqlMetadata.getColumnCount()+1)) yield
new FieldMetadata {
val name: String = sqlMetadata.getColumnName(count);
val index: Int = count;
val datatype: DataType = dbc.datatype.Factory.create(sqlMetadata,count);
val catalog: String = sqlMetadata.getCatalogName(count);
val schema: String = sqlMetadata.getSchemaName(count);
val table: String = sqlMetadata.getTableName(count);
}
/** Metadata about the field at the given index. If there is no such
* field None
is returned instead. */
def metadataFor (index:Int): Option[FieldMetadata] =
try {Some(metadata(index))} catch {case e => None}
/** Metadata about the field with the given column name. If there is no
* such field, None
is returned instead. */
def metadataFor (name:String): Option[FieldMetadata] =
metadata.find(f=>(f.name==name));
/** An iterator on the tuples of the relation.
*