summaryrefslogtreecommitdiff
path: root/src/library/scala/dbc/result/Tuple.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/scala/dbc/result/Tuple.scala')
-rw-r--r--src/library/scala/dbc/result/Tuple.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/library/scala/dbc/result/Tuple.scala b/src/library/scala/dbc/result/Tuple.scala
new file mode 100644
index 0000000000..41c2f1f6d1
--- /dev/null
+++ b/src/library/scala/dbc/result/Tuple.scala
@@ -0,0 +1,38 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2005, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.dbc.result;
+
+/** An ISO-9075:2003 (SQL) table row. This is equivalent to a tuple in the relational model. */
+abstract class Tuple {
+
+ /** All the fields contained in the tuple. */
+ def fields: List[Field];
+
+ /** The relation that contains the tuple. */
+ def originatingRelation: Relation;
+
+ /** The field at the given index. If there is no such field (that is the index is out of bounds), <code>None</code> is returned instead. */
+ def apply (index:Int): Field =
+ try {
+ fields(index)
+ } catch {
+ case e =>
+ throw new java.lang.IndexOutOfBoundsException("Field at index "+index+" does not exist in relation");
+ }
+
+ /** The field with the given column name. If there is no such field, <code>None</code> is returned instead. */
+ def apply (name:String): Field = {
+ def findField (fields: List[Field], name:String): Field = fields match {
+ case Nil => throw new java.lang.IndexOutOfBoundsException("Field '"+name+"' does not exist in relation")
+ case field :: _ if (field.metadata.name == name) => field
+ case field :: fields => findField (fields, name)
+ }
+ findField (fields, name);
+ }
+}