DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Package Functions | Static Package Functions | Properties | Private Member Functions | Static Private Member Functions | List of all members
Deveel.Data.Types.NumericType Class Reference
Inheritance diagram for Deveel.Data.Types.NumericType:
Deveel.Data.Types.SqlType Deveel.Data.Types.ISizeableType Deveel.Data.Serialization.ISerializable

Public Member Functions

 NumericType (SqlTypeCode typeCode, int size, byte scale)
 
 NumericType (SqlTypeCode typeCode)
 
 NumericType (SqlTypeCode typeCode, int size)
 
override bool Equals (object obj)
 
override Type GetObjectType ()
 
override Type GetRuntimeType ()
 
override bool IsCacheable (ISqlObject value)
 
override int GetHashCode ()
 
override SqlType Wider (SqlType otherType)
 Gets the one data-type between this and the other one given that handles the wider range of values. More...
 
override bool IsComparable (SqlType type)
 Verifies if a given SqlType is comparable to this data-type. More...
 
override int Compare (ISqlObject x, ISqlObject y)
 
override bool CanCastTo (SqlType destType)
 Verifies if this type can cast any value to the given SqlType. More...
 
override DataObject CastTo (DataObject value, SqlType destType)
 Converts the given object value to a SqlType specified. More...
 
override string ToString ()
 
override object ConvertTo (ISqlObject obj, Type destType)
 
override ISqlObject Add (ISqlObject a, ISqlObject b)
 
override ISqlObject Subtract (ISqlObject a, ISqlObject b)
 
override ISqlObject Multiply (ISqlObject a, ISqlObject b)
 
override ISqlObject Divide (ISqlObject a, ISqlObject b)
 
override ISqlObject Modulus (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsSmallerThan (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsGreatherThan (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsSmallerOrEqualThan (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsGreaterOrEqualThan (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsEqualTo (ISqlObject a, ISqlObject b)
 
override SqlBoolean IsNotEqualTo (ISqlObject a, ISqlObject b)
 
override ISqlObject Negate (ISqlObject value)
 
override ISqlObject Reverse (ISqlObject value)
 
override ISqlObject UnaryPlus (ISqlObject value)
 
override ISqlObject XOr (ISqlObject a, ISqlObject b)
 
override ISqlObject And (ISqlObject a, ISqlObject b)
 
override ISqlObject Or (ISqlObject a, ISqlObject b)
 
override void SerializeObject (Stream stream, ISqlObject obj)
 
override ISqlObject DeserializeObject (Stream stream)
 
- Public Member Functions inherited from Deveel.Data.Types.SqlType
override bool Equals (object obj)
 
override int GetHashCode ()
 
virtual bool Equals (SqlType other)
 
override string ToString ()
 
virtual ISqlObject CreateFromLargeObject (ILargeObject objRef)
 
virtual ISqlObject CreateFrom (object value)
 

Protected Member Functions

override void GetData (SerializeData data)
 
- Protected Member Functions inherited from Deveel.Data.Types.SqlType
 SqlType (SqlTypeCode sqlType)
 Constructs the SqlType for the given specific SQL TYPE. More...
 
 SqlType (string name, SqlTypeCode typeCode)
 Constructs the SqlType for the given specific SQL TYPE and a given name. More...
 
 SqlType (ObjectData data)
 

Package Functions

override int ColumnSizeOf (ISqlObject obj)
 
- Package Functions inherited from Deveel.Data.Types.SqlType
virtual int GetCacheUsage (ISqlObject value)
 

Static Package Functions

static bool IsNumericType (SqlTypeCode typeCode)
 

Properties

int Size [get, private set]
 
byte Scale [get, private set]
 
override bool IsStorable [get]
 
- Properties inherited from Deveel.Data.Types.SqlType
string Name [get, private set]
 Gets the name of the data-type that is used to resolve it within the context. More...
 
SqlTypeCode TypeCode [get, private set]
 Gets the kind of SQL type this data-type handles. More...
 
virtual bool IsIndexable [get]
 Indicates if the values handled by the type can be part of an index. More...
 
bool IsPrimitive [get]
 Gets a value indicating if this data-type is primitive. More...
 
bool IsNull [get]
 
virtual bool IsStorable [get]
 
- Properties inherited from Deveel.Data.Types.ISizeableType
int Size [get]
 

Private Member Functions

 NumericType (ObjectData data)
 

Static Private Member Functions

static void AssertIsNumeric (SqlTypeCode typeCode)
 
static int GetIntSize (SqlTypeCode sqlType)
 
static int GetFloatSize (SqlTypeCode sqlType)
 
static SqlDateTime ToDate (long time)
 

Additional Inherited Members

- Static Public Member Functions inherited from Deveel.Data.Types.SqlType
static SqlType Parse (string s)
 Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent. More...
 
static SqlType Parse (IContext context, string s)
 Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent. More...
 
static bool IsPrimitiveType (SqlTypeCode typeCode)
 
static SqlType Resolve (SqlTypeCode typeCode)
 
static SqlType Resolve (SqlTypeCode typeCode, DataTypeMeta[] meta)
 
static SqlType Resolve (SqlTypeCode typeCode, DataTypeMeta[] meta, ITypeResolver resolver)
 
static SqlType Resolve (SqlTypeCode typeCode, string name)
 
static SqlType Resolve (SqlTypeCode typeCode, string name, DataTypeMeta[] meta)
 
static SqlType Resolve (string name)
 
static SqlType Resolve (string name, DataTypeMeta[] meta)
 
static SqlType Resolve (string name, DataTypeMeta[] meta, ITypeResolver resolver)
 
static SqlType Resolve (SqlTypeCode typeCode, string name, DataTypeMeta[] meta, ITypeResolver resolver)
 

Detailed Description

Definition at line 27 of file NumericType.cs.

Constructor & Destructor Documentation

Deveel.Data.Types.NumericType.NumericType ( SqlTypeCode  typeCode,
int  size,
byte  scale 
)
inline

Definition at line 28 of file NumericType.cs.

29  : base("NUMERIC", typeCode) {
30  AssertIsNumeric(typeCode);
31  Size = size;
32  Scale = scale;
33  }
static void AssertIsNumeric(SqlTypeCode typeCode)
Definition: NumericType.cs:105
Deveel.Data.Types.NumericType.NumericType ( SqlTypeCode  typeCode)
inline

Definition at line 35 of file NumericType.cs.

36  : this(typeCode, -1) {
37  }
Deveel.Data.Types.NumericType.NumericType ( SqlTypeCode  typeCode,
int  size 
)
inline

Definition at line 39 of file NumericType.cs.

40  : this(typeCode, size, 0) {
41  }
Deveel.Data.Types.NumericType.NumericType ( ObjectData  data)
inlineprivate

Definition at line 43 of file NumericType.cs.

44  : base(data) {
45  Size = data.GetInt32("Size");
46  Scale = data.GetByte("Scale");
47  }

Member Function Documentation

override ISqlObject Deveel.Data.Types.NumericType.Add ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 332 of file NumericType.cs.

332  {
333  if (!(a is SqlNumber))
334  throw new ArgumentException();
335  if (b is SqlNull || b.IsNull)
336  return SqlNumber.Null;
337 
338  var num1 = (SqlNumber) a;
339  SqlNumber num2;
340 
341  if (b is SqlBoolean) {
342  if ((SqlBoolean) b) {
343  num2 = SqlNumber.One;
344  } else if (!(SqlBoolean) b) {
345  num2 = SqlNumber.Zero;
346  } else {
347  num2 = SqlNumber.Null;
348  }
349  } else if (b is SqlNumber) {
350  num2 = (SqlNumber) b;
351  } else {
352  throw new ArgumentException();
353  }
354 
355  return num1.Add(num2);
356  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
static readonly SqlNumber Zero
Definition: SqlNumber.cs:29
static readonly SqlNumber Null
Definition: SqlNumber.cs:31
static readonly SqlNumber One
Definition: SqlNumber.cs:30
override ISqlObject Deveel.Data.Types.NumericType.And ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 576 of file NumericType.cs.

576  {
577  if (!(a is SqlNumber) ||
578  !(b is SqlNumber))
579  throw new ArgumentException();
580 
581  if (b.IsNull)
582  return SqlNumber.Null;
583 
584  if (a.IsNull)
585  return a;
586 
587  var num1 = (SqlNumber) a;
588  var num2 = (SqlNumber) b;
589 
590  return num1.And(num2);
591  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
static void Deveel.Data.Types.NumericType.AssertIsNumeric ( SqlTypeCode  typeCode)
inlinestaticprivate

Definition at line 105 of file NumericType.cs.

105  {
106  if (!IsNumericType(typeCode))
107  throw new ArgumentException(String.Format("The type '{0}' is not a valid NUMERIC type.", typeCode));
108  }
A long string in the system.
static bool IsNumericType(SqlTypeCode typeCode)
Definition: NumericType.cs:684
override bool Deveel.Data.Types.NumericType.CanCastTo ( SqlType  destType)
inlinevirtual

Verifies if this type can cast any value to the given SqlType.

Parameters
destTypeThe other type, destination of the cast, to verify.

By default, this method returns false, because cast process must be specified per type: when overriding the method CastTo, pay attention to also override this method accordingly.

Returns

CastTo

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 214 of file NumericType.cs.

214  {
215  return destType.TypeCode != SqlTypeCode.Array &&
216  destType.TypeCode != SqlTypeCode.ColumnType &&
217  destType.TypeCode != SqlTypeCode.RowType &&
218  destType.TypeCode != SqlTypeCode.Object;
219  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override DataObject Deveel.Data.Types.NumericType.CastTo ( DataObject  value,
SqlType  destType 
)
inlinevirtual

Converts the given object value to a SqlType specified.

Parameters
valueThe value to convert.
destTypeThe destination type of the conversion.

If the given destType destination type is equivalent to this type, it will return the value provided, otherwise it will throw an exception by default.

Casting values to specific types is specific to each data-type: override this method to support type-specific conversions.

When overriding this method, CanCastTo should be overridden accordingly to indicate the type supports casting.

Returns
Returns an instance of DataObject that is the result of the conversion from this data-type to the other type given.

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 221 of file NumericType.cs.

221  {
222  var n = (SqlNumber) value.Value;
223  var sqlType = destType.TypeCode;
224  ISqlObject casted;
225 
226  switch (sqlType) {
227  case (SqlTypeCode.Bit):
228  case (SqlTypeCode.Boolean):
229  casted = new SqlBoolean(n.ToBoolean());
230  break;
231  case (SqlTypeCode.TinyInt):
232  case (SqlTypeCode.SmallInt):
233  case (SqlTypeCode.Integer):
234  casted = new SqlNumber(n.ToInt32());
235  break;
236  case (SqlTypeCode.BigInt):
237  casted = new SqlNumber(n.ToInt64());
238  break;
239  case (SqlTypeCode.Float):
240  case (SqlTypeCode.Real):
241  case (SqlTypeCode.Double):
242  double d;
243  if (n.State == NumericState.NotANumber) {
244  casted = new SqlNumber(Double.NaN);
245  } else if (n.State == NumericState.PositiveInfinity) {
246  casted = new SqlNumber(Double.PositiveInfinity);
247  } else if (n.State == NumericState.NegativeInfinity) {
248  casted = new SqlNumber(Double.NegativeInfinity);
249  } else {
250  casted = new SqlNumber(n.ToDouble());
251  }
252 
253  break;
254  case (SqlTypeCode.Numeric):
255  case (SqlTypeCode.Decimal):
256  casted = n;
257  break;
258  case (SqlTypeCode.Char):
259  casted = new SqlString(n.ToString().PadRight(((StringType) destType).MaxSize));
260  break;
261  case (SqlTypeCode.VarChar):
262  case (SqlTypeCode.LongVarChar):
263  case (SqlTypeCode.String):
264  casted = new SqlString(n.ToString());
265  break;
266  case (SqlTypeCode.Date):
267  case (SqlTypeCode.Time):
268  case (SqlTypeCode.TimeStamp):
269  casted = ToDate(n.ToInt64());
270  break;
271  case (SqlTypeCode.Blob):
272  case (SqlTypeCode.Binary):
273  case (SqlTypeCode.VarBinary):
274  case (SqlTypeCode.LongVarBinary):
275  casted = new SqlBinary(n.ToByteArray());
276  break;
277  case (SqlTypeCode.Null):
278  casted = SqlNull.Value;
279  break;
280  default:
281  throw new InvalidCastException();
282  }
283 
284  return new DataObject(destType, casted);
285  }
NumericState
Lists all the possible special states of a number.
Definition: NumericState.cs:21
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
static readonly SqlNull Value
Definition: SqlNull.cs:24
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
static SqlDateTime ToDate(long time)
Definition: NumericType.cs:210
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
Deveel.Data.Sql.Objects.SqlString SqlString
Definition: DataObject.cs:27
override int Deveel.Data.Types.NumericType.ColumnSizeOf ( ISqlObject  obj)
inlinepackagevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 662 of file NumericType.cs.

662  {
663  if (obj is SqlNull)
664  return 1;
665 
666  if (!(obj is SqlNumber))
667  throw new ArgumentException(String.Format("Cannot determine the size of an object of type '{0}'.", obj.GetType()));
668 
669  var number = (SqlNumber) obj;
670 
671  if (number.IsNull)
672  return 1;
673 
674  if (number.CanBeInt32)
675  return 1 + 4;
676  if (number.CanBeInt64)
677  return 1+ 8;
678 
679  // Type + Scale + Precision + Byte Count
680  var length = number.ToByteArray().Length;
681  return 1 + 4 + 4 + 4 + length;
682  }
A long string in the system.
override int Deveel.Data.Types.NumericType.Compare ( ISqlObject  x,
ISqlObject  y 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 195 of file NumericType.cs.

195  {
196  var n1 = (SqlNumber)x;
197  SqlNumber n2;
198 
199  if (y is SqlNumber) {
200  n2 = (SqlNumber)y;
201  } else if (y is SqlBoolean) {
202  n2 = (SqlBoolean) y ? SqlNumber.One : SqlNumber.Zero;
203  } else {
204  throw new NotSupportedException();
205  }
206 
207  return n1.CompareTo(n2);
208  }
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override object Deveel.Data.Types.NumericType.ConvertTo ( ISqlObject  obj,
Type  destType 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 302 of file NumericType.cs.

302  {
303  if (!(obj is SqlNumber))
304  throw new ArgumentException();
305 
306  var number = (SqlNumber)obj;
307  if (number.IsNull)
308  return null;
309 
310  if (destType == typeof(byte))
311  return number.ToByte();
312  if (destType == typeof(short))
313  return number.ToInt16();
314  if (destType == typeof(int))
315  return number.ToInt32();
316  if (destType == typeof(long))
317  return number.ToInt64();
318  if (destType == typeof(float))
319  return number.ToSingle();
320  if (destType == typeof(double))
321  return number.ToDouble();
322 
323  if (destType == typeof(bool))
324  return number.ToBoolean();
325 
326  if (destType == typeof(string))
327  return number.ToString();
328 
329  return base.ConvertTo(obj, destType);
330  }
override ISqlObject Deveel.Data.Types.NumericType.DeserializeObject ( Stream  stream)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 636 of file NumericType.cs.

636  {
637  var reader = new BinaryReader(stream);
638 
639  var type = reader.ReadByte();
640  if (type == 0)
641  return SqlNumber.Null;
642 
643  if (type == 1) {
644  var value = reader.ReadInt32();
645  return new SqlNumber(value);
646  }
647  if (type == 2) {
648  var value = reader.ReadInt64();
649  return new SqlNumber(value);
650  }
651  if (type == 3) {
652  var precision = reader.ReadInt32();
653  var scale = reader.ReadInt32();
654  var length = reader.ReadInt32();
655  var bytes = reader.ReadBytes(length);
656  return new SqlNumber(bytes, scale, precision);
657  }
658 
659  throw new FormatException();
660  }
static readonly SqlNumber Null
Definition: SqlNumber.cs:31
override ISqlObject Deveel.Data.Types.NumericType.Divide ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 400 of file NumericType.cs.

400  {
401  if (!(a is SqlNumber) ||
402  !(b is SqlNumber))
403  throw new ArgumentException();
404 
405  if (b.IsNull)
406  return SqlNumber.Null;
407 
408  if (a.IsNull)
409  return a;
410 
411  var num1 = (SqlNumber)a;
412  var num2 = (SqlNumber)b;
413 
414  return num1.Divide(num2);
415  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override bool Deveel.Data.Types.NumericType.Equals ( object  obj)
inline

Definition at line 62 of file NumericType.cs.

62  {
63  var other = obj as NumericType;
64  if (other == null)
65  return false;
66 
67  return TypeCode == other.TypeCode &&
68  Size == other.Size &&
69  Scale == other.Scale;
70  }
NumericType(SqlTypeCode typeCode, int size, byte scale)
Definition: NumericType.cs:28
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
override void Deveel.Data.Types.NumericType.GetData ( SerializeData  data)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 57 of file NumericType.cs.

57  {
58  data.SetValue("Size", Size);
59  data.SetValue("Scale", Scale);
60  }
void SetValue(string key, Type type, object value)
static int Deveel.Data.Types.NumericType.GetFloatSize ( SqlTypeCode  sqlType)
inlinestaticprivate

Definition at line 126 of file NumericType.cs.

126  {
127  switch (sqlType) {
128  default:
129  return 0;
130  case SqlTypeCode.Real:
131  return 4;
132  case SqlTypeCode.Float:
133  case SqlTypeCode.Double:
134  return 8;
135  }
136  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override int Deveel.Data.Types.NumericType.GetHashCode ( )
inline

Definition at line 101 of file NumericType.cs.

101  {
102  return (TypeCode.GetHashCode() * Scale) + Size.GetHashCode();
103  }
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
static int Deveel.Data.Types.NumericType.GetIntSize ( SqlTypeCode  sqlType)
inlinestaticprivate

Definition at line 110 of file NumericType.cs.

110  {
111  switch (sqlType) {
112  case SqlTypeCode.TinyInt:
113  return 1;
114  case SqlTypeCode.SmallInt:
115  return 2;
116  case SqlTypeCode.Integer:
117  return 4;
118  case SqlTypeCode.BigInt:
119  return 8;
120  default:
121  return 0;
122  }
123  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override Type Deveel.Data.Types.NumericType.GetObjectType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 72 of file NumericType.cs.

72  {
73  return typeof(SqlNumber);
74  }
override Type Deveel.Data.Types.NumericType.GetRuntimeType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 76 of file NumericType.cs.

76  {
77  if (TypeCode == SqlTypeCode.TinyInt)
78  return typeof(byte);
79  if (TypeCode == SqlTypeCode.SmallInt)
80  return typeof(short);
81  if (TypeCode == SqlTypeCode.Integer)
82  return typeof(int);
83  if (TypeCode == SqlTypeCode.BigInt)
84  return typeof(long);
85  if (TypeCode == SqlTypeCode.Float ||
86  TypeCode == SqlTypeCode.Real)
87  return typeof(float);
88  if (TypeCode == SqlTypeCode.Double)
89  return typeof(double);
90  if (TypeCode == SqlTypeCode.Numeric ||
91  TypeCode == SqlTypeCode.Decimal)
92  return typeof(BigDecimal);
93 
94  return base.GetRuntimeType();
95  }
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override bool Deveel.Data.Types.NumericType.IsCacheable ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 97 of file NumericType.cs.

97  {
98  return value is SqlNumber || value is SqlNull;
99  }
override bool Deveel.Data.Types.NumericType.IsComparable ( SqlType  type)
inlinevirtual

Verifies if a given SqlType is comparable to this data-type.

Parameters
typeThe other data-type to verify the compatibility.

It is not required two SqlType to be identical to be compared: when overridden by a derived class, this methods verifies the properties of the argument type, to see if values handled by the types can be compared.

By default, this method compares the values returned by TypeCode to see if they are identical.

Returns
Returns true if the values handled by this data-type can be compared to ones handled by the given type , or false otherwise.

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 191 of file NumericType.cs.

191  {
192  return type is NumericType || type is BooleanType;
193  }
NumericType(SqlTypeCode typeCode, int size, byte scale)
Definition: NumericType.cs:28
override SqlBoolean Deveel.Data.Types.NumericType.IsEqualTo ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 502 of file NumericType.cs.

502  {
503  if (!(a is SqlNumber) ||
504  !(b is SqlNumber))
505  throw new ArgumentException();
506 
507  if (b.IsNull)
508  return a.IsNull;
509 
510  if (a.IsNull)
511  return b.IsNull;
512 
513  var num1 = (SqlNumber) a;
514  var num2 = (SqlNumber) b;
515 
516  return num1.Equals(num2);
517  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override SqlBoolean Deveel.Data.Types.NumericType.IsGreaterOrEqualThan ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 485 of file NumericType.cs.

485  {
486  if (!(a is SqlNumber) ||
487  !(b is SqlNumber))
488  throw new ArgumentException();
489 
490  if (b.IsNull)
491  return SqlBoolean.Null;
492 
493  if (a.IsNull)
494  return SqlBoolean.Null;
495 
496  var num1 = (SqlNumber) a;
497  var num2 = (SqlNumber) b;
498 
499  return num1 >= num2;
500  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override SqlBoolean Deveel.Data.Types.NumericType.IsGreatherThan ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 451 of file NumericType.cs.

451  {
452  if (!(a is SqlNumber) ||
453  !(b is SqlNumber))
454  throw new ArgumentException();
455 
456  if (b.IsNull)
457  return SqlBoolean.Null;
458 
459  if (a.IsNull)
460  return SqlBoolean.Null;
461 
462  var num1 = (SqlNumber) a;
463  var num2 = (SqlNumber) b;
464 
465  return num1 > num2;
466  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override SqlBoolean Deveel.Data.Types.NumericType.IsNotEqualTo ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 519 of file NumericType.cs.

519  {
520  return !IsEqualTo(a, b);
521  }
override SqlBoolean IsEqualTo(ISqlObject a, ISqlObject b)
Definition: NumericType.cs:502
static bool Deveel.Data.Types.NumericType.IsNumericType ( SqlTypeCode  typeCode)
inlinestaticpackage

Definition at line 684 of file NumericType.cs.

684  {
685  return typeCode == SqlTypeCode.TinyInt ||
686  typeCode == SqlTypeCode.SmallInt ||
687  typeCode == SqlTypeCode.Integer ||
688  typeCode == SqlTypeCode.BigInt ||
689  typeCode == SqlTypeCode.Real ||
690  typeCode == SqlTypeCode.Float ||
691  typeCode == SqlTypeCode.Double ||
692  typeCode == SqlTypeCode.Decimal ||
693  typeCode == SqlTypeCode.Numeric;
694  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override SqlBoolean Deveel.Data.Types.NumericType.IsSmallerOrEqualThan ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 468 of file NumericType.cs.

468  {
469  if (!(a is SqlNumber) ||
470  !(b is SqlNumber))
471  throw new ArgumentException();
472 
473  if (b.IsNull)
474  return SqlBoolean.Null;
475 
476  if (a.IsNull)
477  return SqlBoolean.Null;
478 
479  var num1 = (SqlNumber) a;
480  var num2 = (SqlNumber) b;
481 
482  return num1 <= num2;
483  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override SqlBoolean Deveel.Data.Types.NumericType.IsSmallerThan ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 434 of file NumericType.cs.

434  {
435  if (!(a is SqlNumber) ||
436  !(b is SqlNumber))
437  throw new ArgumentException();
438 
439  if (b.IsNull)
440  return SqlBoolean.Null;
441 
442  if (a.IsNull)
443  return SqlBoolean.Null;
444 
445  var num1 = (SqlNumber) a;
446  var num2 = (SqlNumber) b;
447 
448  return num1 < num2;
449  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.NumericType.Modulus ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 417 of file NumericType.cs.

417  {
418  if (!(a is SqlNumber) ||
419  !(b is SqlNumber))
420  throw new ArgumentException();
421 
422  if (b.IsNull)
423  return SqlNumber.Null;
424 
425  if (a.IsNull)
426  return a;
427 
428  var num1 = (SqlNumber) a;
429  var num2 = (SqlNumber) b;
430 
431  return num1.Modulo(num2);
432  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.NumericType.Multiply ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 384 of file NumericType.cs.

384  {
385  if (!(a is SqlNumber) ||
386  !(b is SqlNumber))
387  throw new ArgumentException();
388  if (b.IsNull)
389  return SqlNumber.Null;
390 
391  if (a.IsNull)
392  return a;
393 
394  var num1 = (SqlNumber) a;
395  var num2 = (SqlNumber) b;
396 
397  return num1.Multiply(num2);
398  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.NumericType.Negate ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 523 of file NumericType.cs.

523  {
524  if (!(value is SqlNumber))
525  throw new ArgumentException();
526 
527  var num = (SqlNumber) value;
528 
529  if (num.IsNull)
530  return num;
531 
532  return num.Negate();
533  }
override ISqlObject Deveel.Data.Types.NumericType.Or ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 593 of file NumericType.cs.

593  {
594  if (!(a is SqlNumber) ||
595  !(b is SqlNumber))
596  throw new ArgumentException();
597 
598  if (b.IsNull)
599  return SqlNumber.Null;
600 
601  if (a.IsNull)
602  return a;
603 
604  var num1 = (SqlNumber) a;
605  var num2 = (SqlNumber) b;
606 
607  return num1.Or(num2);
608  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.NumericType.Reverse ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 535 of file NumericType.cs.

535  {
536  if (!(value is SqlNumber))
537  throw new ArgumentException();
538 
539  var num = (SqlNumber)value;
540 
541  if (num.IsNull)
542  return num;
543 
544  return num.Not();
545  }
override void Deveel.Data.Types.NumericType.SerializeObject ( Stream  stream,
ISqlObject  obj 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 610 of file NumericType.cs.

610  {
611  var writer = new BinaryWriter(stream);
612 
613  if (obj is SqlNull) {
614  writer.Write((byte)0);
615  } else {
616  var number = (SqlNumber) obj;
617  if (obj.IsNull) {
618  writer.Write((byte) 0);
619  } else if (number.CanBeInt32) {
620  writer.Write((byte) 1);
621  writer.Write(number.ToInt32());
622  } else if (number.CanBeInt64) {
623  writer.Write((byte) 2);
624  writer.Write(number.ToInt64());
625  } else {
626  var bytes = number.ToByteArray();
627  writer.Write((byte) 3);
628  writer.Write(number.Precision);
629  writer.Write(number.Scale);
630  writer.Write(bytes.Length);
631  writer.Write(bytes);
632  }
633  }
634  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.NumericType.Subtract ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 358 of file NumericType.cs.

358  {
359  if (!(a is SqlNumber))
360  throw new ArgumentException();
361  if (b is SqlNull || b.IsNull)
362  return SqlNumber.Null;
363 
364  var num1 = (SqlNumber) a;
365  SqlNumber num2;
366 
367  if (b is SqlBoolean) {
368  if ((SqlBoolean) b) {
369  num2 = SqlNumber.One;
370  } else if (!(SqlBoolean) b) {
371  num2 = SqlNumber.Zero;
372  } else {
373  num2 = SqlNumber.Null;
374  }
375  } else if (b is SqlNumber) {
376  num2 = (SqlNumber) b;
377  } else {
378  throw new ArgumentException();
379  }
380 
381  return num1.Subtract(num2);
382  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
static readonly SqlNumber Zero
Definition: SqlNumber.cs:29
static readonly SqlNumber Null
Definition: SqlNumber.cs:31
static readonly SqlNumber One
Definition: SqlNumber.cs:30
static SqlDateTime Deveel.Data.Types.NumericType.ToDate ( long  time)
inlinestaticprivate

Definition at line 210 of file NumericType.cs.

210  {
211  return new SqlDateTime(time);
212  }
override string Deveel.Data.Types.NumericType.ToString ( )
inline

Definition at line 287 of file NumericType.cs.

287  {
288  var sb = new StringBuilder(Name);
289  if (Size != -1) {
290  sb.Append('(');
291  sb.Append(Size);
292  if (Scale > 0) {
293  sb.Append(',');
294  sb.Append(Scale);
295  }
296 
297  sb.Append(')');
298  }
299  return sb.ToString();
300  }
string Name
Gets the name of the data-type that is used to resolve it within the context.
Definition: SqlType.cs:75
override ISqlObject Deveel.Data.Types.NumericType.UnaryPlus ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 547 of file NumericType.cs.

547  {
548  if (!(value is SqlNumber))
549  throw new ArgumentException();
550 
551  var num = (SqlNumber)value;
552 
553  if (num.IsNull)
554  return num;
555 
556  return num.Plus();
557  }
override SqlType Deveel.Data.Types.NumericType.Wider ( SqlType  otherType)
inlinevirtual

Gets the one data-type between this and the other one given that handles the wider range of values.

Parameters
otherTypeThe other type to verify.

This is very important for operations and functions, when operating on objects with comparable but different data-types, to ensure the result of the operation will be capable to handle the final value.

By default, this method returns this instance, as it is not able to dynamically define the wider type.

Returns
Returns this type if it handles a wider range of values or otherType other type given otherwise.

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 138 of file NumericType.cs.

138  {
139  SqlTypeCode t1SqlType = TypeCode;
140  SqlTypeCode t2SqlType = otherType.TypeCode;
141  if (t1SqlType == SqlTypeCode.Decimal) {
142  return this;
143  }
144  if (t2SqlType == SqlTypeCode.Decimal) {
145  return otherType;
146  }
147  if (t1SqlType == SqlTypeCode.Numeric) {
148  return this;
149  }
150  if (t2SqlType == SqlTypeCode.Numeric) {
151  return otherType;
152  }
153 
154  if (t1SqlType == SqlTypeCode.Bit) {
155  return otherType; // It can't be any smaller than a Bit
156  }
157  if (t2SqlType == SqlTypeCode.Bit) {
158  return this;
159  }
160 
161  int t1IntSize = GetIntSize(t1SqlType);
162  int t2IntSize = GetIntSize(t2SqlType);
163  if (t1IntSize > 0 && t2IntSize > 0) {
164  // Both are int types, use the largest size
165  return (t1IntSize > t2IntSize) ? this : otherType;
166  }
167 
168  int t1FloatSize = GetFloatSize(t1SqlType);
169  int t2FloatSize = GetFloatSize(t2SqlType);
170  if (t1FloatSize > 0 && t2FloatSize > 0) {
171  // Both are floating types, use the largest size
172  return (t1FloatSize > t2FloatSize) ? this : otherType;
173  }
174 
175  if (t1FloatSize > t2IntSize) {
176  return this;
177  }
178  if (t2FloatSize > t1IntSize) {
179  return otherType;
180  }
181  if (t1IntSize >= t2FloatSize || t2IntSize >= t1FloatSize) {
182  // Must be a long (8 bytes) and a real (4 bytes), widen to a double
183  return new NumericType(SqlTypeCode.Double, 8, 0);
184  }
185 
186  // NOTREACHED - can't get here, the last three if statements cover
187  // all possibilities.
188  throw new InvalidOperationException("Widest type error.");
189  }
NumericType(SqlTypeCode typeCode, int size, byte scale)
Definition: NumericType.cs:28
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
static int GetIntSize(SqlTypeCode sqlType)
Definition: NumericType.cs:110
static int GetFloatSize(SqlTypeCode sqlType)
Definition: NumericType.cs:126
override ISqlObject Deveel.Data.Types.NumericType.XOr ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 559 of file NumericType.cs.

559  {
560  if (!(a is SqlNumber) ||
561  !(b is SqlNumber))
562  throw new ArgumentException();
563 
564  if (b.IsNull)
565  return SqlNumber.Null;
566 
567  if (a.IsNull)
568  return a;
569 
570  var num1 = (SqlNumber) a;
571  var num2 = (SqlNumber) b;
572 
573  return num1.XOr(num2);
574  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28

Property Documentation

override bool Deveel.Data.Types.NumericType.IsStorable
get

Definition at line 53 of file NumericType.cs.

byte Deveel.Data.Types.NumericType.Scale
getprivate set

Definition at line 51 of file NumericType.cs.

int Deveel.Data.Types.NumericType.Size
getprivate set

Definition at line 49 of file NumericType.cs.


The documentation for this class was generated from the following file: