summaryrefslogtreecommitdiff
path: root/src/dbc/scala/dbc/syntax/DataTypeUtil.scala
blob: 573337d01c620fd72ae4d2381abb7ed731411095 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala.dbc
package syntax;


import java.math.BigDecimal;
import java.math.BigInteger;

@deprecated(DbcIsDeprecated) 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;

}