Removed all tabs in DBC library source.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@7000 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
593e59aa86
commit
69e0a1d3ab
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Database.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc;
|
||||
|
@ -15,9 +15,8 @@ package scala.dbc;
|
|||
import java.sql._;
|
||||
|
||||
/** A link to a database. The <code>Database</code> abstract class must
|
||||
* be specialised for every different DBMS.
|
||||
* @author Gilles Dubochet
|
||||
**/
|
||||
* be specialised for every different DBMS.
|
||||
* @author Gilles Dubochet **/
|
||||
case class Database(dbms: Vendor) {
|
||||
|
||||
class Closed extends Exception {}
|
||||
|
@ -61,7 +60,7 @@ case class Database(dbms: Vendor) {
|
|||
usedConnections = connection :: usedConnections;
|
||||
lock.release;
|
||||
connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,13 +114,11 @@ case class Database(dbms: Vendor) {
|
|||
val sqlResult = connection.createStatement().executeQuery(statement.sqlString);
|
||||
closeConnection(connection);
|
||||
statement.typeCheck(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Executes a statement that updates the state of the database.
|
||||
*
|
||||
* @param statusStatement The statement to execute.
|
||||
* @return The status of the database after the statement has been executed.
|
||||
*/
|
||||
* @param statusStatement The statement to execute.
|
||||
* @return The status of the database after the statement has been executed. */
|
||||
def executeStatement(statusStatement: statement.Status): result.Status[Unit] =
|
||||
executeStatement(statusStatement, false);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Boolean.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.datatype;
|
||||
|
@ -14,18 +14,18 @@ package scala.dbc.datatype;
|
|||
|
||||
/** The SQL type for a truth value. */
|
||||
class Boolean extends DataType {
|
||||
|
||||
def isEquivalent (datatype:DataType) = datatype match {
|
||||
case dt:Boolean => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def isSubtypeOf (datatype:DataType) = isEquivalent(datatype);
|
||||
|
||||
type NativeType = scala.Boolean;
|
||||
val nativeTypeId = DataType.BOOLEAN;
|
||||
|
||||
/** A SQL-99 compliant string representation of the type. */
|
||||
override def sqlString: java.lang.String = "BOOLEAN";
|
||||
|
||||
|
||||
def isEquivalent (datatype:DataType) = datatype match {
|
||||
case dt:Boolean => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def isSubtypeOf (datatype:DataType) = isEquivalent(datatype);
|
||||
|
||||
type NativeType = scala.Boolean;
|
||||
val nativeTypeId = DataType.BOOLEAN;
|
||||
|
||||
/** A SQL-99 compliant string representation of the type. */
|
||||
override def sqlString: java.lang.String = "BOOLEAN";
|
||||
|
||||
}
|
||||
|
|
|
@ -6,26 +6,26 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:CharacterLargeObject.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.datatype;
|
||||
|
||||
|
||||
/** A SQL type for an unbounded length string of characters with arbitrary
|
||||
* character set. */
|
||||
* character set. */
|
||||
class CharacterLargeObject extends CharacterString {
|
||||
|
||||
def isEquivalent (datatype:DataType) = datatype match {
|
||||
case dt:CharacterLargeObject => {
|
||||
encoding == dt.encoding
|
||||
}
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def isSubtypeOf (datatype:DataType) = isEquivalent(datatype);
|
||||
|
||||
/** A SQL-99 compliant string representation of the type. */
|
||||
override def sqlString: java.lang.String = "CHARACTER LARGE OBJECT";
|
||||
|
||||
|
||||
def isEquivalent (datatype:DataType) = datatype match {
|
||||
case dt:CharacterLargeObject => {
|
||||
encoding == dt.encoding
|
||||
}
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def isSubtypeOf (datatype:DataType) = isEquivalent(datatype);
|
||||
|
||||
/** A SQL-99 compliant string representation of the type. */
|
||||
override def sqlString: java.lang.String = "CHARACTER LARGE OBJECT";
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:CharacterString.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.datatype;
|
||||
|
@ -14,11 +14,11 @@ package scala.dbc.datatype;
|
|||
|
||||
/** A type category for all SQL types that store strings of characters. */
|
||||
abstract class CharacterString extends String {
|
||||
|
||||
|
||||
type NativeType = java.lang.String;
|
||||
val nativeTypeId = DataType.STRING;
|
||||
|
||||
/** The name of the character set in which the string is encoded. */
|
||||
def encoding: Option[java.lang.String] = None;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Factory.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.datatype;
|
||||
|
@ -65,184 +65,184 @@ object Factory {
|
|||
metadata.getColumnType(index) match {
|
||||
/* Boolean data types. */
|
||||
case BOOLEAN => new datatype.Boolean {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
case BIT => new datatype.Boolean {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
/* Fixed precision numeric data types. */
|
||||
case DECIMAL => {
|
||||
Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
}
|
||||
Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
case NUMERIC => {
|
||||
Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
}
|
||||
Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 10;
|
||||
val precision = metadata.getPrecision(index);
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = metadata.getScale(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Fixed precision integer data types. */
|
||||
case BIGINT =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
case INTEGER =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 32;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 32;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
case SMALLINT =>
|
||||
new datatype.ExactNumeric[Short](DataType.SHORT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 16;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
new datatype.ExactNumeric[Short](DataType.SHORT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 16;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
case TINYINT =>
|
||||
new datatype.ExactNumeric[Byte](DataType.BYTE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 8;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
new datatype.ExactNumeric[Byte](DataType.BYTE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 8;
|
||||
val signed = metadata.isSigned(index);
|
||||
val scale = 0;
|
||||
}
|
||||
/* Floating point numeric data types. */
|
||||
case REAL =>
|
||||
new datatype.ApproximateNumeric[Float](DataType.FLOAT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
new datatype.ApproximateNumeric[Float](DataType.FLOAT) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
case DOUBLE =>
|
||||
new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
case FLOAT =>
|
||||
new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = metadata.isSigned(index);
|
||||
}
|
||||
/* Character string data types. */
|
||||
case CHAR => new datatype.Character {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val length = metadata.getColumnDisplaySize(index);
|
||||
override val nullable = isNullable(metadata,index);
|
||||
val length = metadata.getColumnDisplaySize(index);
|
||||
}
|
||||
case CLOB => new datatype.CharacterLargeObject {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
case LONGVARCHAR => {
|
||||
if (metadata.getColumnDisplaySize(index) >= 0)
|
||||
new datatype.CharacterVarying {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
def length = metadata.getColumnDisplaySize(index);
|
||||
}
|
||||
else // A PostgreSQL Hack
|
||||
new datatype.CharacterLargeObject {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
if (metadata.getColumnDisplaySize(index) >= 0)
|
||||
new datatype.CharacterVarying {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
def length = metadata.getColumnDisplaySize(index);
|
||||
}
|
||||
else // A PostgreSQL Hack
|
||||
new datatype.CharacterLargeObject {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
}
|
||||
case VARCHAR => {
|
||||
if (metadata.getColumnDisplaySize(index) >= 0)
|
||||
new datatype.CharacterVarying {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
def length = metadata.getColumnDisplaySize(index);
|
||||
}
|
||||
else // A PostgreSQL Hack
|
||||
new datatype.CharacterLargeObject {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
if (metadata.getColumnDisplaySize(index) >= 0)
|
||||
new datatype.CharacterVarying {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
def length = metadata.getColumnDisplaySize(index);
|
||||
}
|
||||
else // A PostgreSQL Hack
|
||||
new datatype.CharacterLargeObject {
|
||||
override val nullable = isNullable(metadata,index);
|
||||
}
|
||||
}
|
||||
/* Undefined cases. */
|
||||
case OTHER => new datatype.Unknown {
|
||||
override val nullable = isNullable(metadata, index);
|
||||
override val nullable = isNullable(metadata, index);
|
||||
}
|
||||
/* Unsupported data types. */
|
||||
case REF | ARRAY | STRUCT =>
|
||||
error ("I don't support composite data types yet.");
|
||||
error ("I don't support composite data types yet.");
|
||||
case DATALINK | DISTINCT | JAVA_OBJECT | NULL =>
|
||||
error ("I won't support strange data types.");
|
||||
error ("I won't support strange data types.");
|
||||
/* Unsupported binary string data types. */
|
||||
case BINARY | BLOB | LONGVARBINARY | VARBINARY =>
|
||||
error ("I don't support binary string data types yet.");
|
||||
error ("I don't support binary string data types yet.");
|
||||
/* Unsupported date and time data types. */
|
||||
case DATE | TIME | TIMESTAMP =>
|
||||
error ("I don't support date and time data types yet.");
|
||||
error ("I don't support date and time data types yet.");
|
||||
/* Default case */
|
||||
case x => error ("I don't know about this ("+metadata.getColumnTypeName(index)+") JDBC type.")
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:IncompatibleSchema.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.exception;
|
||||
|
@ -14,6 +14,6 @@ package scala.dbc.exception;
|
|||
|
||||
/** A type category for all SQL types that store constant-precision numbers. */
|
||||
case class IncompatibleSchema (
|
||||
expectedSchema: List[DataType],
|
||||
foundSchema: List[DataType]
|
||||
expectedSchema: List[DataType],
|
||||
foundSchema: List[DataType]
|
||||
) extends Exception;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Field.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.result;
|
||||
|
@ -24,28 +24,28 @@ abstract class Field {
|
|||
def content: Value;
|
||||
|
||||
final def value[Type <: Value]: Type =
|
||||
content.asInstanceOf[Type];
|
||||
content.asInstanceOf[Type];
|
||||
|
||||
final def exactNumericValue[NativeType] =
|
||||
content.asInstanceOf[dbc.value.ExactNumeric[NativeType]];
|
||||
content.asInstanceOf[dbc.value.ExactNumeric[NativeType]];
|
||||
|
||||
final def approximateNumericValue[NativeType] =
|
||||
content.asInstanceOf[dbc.value.ApproximateNumeric[NativeType]];
|
||||
|
||||
content.asInstanceOf[dbc.value.ApproximateNumeric[NativeType]];
|
||||
|
||||
final def booleanValue =
|
||||
content.asInstanceOf[dbc.value.Boolean];
|
||||
|
||||
content.asInstanceOf[dbc.value.Boolean];
|
||||
|
||||
final def characterValue =
|
||||
content.asInstanceOf[dbc.value.Character];
|
||||
|
||||
content.asInstanceOf[dbc.value.Character];
|
||||
|
||||
final def characterLargeObjectValue =
|
||||
content.asInstanceOf[dbc.value.CharacterLargeObject];
|
||||
|
||||
content.asInstanceOf[dbc.value.CharacterLargeObject];
|
||||
|
||||
final def characterVaryingValue =
|
||||
content.asInstanceOf[dbc.value.CharacterVarying];
|
||||
|
||||
content.asInstanceOf[dbc.value.CharacterVarying];
|
||||
|
||||
final def unknownValue =
|
||||
content.asInstanceOf[dbc.value.Unknown];
|
||||
content.asInstanceOf[dbc.value.Unknown];
|
||||
|
||||
/** The tuple that contains this field. */
|
||||
def originatingTuple: Tuple;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:FieldMetadata.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.result;
|
||||
|
@ -14,23 +14,23 @@ package scala.dbc.result;
|
|||
|
||||
/** Informations attached to a field about its content and its relationship to the originating database. */
|
||||
abstract class FieldMetadata {
|
||||
|
||||
/** The name of the field. */
|
||||
def name: String;
|
||||
|
||||
/** The index of the field in the tuple. */
|
||||
def index: Int;
|
||||
|
||||
/** The expected type of the field. This information is used for automatic transformation of the field value into a usable type. */
|
||||
def datatype: DataType;
|
||||
|
||||
/** The name of the catalog in the database from which the field originates */
|
||||
def catalog: String;
|
||||
|
||||
/** The name of the schema in the database from which the field originates */
|
||||
def schema: String;
|
||||
|
||||
/** The name of the table in the database from which the field originates */
|
||||
def table: String;
|
||||
|
||||
/** The name of the field. */
|
||||
def name: String;
|
||||
|
||||
/** The index of the field in the tuple. */
|
||||
def index: Int;
|
||||
|
||||
/** The expected type of the field. This information is used for automatic transformation of the field value into a usable type. */
|
||||
def datatype: DataType;
|
||||
|
||||
/** The name of the catalog in the database from which the field originates */
|
||||
def catalog: String;
|
||||
|
||||
/** The name of the schema in the database from which the field originates */
|
||||
def schema: String;
|
||||
|
||||
/** The name of the table in the database from which the field originates */
|
||||
def table: String;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Relation.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.result;
|
||||
|
@ -29,12 +29,12 @@ abstract class Relation extends Object with Iterable[Tuple] {
|
|||
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);
|
||||
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
|
||||
|
@ -56,16 +56,16 @@ abstract class Relation extends Object with Iterable[Tuple] {
|
|||
def hasNext: Boolean = !(result.isLast());
|
||||
def next: Tuple = {
|
||||
if (result.next()) {
|
||||
new Tuple {
|
||||
val me = this;
|
||||
val originatingRelation = Relation.this;
|
||||
val fields: List[Field] = for (val fieldMetadata <- metadata) yield
|
||||
new Field {
|
||||
val metadata = fieldMetadata;
|
||||
val content = dbc.value.Factory.create(result,metadata.index,metadata.datatype);
|
||||
val originatingTuple = me;
|
||||
}
|
||||
}
|
||||
new Tuple {
|
||||
val me = this;
|
||||
val originatingRelation = Relation.this;
|
||||
val fields: List[Field] = for (val fieldMetadata <- metadata) yield
|
||||
new Field {
|
||||
val metadata = fieldMetadata;
|
||||
val content = dbc.value.Factory.create(result,metadata.index,metadata.datatype);
|
||||
val originatingTuple = me;
|
||||
}
|
||||
}
|
||||
} else error("next on empty iterator")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Status.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.result;
|
||||
|
@ -16,13 +16,13 @@ import scala.dbc.datatype._;
|
|||
|
||||
/** An object containing the status of a query */
|
||||
abstract class Status[ResultType] {
|
||||
|
||||
/** The statement that generated this status result. */
|
||||
def statement: scala.dbc.statement.Statement;
|
||||
|
||||
/** The number of elements modified or added by this statement. */
|
||||
def touchedCount: Option[Int];
|
||||
|
||||
def result: ResultType;
|
||||
|
||||
|
||||
/** The statement that generated this status result. */
|
||||
def statement: scala.dbc.statement.Statement;
|
||||
|
||||
/** The number of elements modified or added by this statement. */
|
||||
def touchedCount: Option[Int];
|
||||
|
||||
def result: ResultType;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Tuple.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.result;
|
||||
|
@ -24,10 +24,10 @@ abstract class Tuple {
|
|||
/** 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)
|
||||
fields(index)
|
||||
} catch {
|
||||
case e =>
|
||||
throw new java.lang.IndexOutOfBoundsException("Field at index "+index+" does not exist in relation");
|
||||
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. */
|
||||
|
|
|
@ -6,21 +6,21 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:AccessMode.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
||||
|
||||
abstract class AccessMode {
|
||||
def sqlString: String;
|
||||
def sqlString: String;
|
||||
}
|
||||
|
||||
object AccessMode {
|
||||
case object ReadOnly extends AccessMode {
|
||||
def sqlString = "READ ONLY";
|
||||
}
|
||||
case object ReadWrite extends AccessMode {
|
||||
def sqlString = "READ WRITE"
|
||||
}
|
||||
case object ReadOnly extends AccessMode {
|
||||
def sqlString = "READ ONLY";
|
||||
}
|
||||
case object ReadWrite extends AccessMode {
|
||||
def sqlString = "READ WRITE"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Insert.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -16,21 +16,21 @@ import scala.dbc.statement.expression._;
|
|||
|
||||
/** An insertion of values into a table. */
|
||||
case class Insert (
|
||||
insertionTarget: String,
|
||||
insertionData: InsertionData
|
||||
insertionTarget: String,
|
||||
insertionData: InsertionData
|
||||
) extends Status {
|
||||
|
||||
/** A SQL-99 compliant string representation of the select statement. */
|
||||
def sqlString: String = (
|
||||
"INSERT INTO " +
|
||||
insertionTarget +
|
||||
" " + insertionData.sqlString
|
||||
);
|
||||
|
||||
/** The name of the table where the data should be added. */
|
||||
//def insertionTarget: String;
|
||||
|
||||
/** The data that will be added tot he table. */
|
||||
//def insertionData: InsertionData;
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the select statement. */
|
||||
def sqlString: String = (
|
||||
"INSERT INTO " +
|
||||
insertionTarget +
|
||||
" " + insertionData.sqlString
|
||||
);
|
||||
|
||||
/** The name of the table where the data should be added. */
|
||||
//def insertionTarget: String;
|
||||
|
||||
/** The data that will be added tot he table. */
|
||||
//def insertionData: InsertionData;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:InsertionData.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -16,26 +16,26 @@ import scala.dbc.statement.expression._;
|
|||
|
||||
/** Data to be inserted into a table in an <code>Insert</code>. */
|
||||
abstract class InsertionData {
|
||||
def sqlString: String;
|
||||
def sqlString: String;
|
||||
}
|
||||
|
||||
object InsertionData {
|
||||
/** Insertion of data resulting from a query on the database. */
|
||||
case class Subquery (query:Relation) extends InsertionData {
|
||||
def sqlString = query.sqlString;
|
||||
}
|
||||
/** Insertion of data as explicitly defined values. */
|
||||
case class Constructor (
|
||||
columnNames:Option[List[String]],
|
||||
columnValues:List[Expression]
|
||||
) extends InsertionData {
|
||||
def sqlString = (
|
||||
(columnNames match {
|
||||
case None => ""
|
||||
case Some(cn) => cn.mkString(" (",", ",")")
|
||||
}) +
|
||||
" VALUES" +
|
||||
columnValues.map(e=>e.sqlInnerString).mkString(" (",", ",")")
|
||||
)
|
||||
}
|
||||
/** Insertion of data resulting from a query on the database. */
|
||||
case class Subquery (query:Relation) extends InsertionData {
|
||||
def sqlString = query.sqlString;
|
||||
}
|
||||
/** Insertion of data as explicitly defined values. */
|
||||
case class Constructor (
|
||||
columnNames:Option[List[String]],
|
||||
columnValues:List[Expression]
|
||||
) extends InsertionData {
|
||||
def sqlString = (
|
||||
(columnNames match {
|
||||
case None => ""
|
||||
case Some(cn) => cn.mkString(" (",", ",")")
|
||||
}) +
|
||||
" VALUES" +
|
||||
columnValues.map(e=>e.sqlInnerString).mkString(" (",", ",")")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,27 +6,27 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:IsolationLevel.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
||||
|
||||
abstract class IsolationLevel {
|
||||
def sqlString: String;
|
||||
def sqlString: String;
|
||||
}
|
||||
|
||||
object IsolationLevel {
|
||||
case object ReadUncommitted extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL READ UNCOMMITTED"
|
||||
}
|
||||
case object ReadCommitted extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL READ COMMITTED"
|
||||
}
|
||||
case object RepeatableRead extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL REPEATABLE READ"
|
||||
}
|
||||
case object Serializable extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL SERIALIZABLE"
|
||||
}
|
||||
case object ReadUncommitted extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL READ UNCOMMITTED"
|
||||
}
|
||||
case object ReadCommitted extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL READ COMMITTED"
|
||||
}
|
||||
case object RepeatableRead extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL REPEATABLE READ"
|
||||
}
|
||||
case object Serializable extends IsolationLevel {
|
||||
def sqlString = "ISOLATION LEVEL SERIALIZABLE"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Jointure.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -14,34 +14,34 @@ package scala.dbc.statement;
|
|||
|
||||
/** A jointure between two relations. */
|
||||
abstract class Jointure extends Relation {
|
||||
|
||||
/** The relation on the left part of the join. */
|
||||
def leftRelation: Relation;
|
||||
|
||||
/** The relation on the right part of the join. */
|
||||
def rightRelation: Relation;
|
||||
|
||||
/** The type of the jointure. */
|
||||
def joinType: JoinType;
|
||||
|
||||
/** The condition on which the jointure needs be done. */
|
||||
def joinCondition: Option[Expression];
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation statement. */
|
||||
def sqlString: String = {
|
||||
"SELECT * FROM " + sqlInnerString
|
||||
}
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside a query. */
|
||||
def sqlInnerString: String = (
|
||||
leftRelation.sqlInnerString + " " +
|
||||
joinType.sqlString + " " +
|
||||
rightRelation.sqlInnerString +
|
||||
(joinCondition match {
|
||||
case Some(jc) => jc.sqlString
|
||||
case None => ""
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
/** The relation on the left part of the join. */
|
||||
def leftRelation: Relation;
|
||||
|
||||
/** The relation on the right part of the join. */
|
||||
def rightRelation: Relation;
|
||||
|
||||
/** The type of the jointure. */
|
||||
def joinType: JoinType;
|
||||
|
||||
/** The condition on which the jointure needs be done. */
|
||||
def joinCondition: Option[Expression];
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation statement. */
|
||||
def sqlString: String = {
|
||||
"SELECT * FROM " + sqlInnerString
|
||||
}
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside a query. */
|
||||
def sqlInnerString: String = (
|
||||
leftRelation.sqlInnerString + " " +
|
||||
joinType.sqlString + " " +
|
||||
rightRelation.sqlInnerString +
|
||||
(joinCondition match {
|
||||
case Some(jc) => jc.sqlString
|
||||
case None => ""
|
||||
})
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Relation.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -20,12 +20,12 @@ abstract class Relation extends Statement {
|
|||
|
||||
def typeCheck (relation: result.Relation): Unit = {
|
||||
val sameType: Boolean = (
|
||||
relation.metadata.length == fieldTypes.length &&
|
||||
(relation.metadata.zip(fieldTypes).forall({case Pair(field,expectedType) =>
|
||||
isCompatibleType(field.datatype, expectedType)}))
|
||||
relation.metadata.length == fieldTypes.length &&
|
||||
(relation.metadata.zip(fieldTypes).forall({case Pair(field,expectedType) =>
|
||||
isCompatibleType(field.datatype, expectedType)}))
|
||||
);
|
||||
if (!sameType)
|
||||
throw new exception.IncompatibleSchema(fieldTypes,relation.metadata.map(field=>field.datatype));
|
||||
throw new exception.IncompatibleSchema(fieldTypes,relation.metadata.map(field=>field.datatype));
|
||||
}
|
||||
|
||||
def fieldTypes: List[DataType];
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Select.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -75,8 +75,8 @@ abstract class Select extends Relation {
|
|||
(groupByClause match {
|
||||
case None => ""
|
||||
case Some(gbl) => gbl match {
|
||||
case Nil => error("Empty group by clause is not allowed")
|
||||
case _ =>
|
||||
case Nil => error("Empty group by clause is not allowed")
|
||||
case _ =>
|
||||
(" GROUP BY " +
|
||||
gbl.tail.foldLeft(gbl.head.sqlInnerString)
|
||||
((name:String, gb) => name + ", " + gb.sqlInnerString))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:SetClause.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -16,7 +16,7 @@ import scala.dbc.statement.expression._;
|
|||
|
||||
/** Data to be inserted into a table in an <code>Insert</code>. */
|
||||
case class SetClause (name:String, expr:Expression) {
|
||||
val value: Pair[String,Expression] = Pair(name,expr);
|
||||
def sqlString: String =
|
||||
value._1 + " = " + value._2.sqlInnerString;
|
||||
val value: Pair[String,Expression] = Pair(name,expr);
|
||||
def sqlString: String =
|
||||
value._1 + " = " + value._2.sqlInnerString;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:SetQuantifier.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -14,21 +14,21 @@ package scala.dbc.statement;
|
|||
|
||||
/** A set quantifier that defines the collection type of a relation. */
|
||||
abstract class SetQuantifier {
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String;
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String;
|
||||
}
|
||||
|
||||
object SetQuantifier {
|
||||
/** A set quantifier that defines a relation as being a bag. That means
|
||||
* that duplicates are allowed. */
|
||||
case object AllTuples extends SetQuantifier {
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String = "ALL";
|
||||
}
|
||||
/** A set quantifier that defines a relation as being a set. That means
|
||||
* that duplicates are not allowed and will be pruned. */
|
||||
case object DistinctTuples extends SetQuantifier {
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String = "DISTINCT";
|
||||
}
|
||||
/** A set quantifier that defines a relation as being a bag. That means
|
||||
* that duplicates are allowed. */
|
||||
case object AllTuples extends SetQuantifier {
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String = "ALL";
|
||||
}
|
||||
/** A set quantifier that defines a relation as being a set. That means
|
||||
* that duplicates are not allowed and will be pruned. */
|
||||
case object DistinctTuples extends SetQuantifier {
|
||||
/** A SQL-99 compliant string representation of the set quantifier. */
|
||||
def sqlString: String = "DISTINCT";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Statement.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -14,5 +14,5 @@ package scala.dbc.statement;
|
|||
|
||||
/** An ISO-9075:2003 (SQL) statement. */
|
||||
abstract class Statement {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Status.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -14,17 +14,17 @@ package scala.dbc.statement;
|
|||
|
||||
/** A statement that changes the status of the database. */
|
||||
abstract class Status extends Statement {
|
||||
|
||||
/** A SQL-99 compliant string representation of the statement. */
|
||||
def sqlString: String;
|
||||
|
||||
/** Executes the statement on the given database. */
|
||||
def execute (database: scala.dbc.Database): scala.dbc.result.Status[Unit] = {
|
||||
database.executeStatement(this);
|
||||
}
|
||||
|
||||
def execute (database: scala.dbc.Database, debug: Boolean): scala.dbc.result.Status[Unit] = {
|
||||
database.executeStatement(this,debug);
|
||||
}
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the statement. */
|
||||
def sqlString: String;
|
||||
|
||||
/** Executes the statement on the given database. */
|
||||
def execute (database: scala.dbc.Database): scala.dbc.result.Status[Unit] = {
|
||||
database.executeStatement(this);
|
||||
}
|
||||
|
||||
def execute (database: scala.dbc.Database, debug: Boolean): scala.dbc.result.Status[Unit] = {
|
||||
database.executeStatement(this,debug);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,35 +6,35 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Table.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
||||
|
||||
/** A reference to a table in the database.
|
||||
* @author Gilles Dubochet
|
||||
* @version 1.0 */
|
||||
* @author Gilles Dubochet
|
||||
* @version 1.0 */
|
||||
abstract class Table extends Relation {
|
||||
|
||||
/** The name of the table in the database. */
|
||||
def tableName: String;
|
||||
|
||||
/** The name that the table will be called in the enclosing statement. */
|
||||
def tableRename: Option[String];
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation statement. */
|
||||
def sqlString: String = {
|
||||
"SELECT * FROM " + tableName
|
||||
}
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside a query. */
|
||||
def sqlInnerString: String = (
|
||||
tableName +
|
||||
(tableRename match {
|
||||
case None => ""
|
||||
case Some(rename) => " AS " + rename
|
||||
})
|
||||
)
|
||||
|
||||
/** The name of the table in the database. */
|
||||
def tableName: String;
|
||||
|
||||
/** The name that the table will be called in the enclosing statement. */
|
||||
def tableRename: Option[String];
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation statement. */
|
||||
def sqlString: String = {
|
||||
"SELECT * FROM " + tableName
|
||||
}
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside a query. */
|
||||
def sqlInnerString: String = (
|
||||
tableName +
|
||||
(tableRename match {
|
||||
case None => ""
|
||||
case Some(rename) => " AS " + rename
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Transaction.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -14,42 +14,42 @@ package scala.dbc.statement;
|
|||
|
||||
/** A statement that changes the status of the database. */
|
||||
case class Transaction [ResultType] (
|
||||
transactionBody: (scala.dbc.Database=>ResultType),
|
||||
accessMode: Option[AccessMode],
|
||||
isolationLevel: Option[IsolationLevel]
|
||||
transactionBody: (scala.dbc.Database=>ResultType),
|
||||
accessMode: Option[AccessMode],
|
||||
isolationLevel: Option[IsolationLevel]
|
||||
) extends Statement {
|
||||
|
||||
/** A SQL-99 compliant string representation of the statement. */
|
||||
def sqlStartString: String = (
|
||||
"START TRANSACTION" +
|
||||
(Pair(accessMode,isolationLevel) match {
|
||||
case Pair(None,None) => ""
|
||||
case Pair(Some(am),None) => " " + am.sqlString
|
||||
case Pair(None,Some(il)) => " " + il.sqlString
|
||||
case Pair(Some(am),Some(il)) => " " + am.sqlString + ", " + il.sqlString
|
||||
})
|
||||
);
|
||||
|
||||
def sqlCommitString: String = {
|
||||
"COMMIT"
|
||||
}
|
||||
|
||||
def sqlAbortString: String = {
|
||||
"ROLLBACK"
|
||||
}
|
||||
|
||||
//def transactionBody: (()=>Unit);
|
||||
|
||||
//def accessMode: Option[AccessMode];
|
||||
|
||||
//def isolationLevel: Option[IsolationLevel];
|
||||
|
||||
def execute (database: scala.dbc.Database): scala.dbc.result.Status[ResultType] = {
|
||||
database.executeStatement(this);
|
||||
}
|
||||
|
||||
def execute (database: scala.dbc.Database, debug: Boolean): scala.dbc.result.Status[ResultType] = {
|
||||
database.executeStatement(this,debug);
|
||||
}
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the statement. */
|
||||
def sqlStartString: String = (
|
||||
"START TRANSACTION" +
|
||||
(Pair(accessMode,isolationLevel) match {
|
||||
case Pair(None,None) => ""
|
||||
case Pair(Some(am),None) => " " + am.sqlString
|
||||
case Pair(None,Some(il)) => " " + il.sqlString
|
||||
case Pair(Some(am),Some(il)) => " " + am.sqlString + ", " + il.sqlString
|
||||
})
|
||||
);
|
||||
|
||||
def sqlCommitString: String = {
|
||||
"COMMIT"
|
||||
}
|
||||
|
||||
def sqlAbortString: String = {
|
||||
"ROLLBACK"
|
||||
}
|
||||
|
||||
//def transactionBody: (()=>Unit);
|
||||
|
||||
//def accessMode: Option[AccessMode];
|
||||
|
||||
//def isolationLevel: Option[IsolationLevel];
|
||||
|
||||
def execute (database: scala.dbc.Database): scala.dbc.result.Status[ResultType] = {
|
||||
database.executeStatement(this);
|
||||
}
|
||||
|
||||
def execute (database: scala.dbc.Database, debug: Boolean): scala.dbc.result.Status[ResultType] = {
|
||||
database.executeStatement(this,debug);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Update.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement;
|
||||
|
@ -16,32 +16,32 @@ import scala.dbc.statement.expression._;
|
|||
|
||||
/** An update of the state of a table. */
|
||||
case class Update (
|
||||
updateTarget: String,
|
||||
setClauses: List[SetClause],
|
||||
whereClause: Option[Expression]
|
||||
updateTarget: String,
|
||||
setClauses: List[SetClause],
|
||||
whereClause: Option[Expression]
|
||||
) extends Status {
|
||||
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the select statement. */
|
||||
def sqlString: String = (
|
||||
"UPDATE " +
|
||||
updateTarget +
|
||||
" SET " + setClauses.map(sc=>sc.sqlString).mkString("",", ","") +
|
||||
(whereClause match {
|
||||
case None => ""
|
||||
case Some(expr) => " WHERE " + expr.sqlString
|
||||
})
|
||||
);
|
||||
|
||||
/** The name of the table that should be updated. */
|
||||
//def updateTarget: String;
|
||||
|
||||
/** The data that will be added tot he table. */
|
||||
//def setClauses: List[SetClause];
|
||||
|
||||
/** Defines condition that must be true in the tuples that will be updated.
|
||||
* This value expression must return a boolean or boolean-compatible
|
||||
* value. */
|
||||
//def whereClause: Option[scala.dbc.statement.expression.Expression];
|
||||
|
||||
/** A SQL-99 compliant string representation of the select statement. */
|
||||
def sqlString: String = (
|
||||
"UPDATE " +
|
||||
updateTarget +
|
||||
" SET " + setClauses.map(sc=>sc.sqlString).mkString("",", ","") +
|
||||
(whereClause match {
|
||||
case None => ""
|
||||
case Some(expr) => " WHERE " + expr.sqlString
|
||||
})
|
||||
);
|
||||
|
||||
/** The name of the table that should be updated. */
|
||||
//def updateTarget: String;
|
||||
|
||||
/** The data that will be added tot he table. */
|
||||
//def setClauses: List[SetClause];
|
||||
|
||||
/** Defines condition that must be true in the tuples that will be updated.
|
||||
* This value expression must return a boolean or boolean-compatible
|
||||
* value. */
|
||||
//def whereClause: Option[scala.dbc.statement.expression.Expression];
|
||||
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Constant.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement.expression;
|
||||
|
||||
|
||||
abstract class Constant extends Expression {
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = constantValue.sqlString;
|
||||
|
||||
/** The value of the constant. */
|
||||
def constantValue: Value;
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = constantValue.sqlString;
|
||||
|
||||
/** The value of the constant. */
|
||||
def constantValue: Value;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Default.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement.expression;
|
||||
|
||||
|
||||
case object Default extends Expression {
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = "DEFAULT";
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = "DEFAULT";
|
||||
|
||||
}
|
||||
|
|
|
@ -6,27 +6,27 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:FunctionCall.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement.expression;
|
||||
|
||||
|
||||
case class FunctionCall (
|
||||
functionName: String,
|
||||
arguments: List[Expression]
|
||||
functionName: String,
|
||||
arguments: List[Expression]
|
||||
) extends Expression {
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = {
|
||||
functionName + "(" + arguments.mkString("",", ","") + ")"
|
||||
}
|
||||
|
||||
/** The name of the function to call. */
|
||||
//def functionName: String;
|
||||
|
||||
/** A list of all argument expressions to pass to the function, in order. */
|
||||
//def arguments: List[Expression];
|
||||
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = {
|
||||
functionName + "(" + arguments.mkString("",", ","") + ")"
|
||||
}
|
||||
|
||||
/** The name of the function to call. */
|
||||
//def functionName: String;
|
||||
|
||||
/** A list of all argument expressions to pass to the function, in order. */
|
||||
//def arguments: List[Expression];
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:SetFunction.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement.expression;
|
||||
|
@ -27,8 +27,8 @@ object SetFunction {
|
|||
def sqlString = (
|
||||
"(" +
|
||||
(setQuantifier match {
|
||||
case None => ""
|
||||
case Some(sq) => sq.sqlString + " "
|
||||
case None => ""
|
||||
case Some(sq) => sq.sqlString + " "
|
||||
}) +
|
||||
valueExpression.sqlString + ")"
|
||||
);
|
||||
|
|
|
@ -6,26 +6,26 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:TypeCast.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.statement.expression;
|
||||
|
||||
|
||||
case class TypeCast (
|
||||
expression: Expression,
|
||||
castType: DataType
|
||||
expression: Expression,
|
||||
castType: DataType
|
||||
) extends Expression {
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = {
|
||||
"CAST (" + expression.sqlInnerString + " AS " + castType.sqlString + ")";
|
||||
}
|
||||
|
||||
/** The expression that will be casted. */
|
||||
//def expression: Expression;
|
||||
|
||||
/** The type to which to cast. */
|
||||
//def castType: scala.dbc.datatype.DataType;
|
||||
|
||||
/** A SQL-99 compliant string representation of the relation sub-
|
||||
* statement. This only has a meaning inside another statement. */
|
||||
def sqlInnerString: String = {
|
||||
"CAST (" + expression.sqlInnerString + " AS " + castType.sqlString + ")";
|
||||
}
|
||||
|
||||
/** The expression that will be casted. */
|
||||
//def expression: Expression;
|
||||
|
||||
/** The type to which to cast. */
|
||||
//def castType: scala.dbc.datatype.DataType;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:DataTypeUtil.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.syntax;
|
||||
|
@ -19,80 +19,80 @@ object DataTypeUtil {
|
|||
|
||||
final val java_lang_Integer_SIZE = 32;
|
||||
final val java_lang_Long_SIZE = 64;
|
||||
|
||||
def boolean = new datatype.Boolean;
|
||||
def tinyint = new datatype.ExactNumeric[Byte](dbc.DataType.BYTE) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 8;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def smallint = new datatype.ExactNumeric[Short](dbc.DataType.SHORT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 16;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def integer = new datatype.ExactNumeric[Int](dbc.DataType.INT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 32;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def bigint = new datatype.ExactNumeric[Long](dbc.DataType.LONG) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def numeric (_precision:Int): DataType = numeric(_precision,0);
|
||||
def numeric (_precision:Int, _scale:Int): DataType =
|
||||
Pair(datatype.Factory.bytePrecision(_precision,true,true),_scale == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = _scale;
|
||||
}
|
||||
}
|
||||
def real = new datatype.ApproximateNumeric[Float](DataType.FLOAT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = true;
|
||||
}
|
||||
def doublePrecision = new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = true;
|
||||
}
|
||||
def character (_length: Int) = new datatype.Character {
|
||||
val length = _length;
|
||||
}
|
||||
def characterVarying (_length: Int) = new datatype.CharacterVarying {
|
||||
def length = _length;
|
||||
}
|
||||
def characterLargeObject = new datatype.CharacterLargeObject;
|
||||
|
||||
|
||||
def boolean = new datatype.Boolean;
|
||||
def tinyint = new datatype.ExactNumeric[Byte](dbc.DataType.BYTE) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 8;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def smallint = new datatype.ExactNumeric[Short](dbc.DataType.SHORT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 16;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def integer = new datatype.ExactNumeric[Int](dbc.DataType.INT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 32;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def bigint = new datatype.ExactNumeric[Long](dbc.DataType.LONG) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
def numeric (_precision:Int): DataType = numeric(_precision,0);
|
||||
def numeric (_precision:Int, _scale:Int): DataType =
|
||||
Pair(datatype.Factory.bytePrecision(_precision,true,true),_scale == 0) match {
|
||||
case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) =>
|
||||
new datatype.ExactNumeric[Int](DataType.INT) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(bp,true) if (bp <= java_lang_Long_SIZE) =>
|
||||
new datatype.ExactNumeric[Long](DataType.LONG) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(_,true) =>
|
||||
new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = 0;
|
||||
}
|
||||
case Pair(_,false) =>
|
||||
new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) {
|
||||
val precisionRadix = 10;
|
||||
val precision = _precision;
|
||||
val signed = true;
|
||||
val scale = _scale;
|
||||
}
|
||||
}
|
||||
def real = new datatype.ApproximateNumeric[Float](DataType.FLOAT) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 64;
|
||||
val signed = true;
|
||||
}
|
||||
def doublePrecision = new datatype.ApproximateNumeric[Double](DataType.DOUBLE) {
|
||||
val precisionRadix = 2;
|
||||
val precision = 128;
|
||||
val signed = true;
|
||||
}
|
||||
def character (_length: Int) = new datatype.Character {
|
||||
val length = _length;
|
||||
}
|
||||
def characterVarying (_length: Int) = new datatype.CharacterVarying {
|
||||
def length = _length;
|
||||
}
|
||||
def characterLargeObject = new datatype.CharacterLargeObject;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Database.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.syntax;
|
||||
|
@ -15,19 +15,19 @@ package scala.dbc.syntax;
|
|||
import java.net.URI;
|
||||
|
||||
object Database {
|
||||
|
||||
def database (server:String, username:String, password:String): dbc.Database = {
|
||||
val uri = new URI(server);
|
||||
// Java 1.5 if (uri.toString().contains("postgres")) {
|
||||
|
||||
def database (server:String, username:String, password:String): dbc.Database = {
|
||||
val uri = new URI(server);
|
||||
// Java 1.5 if (uri.toString().contains("postgres")) {
|
||||
if (uri.toString().indexOf("postgres") != -1) {
|
||||
new dbc.Database(new vendor.PostgreSQL {
|
||||
val uri = new URI(server);
|
||||
val user = username;
|
||||
val pass = password;
|
||||
})
|
||||
} else {
|
||||
throw new Exception("No DBMS vendor support could be found for the given URI");
|
||||
}
|
||||
}
|
||||
|
||||
new dbc.Database(new vendor.PostgreSQL {
|
||||
val uri = new URI(server);
|
||||
val user = username;
|
||||
val pass = password;
|
||||
})
|
||||
} else {
|
||||
throw new Exception("No DBMS vendor support could be found for the given URI");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Statement.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.syntax;
|
||||
|
@ -84,10 +84,10 @@ object Statement {
|
|||
def and (sdc:SelectDerivedColumns): SelectDerivedColumns = new SelectDerivedColumns {
|
||||
val selectList = SelectDerivedColumns.this.selectList ::: sdc.selectList;
|
||||
val selectTypes =
|
||||
if (SelectDerivedColumns.this.selectTypes.isEmpty | sdc.selectTypes.isEmpty)
|
||||
Nil
|
||||
else
|
||||
SelectDerivedColumns.this.selectTypes ::: sdc.selectTypes;
|
||||
if (SelectDerivedColumns.this.selectTypes.isEmpty | sdc.selectTypes.isEmpty)
|
||||
Nil
|
||||
else
|
||||
SelectDerivedColumns.this.selectTypes ::: sdc.selectTypes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,38 +125,38 @@ object Statement {
|
|||
def fromRelation: statement.Relation;
|
||||
def innerJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable {
|
||||
val fromRelation = new statement.Jointure {
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Inner;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Inner;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
}
|
||||
}
|
||||
def leftOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable {
|
||||
val fromRelation = new statement.Jointure {
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Left;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Left;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
}
|
||||
}
|
||||
def rightOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable {
|
||||
val fromRelation = new statement.Jointure {
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Right;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Right;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
}
|
||||
}
|
||||
def fullOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable {
|
||||
val fromRelation = new statement.Jointure {
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Full;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
val leftRelation = SelectSourceTable.this.fromRelation;
|
||||
val rightRelation = sst.fromRelation;
|
||||
val joinType = statement.JoinType.Outer.Full;
|
||||
val joinCondition = None;
|
||||
val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -249,14 +249,14 @@ object Statement {
|
|||
def groupByClause: List[statement.Expression];
|
||||
def then (se:StatementExpression): SelectGroupBy = new SelectGroupBy {
|
||||
val groupByClause =
|
||||
SelectGroupBy.this.groupByClause ::: List(se.toStatement);
|
||||
SelectGroupBy.this.groupByClause ::: List(se.toStatement);
|
||||
}
|
||||
def then (se:String): SelectGroupBy = new SelectGroupBy {
|
||||
val groupByClause =
|
||||
SelectGroupBy.this.groupByClause ::: List(new statement.expression.Field {
|
||||
val tableName = None;
|
||||
val fieldName = se;
|
||||
});
|
||||
SelectGroupBy.this.groupByClause ::: List(new statement.expression.Field {
|
||||
val tableName = None;
|
||||
val fieldName = se;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:StatementExpression.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.syntax;
|
||||
|
@ -164,7 +164,7 @@ abstract class StatementExpression {
|
|||
val operator = "IN";
|
||||
val leftOperand = StatementExpression.this.toStatement;
|
||||
val rightOperand = new statement.expression.Select {
|
||||
val selectStatement = se;
|
||||
val selectStatement = se;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ object StatementExpression {
|
|||
val operator = "EXISTS";
|
||||
val operatorIsLeft = true;
|
||||
val operand = new statement.expression.Select {
|
||||
val selectStatement = se;
|
||||
val selectStatement = se;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Boolean.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
||||
|
||||
abstract class Boolean extends Value {
|
||||
|
||||
val dataType: datatype.Boolean;
|
||||
|
||||
def sqlString = if (nativeValue) "TRUE" else "FALSE";
|
||||
|
||||
|
||||
val dataType: datatype.Boolean;
|
||||
|
||||
def sqlString = if (nativeValue) "TRUE" else "FALSE";
|
||||
|
||||
}
|
||||
|
||||
object Boolean {
|
||||
|
||||
implicit def booleanToBoolean (obj:value.Boolean): scala.Boolean = obj.nativeValue;
|
||||
|
||||
|
||||
implicit def booleanToBoolean (obj:value.Boolean): scala.Boolean = obj.nativeValue;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Character.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
@ -14,22 +14,22 @@ package scala.dbc.value;
|
|||
|
||||
/** A SQL-99 value of type character string. */
|
||||
abstract class Character extends Value {
|
||||
|
||||
override val dataType: datatype.Character;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
|
||||
override val dataType: datatype.Character;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** An object offering transformation methods (views) on the value.
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
object Character {
|
||||
|
||||
/** A character string value as a native string. */
|
||||
implicit def characterToString (obj:value.Character): String = obj.nativeValue;
|
||||
|
||||
|
||||
/** A character string value as a native string. */
|
||||
implicit def characterToString (obj:value.Character): String = obj.nativeValue;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:CharacterLargeObject.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
@ -14,22 +14,22 @@ package scala.dbc.value;
|
|||
|
||||
/** A SQL-99 value of type character large object. */
|
||||
abstract class CharacterLargeObject extends Value {
|
||||
|
||||
override val dataType: datatype.CharacterLargeObject;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
|
||||
override val dataType: datatype.CharacterLargeObject;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** An object offering transformation methods (views) on the value.
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
object CharacterLargeObject {
|
||||
|
||||
/** A character large object value as a native string. */
|
||||
implicit def characterLargeObjectToString (obj:value.CharacterLargeObject): String = obj.nativeValue;
|
||||
|
||||
|
||||
/** A character large object value as a native string. */
|
||||
implicit def characterLargeObjectToString (obj:value.CharacterLargeObject): String = obj.nativeValue;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:CharacterVarying.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
@ -14,22 +14,22 @@ package scala.dbc.value;
|
|||
|
||||
/** A SQL-99 value of type character varying string. */
|
||||
abstract class CharacterVarying extends Value {
|
||||
|
||||
override val dataType: datatype.CharacterVarying;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
|
||||
override val dataType: datatype.CharacterVarying;
|
||||
|
||||
/** An SQL-99 compliant string representation of the value. */
|
||||
def sqlString: String = {
|
||||
"'" + nativeValue + "'"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** An object offering transformation methods (views) on the value.
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
* This object must be visible in an expression to use value auto-
|
||||
* conversion. */
|
||||
object CharacterVarying {
|
||||
|
||||
/** A character varying string value as a native string. */
|
||||
implicit def characterVaryingToString (obj:value.CharacterVarying): String = obj.nativeValue;
|
||||
|
||||
|
||||
/** A character varying string value as a native string. */
|
||||
implicit def characterVaryingToString (obj:value.CharacterVarying): String = obj.nativeValue;
|
||||
|
||||
}
|
||||
|
|
|
@ -15,143 +15,143 @@ package scala.dbc.value;
|
|||
import java.math._;
|
||||
|
||||
object Conversion {
|
||||
|
||||
class Illegal (msg:String) extends Exception(msg);
|
||||
|
||||
implicit def view1 (value:Value): Byte = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to byte: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view2 (value:Value): Short = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toShort
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to short: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view3 (value:Value): Int = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toInt
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue.toInt
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to int: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view4 (value:Value): Long = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to long: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view5 (value:Value): BigInteger = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to big integer: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view6 (value:Value): BigDecimal = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]];
|
||||
new BigDecimal(v.nativeValue)
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_DECIMAL) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigDecimal]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to big decimal: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view7 (value:Value): Float = {
|
||||
if (value.dataType.nativeTypeId == DataType.FLOAT) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to float: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view8 (value:Value): Double = {
|
||||
if (value.dataType.nativeTypeId == DataType.FLOAT) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]];
|
||||
v.nativeValue.toFloat
|
||||
} else if (value.dataType.nativeTypeId == DataType.DOUBLE) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Double]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to double: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view9 (value:Value): scala.Boolean = {
|
||||
if (value.dataType.nativeTypeId == DataType.BOOLEAN) {
|
||||
val v = value.asInstanceOf[dbc.value.Boolean];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to boolean: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view10 (value:Value): String = value match {
|
||||
case v:dbc.value.Character => v.nativeValue;
|
||||
case v:dbc.value.CharacterLargeObject => v.nativeValue;
|
||||
case v:dbc.value.CharacterVarying => v.nativeValue;
|
||||
case _ => throw new Illegal("Cannot convert value to string")
|
||||
}
|
||||
|
||||
|
||||
class Illegal (msg:String) extends Exception(msg);
|
||||
|
||||
implicit def view1 (value:Value): Byte = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to byte: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view2 (value:Value): Short = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toShort
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to short: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view3 (value:Value): Int = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toInt
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue.toInt
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to int: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view4 (value:Value): Long = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
v.nativeValue.toLong
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to long: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view5 (value:Value): BigInteger = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
new BigInteger(v.nativeValue.toString(),10)
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to big integer: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view6 (value:Value): BigDecimal = {
|
||||
if (value.dataType.nativeTypeId == DataType.BYTE) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.SHORT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.INT) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.LONG) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]];
|
||||
new BigDecimal(v.nativeValue.toString())
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]];
|
||||
new BigDecimal(v.nativeValue)
|
||||
} else if (value.dataType.nativeTypeId == DataType.BIG_DECIMAL) {
|
||||
val v = value.asInstanceOf[dbc.value.ExactNumeric[BigDecimal]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to big decimal: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view7 (value:Value): Float = {
|
||||
if (value.dataType.nativeTypeId == DataType.FLOAT) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to float: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view8 (value:Value): Double = {
|
||||
if (value.dataType.nativeTypeId == DataType.FLOAT) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]];
|
||||
v.nativeValue.toFloat
|
||||
} else if (value.dataType.nativeTypeId == DataType.DOUBLE) {
|
||||
val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Double]];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to double: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view9 (value:Value): scala.Boolean = {
|
||||
if (value.dataType.nativeTypeId == DataType.BOOLEAN) {
|
||||
val v = value.asInstanceOf[dbc.value.Boolean];
|
||||
v.nativeValue
|
||||
} else {
|
||||
throw new Illegal("Cannot convert value to boolean: "+value)
|
||||
}
|
||||
}
|
||||
|
||||
implicit def view10 (value:Value): String = value match {
|
||||
case v:dbc.value.Character => v.nativeValue;
|
||||
case v:dbc.value.CharacterLargeObject => v.nativeValue;
|
||||
case v:dbc.value.CharacterVarying => v.nativeValue;
|
||||
case _ => throw new Illegal("Cannot convert value to string")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:ExactNumeric.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
@ -24,12 +24,12 @@ abstract class ExactNumeric [Type] extends Value {
|
|||
}
|
||||
|
||||
object ExactNumeric {
|
||||
|
||||
|
||||
implicit def exactNumericToByte (obj:value.ExactNumeric[Byte]): Byte = obj.nativeValue;
|
||||
implicit def exactNumericToShort (obj:value.ExactNumeric[Short]): Short = obj.nativeValue;
|
||||
implicit def exactNumericToInt (obj:value.ExactNumeric[Int]): Int = obj.nativeValue;
|
||||
implicit def exactNumericToLong (obj:value.ExactNumeric[Long]): Long = obj.nativeValue;
|
||||
implicit def exactNumericToBigInteger (obj:value.ExactNumeric[BigInteger]): BigInteger = obj.nativeValue;
|
||||
implicit def exactNumericToBigDecimal (obj:value.ExactNumeric[BigDecimal]): BigDecimal = obj.nativeValue;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Factory.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
@ -20,74 +20,74 @@ object Factory {
|
|||
def create (result: java.sql.ResultSet, index: Int, expectedDataType: DataType): Value = {
|
||||
expectedDataType.nativeTypeId match {
|
||||
case DataType.OBJECT =>
|
||||
new value.Unknown {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.Unknown];
|
||||
val nativeValue: Object = result.getObject(index);
|
||||
}
|
||||
new value.Unknown {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.Unknown];
|
||||
val nativeValue: Object = result.getObject(index);
|
||||
}
|
||||
case DataType.STRING => {
|
||||
expectedDataType match {
|
||||
case t:datatype.Character =>
|
||||
new value.Character {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
case t:datatype.CharacterVarying =>
|
||||
new value.CharacterVarying {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
case t:datatype.CharacterLargeObject =>
|
||||
new value.CharacterLargeObject {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
}
|
||||
expectedDataType match {
|
||||
case t:datatype.Character =>
|
||||
new value.Character {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
case t:datatype.CharacterVarying =>
|
||||
new value.CharacterVarying {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
case t:datatype.CharacterLargeObject =>
|
||||
new value.CharacterLargeObject {
|
||||
val dataType = t;
|
||||
val nativeValue: String = result.getString(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
case DataType.BOOLEAN =>
|
||||
new value.Boolean {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.Boolean];
|
||||
val nativeValue: scala.Boolean = result.getBoolean(index);
|
||||
}
|
||||
new value.Boolean {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.Boolean];
|
||||
val nativeValue: scala.Boolean = result.getBoolean(index);
|
||||
}
|
||||
case DataType.FLOAT =>
|
||||
new value.ApproximateNumeric[Float] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Float]];
|
||||
val nativeValue: Float = result.getFloat(index);
|
||||
}
|
||||
new value.ApproximateNumeric[Float] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Float]];
|
||||
val nativeValue: Float = result.getFloat(index);
|
||||
}
|
||||
case DataType.DOUBLE =>
|
||||
new value.ApproximateNumeric[Double] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Double]];
|
||||
val nativeValue: Double = result.getDouble(index);
|
||||
}
|
||||
new value.ApproximateNumeric[Double] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Double]];
|
||||
val nativeValue: Double = result.getDouble(index);
|
||||
}
|
||||
case DataType.BYTE =>
|
||||
new value.ExactNumeric[Byte] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Byte]];
|
||||
val nativeValue: Byte = result.getByte(index);
|
||||
}
|
||||
new value.ExactNumeric[Byte] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Byte]];
|
||||
val nativeValue: Byte = result.getByte(index);
|
||||
}
|
||||
case DataType.SHORT =>
|
||||
new value.ExactNumeric[Short] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Short]];
|
||||
val nativeValue: Short = result.getShort(index);
|
||||
}
|
||||
new value.ExactNumeric[Short] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Short]];
|
||||
val nativeValue: Short = result.getShort(index);
|
||||
}
|
||||
case DataType.INT =>
|
||||
new value.ExactNumeric[Int] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Int]];
|
||||
val nativeValue: Int = result.getInt(index);
|
||||
}
|
||||
new value.ExactNumeric[Int] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Int]];
|
||||
val nativeValue: Int = result.getInt(index);
|
||||
}
|
||||
case DataType.LONG =>
|
||||
new value.ExactNumeric[Long] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Long]];
|
||||
val nativeValue:Long = result.getLong(index);
|
||||
}
|
||||
new value.ExactNumeric[Long] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Long]];
|
||||
val nativeValue:Long = result.getLong(index);
|
||||
}
|
||||
case DataType.BIG_INTEGER =>
|
||||
new value.ExactNumeric[BigInteger] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigInteger]];
|
||||
val nativeValue: BigInteger = result.getBigDecimal(index).unscaledValue();
|
||||
}
|
||||
new value.ExactNumeric[BigInteger] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigInteger]];
|
||||
val nativeValue: BigInteger = result.getBigDecimal(index).unscaledValue();
|
||||
}
|
||||
case DataType.BIG_DECIMAL =>
|
||||
new value.ExactNumeric[BigDecimal] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigDecimal]];
|
||||
val nativeValue: BigDecimal = result.getBigDecimal(index);
|
||||
}
|
||||
new value.ExactNumeric[BigDecimal] {
|
||||
val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigDecimal]];
|
||||
val nativeValue: BigDecimal = result.getBigDecimal(index);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:Unknown.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.value;
|
||||
|
||||
|
||||
abstract class Unknown extends Value {
|
||||
|
||||
val dataType: datatype.Unknown;
|
||||
|
||||
def sqlString = error ("An 'ANY' value cannot be represented.");
|
||||
|
||||
|
||||
val dataType: datatype.Unknown;
|
||||
|
||||
def sqlString = error ("An 'ANY' value cannot be represented.");
|
||||
|
||||
}
|
||||
|
||||
object UnknownType {
|
||||
|
||||
def view (obj:value.Unknown): Object = obj.nativeValue;
|
||||
|
||||
|
||||
def view (obj:value.Unknown): Object = obj.nativeValue;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,22 +6,22 @@
|
|||
** |/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
// $Id:PostgreSQL.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
|
||||
|
||||
|
||||
package scala.dbc.vendor;
|
||||
|
||||
|
||||
abstract class PostgreSQL extends Vendor {
|
||||
|
||||
def uri:java.net.URI;
|
||||
def user:String;
|
||||
def pass:String;
|
||||
|
||||
val retainedConnections = 5;
|
||||
|
||||
val nativeDriverClass = Class.forName("org.postgresql.Driver");
|
||||
|
||||
val urlProtocolString = "jdbc:postgresql:"
|
||||
|
||||
|
||||
def uri:java.net.URI;
|
||||
def user:String;
|
||||
def pass:String;
|
||||
|
||||
val retainedConnections = 5;
|
||||
|
||||
val nativeDriverClass = Class.forName("org.postgresql.Driver");
|
||||
|
||||
val urlProtocolString = "jdbc:postgresql:"
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue