18 using System.Collections.Generic;
27 namespace Deveel.Data.Types {
44 : this(sqlType.ToString().ToUpperInvariant(), sqlType) {
75 public string Name {
get;
private set; }
100 public virtual bool IsIndexable {
107 public bool IsPrimitive {
108 get {
return IsPrimitiveType(TypeCode); }
115 public virtual bool IsStorable {
116 get {
return false; }
181 if (Equals(destType))
185 throw new NotSupportedException();
189 throw new NotSupportedException();
220 return a.CompareTo(b) == 0;
227 return a.CompareTo(b) != 0;
234 return a.CompareTo(b) > 0;
241 return a.CompareTo(b) < 0;
248 return a.CompareTo(b) >= 0;
255 return a.CompareTo(b) <= 0;
280 data.
SetValue(
"TypeCode", (
int) TypeCode);
322 return Parse(null, s);
342 var result = sqlCompiler.
Parse(s);
343 if (result.HasErrors)
348 if (context == null && !node.IsPrimitive)
349 throw new NotSupportedException(
String.Format(
"The type '{0}' is not primitive and no resolve context is provided.", node.TypeName));
353 throw new FormatException(
"Unable to parse the given string to a valid data type.");
360 throw new NotSupportedException();
369 return ((IComparable) x).CompareTo(y);
373 public override bool Equals(
object obj) {
375 if (dataType == null)
378 return Equals(dataType);
383 return TypeCode.GetHashCode();
400 throw new NotSupportedException(
String.Format(
"Type {0} cannot serialize object of type {1}.", GetType(),
405 throw new NotSupportedException(
String.Format(
"Type {0} cannot deserialize types.", GetType()));
422 throw new NotSupportedException();
426 throw new NotSupportedException();
430 throw new NotSupportedException(
String.Format(
"SQL Type {0} cannot be created from a large object.", TypeCode));
438 throw new NotSupportedException(
String.Format(
"The type {0} does not support runtime object conversion.", ToString()));
446 return Resolve(typeCode, meta, null);
450 return Resolve(typeCode, typeCode.ToString().ToUpperInvariant(), meta, resolver);
458 return Resolve(typeCode, name, meta, null);
466 return Resolve(name, meta, null);
470 var typeCode = ResolveTypeCode(name);
471 return Resolve(typeCode, name, meta, resolver);
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
virtual ISqlObject XOr(ISqlObject x, ISqlObject y)
static readonly ISqlParser DataType
void GetData(SerializeData data)
static SqlType Resolve(SqlTypeCode typeCode, DataTypeMeta[] meta, ITypeResolver resolver)
A long string in the system.
virtual ISqlObject Subtract(ISqlObject a, ISqlObject b)
Defines a referenced object that can be accessed on a multi-phase level.
static SqlType Resolve(SqlTypeCode typeCode, string name, DataTypeMeta[] meta)
virtual ISqlObject UnaryPlus(ISqlObject value)
static SqlType Resolve(string name, DataTypeMeta[] meta, ITypeResolver resolver)
virtual SqlBoolean IsNotEqualTo(ISqlObject a, ISqlObject b)
static SqlType Resolve(SqlTypeCode typeCode, string typeName, DataTypeMeta[] metadata, ITypeResolver resolver)
virtual ISqlObject Divide(ISqlObject a, ISqlObject b)
virtual ISqlObject Negate(ISqlObject value)
virtual bool IsComparable(SqlType type)
Verifies if a given SqlType is comparable to this data-type.
SqlType(SqlTypeCode sqlType)
Constructs the SqlType for the given specific SQL TYPE.
static SqlTypeCode ResolveTypeCode(string name)
void SetValue(string key, Type type, object value)
virtual bool Equals(SqlType other)
static SqlType Build(ITypeResolver resolver, ISqlNode sqlNode)
static SqlType Resolve(string name, DataTypeMeta[] meta)
static bool IsPrimitiveType(SqlTypeCode typeCode)
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
SqlType(string name, SqlTypeCode typeCode)
Constructs the SqlType for the given specific SQL TYPE and a given name.
bool IsNull
Gets a boolean value indicating if the object is NULL.
virtual SqlBoolean IsGreaterOrEqualThan(ISqlObject a, ISqlObject b)
virtual ISqlObject Multiply(ISqlObject a, ISqlObject b)
virtual SqlBoolean IsSmallerOrEqualThan(ISqlObject a, ISqlObject b)
static readonly SqlNull Value
static SqlType Resolve(SqlTypeCode typeCode, DataTypeMeta[] meta)
Defines the contract for a valid SQL Object
virtual SqlBoolean IsSmallerThan(ISqlObject a, ISqlObject b)
virtual int GetCacheUsage(ISqlObject value)
virtual int ColumnSizeOf(ISqlObject obj)
virtual bool IsCacheable(ISqlObject value)
static SqlType Resolve(SqlTypeCode typeCode, string name)
override int GetHashCode()
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
virtual ISqlObject Reverse(ISqlObject value)
virtual SqlType Wider(SqlType otherType)
Gets the one data-type between this and the other one given that handles the wider range of values...
virtual ISqlObject Add(ISqlObject a, ISqlObject b)
virtual object ConvertTo(ISqlObject obj, Type destType)
Defines the properties of a specific SQL Type and handles the values compatible.
static SqlTypeCode ResolveTypeCode(string typeName)
virtual ISqlObject And(ISqlObject a, ISqlObject b)
override string ToString()
virtual void GetData(SerializeData data)
SqlParseResult Parse(string input)
Analyzes and parses the input and results an object that describes the parsed nodes in a tree that ca...
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
bool IsComparableTo(ISqlObject other)
Checks if the current object is comparable with the given one.
virtual ISqlObject DeserializeObject(Stream stream)
virtual ISqlObject Or(ISqlObject a, ISqlObject b)
static SqlType Parse(IContext context, string s)
Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent...
virtual void SerializeObject(Stream stream, ISqlObject obj)
virtual ISqlObject Modulus(ISqlObject a, ISqlObject b)
virtual SqlBoolean IsEqualTo(ISqlObject a, ISqlObject b)
static SqlType Resolve(SqlTypeCode typeCode)
virtual ISqlObject CreateFrom(object value)
virtual bool CanCastTo(SqlType destType)
Verifies if this type can cast any value to the given SqlType.
static bool IsPrimitive(SqlTypeCode sqlType)
Describes the information of a data type as found in a SQL string.
An error that occurs when compiling a input string into a SQL object.
virtual int Compare(ISqlObject x, ISqlObject y)
virtual Type GetRuntimeType()
virtual DataObject CastTo(DataObject value, SqlType destType)
Converts the given object value to a SqlType specified.
string GetString(string key)
virtual SqlBoolean IsGreatherThan(ISqlObject a, ISqlObject b)
virtual Type GetObjectType()
override bool Equals(object obj)
static SqlType Resolve(SqlTypeCode typeCode, string name, DataTypeMeta[] meta, ITypeResolver resolver)
static SqlType Parse(string s)
Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent...
static SqlType Resolve(string name)
virtual ISqlObject CreateFromLargeObject(ILargeObject objRef)