package scala.dbc2.syntax import java.math.{BigDecimal, BigInteger} import scala.dbc2.datatype.Digits object DataTypeSyntax { /* Data types */ def boolean = new datatype.Boolean def smallint = new datatype.ExactNumeric { type NativeType = Short val nativeTypeId = dbc2.DataType.SHORT val precision = Digits.TwoBytes val signed = true val scale = Digits.Zero } def integer = new datatype.ExactNumeric { type NativeType = Int val nativeTypeId = dbc2.DataType.INT val precision = Digits.FourBytes val signed = true val scale = Digits.Zero } def bigint = new datatype.ExactNumeric { type NativeType = Long val nativeTypeId = dbc2.DataType.LONG val precision = Digits.EightBytes val signed = true val scale = Digits.Zero } def numeric (_precision:Int): datatype.ExactNumeric = numeric(_precision,0) def numeric (_precision:Int, _scale:Int): datatype.ExactNumeric = Pair(datatype.Factory.bytePrecision(_precision,true),_scale == 0) match { case Pair(Digits.FourBytes | Digits.TwoBytes, true) => new datatype.ExactNumeric { type NativeType = Int val nativeTypeId = DataType.INT val precision = Digits.Decimal(_precision) val signed = true val scale = Digits.Zero } case Pair(Digits.EightBytes, true) => new datatype.ExactNumeric { type NativeType = Long val nativeTypeId = DataType.LONG val precision = Digits.Decimal(_precision) val signed = true val scale = Digits.Zero } case Pair(_,true) => new datatype.ExactNumeric { type NativeType = BigInteger val nativeTypeId = DataType.BIG_INTEGER val precision = Digits.Decimal(_precision) val signed = true val scale = Digits.Zero } case Pair(_,false) => new datatype.ExactNumeric { type NativeType = BigDecimal val nativeTypeId = DataType.BIG_DECIMAL val precision = Digits.Decimal(_precision) val signed = true val scale = Digits.Decimal(_scale) } } def real = new datatype.ApproximateNumeric { type NativeType = Float val nativeTypeId = DataType.FLOAT val precision = Digits.FourBytes val signed = true } def doublePrecision = new datatype.ApproximateNumeric { type NativeType = Double val nativeTypeId = DataType.DOUBLE val precision = Digits.EightBytes 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 string = new datatype.CharacterString {} }