18 using System.Globalization;
23 namespace Deveel.Data.Types {
51 return String(sqlType, maxSize, (CultureInfo) null);
59 return String(sqlType, maxSize, Encoding.Unicode, locale);
67 return String(sqlType, maxSize, encoding, null);
75 return new StringType(sqlType, maxSize, encoding, locale);
95 return Numeric(sqlType, size, 0);
171 return Binary(sqlType, -1);
193 if (
System.String.IsNullOrEmpty(name))
196 if (
System.String.Equals(
"long varchar", name, StringComparison.OrdinalIgnoreCase))
197 name =
"longvarchar";
198 if (
System.String.Equals(
"long varbinary", name, StringComparison.OrdinalIgnoreCase))
199 name =
"longvarbinary";
201 if (name.EndsWith(
"%TYPE", StringComparison.OrdinalIgnoreCase) ||
202 name.EndsWith(
"%ROWTYPE", StringComparison.OrdinalIgnoreCase))
205 if (name.Equals(
"NUMERIC", StringComparison.OrdinalIgnoreCase) ||
206 name.Equals(
"STRING", StringComparison.OrdinalIgnoreCase) ||
207 name.Equals(
"DATE", StringComparison.OrdinalIgnoreCase) ||
208 name.Equals(
"NULL", StringComparison.OrdinalIgnoreCase) ||
209 name.Equals(
"BOOLEAN", StringComparison.OrdinalIgnoreCase) ||
210 name.Equals(
"BINARY", StringComparison.OrdinalIgnoreCase))
213 if (name.Equals(
"BIT", StringComparison.OrdinalIgnoreCase) ||
214 name.Equals(
"BOOLEAN", StringComparison.OrdinalIgnoreCase))
217 if (name.Equals(
"TINYINT", StringComparison.OrdinalIgnoreCase) ||
218 name.Equals(
"SMALLINT", StringComparison.OrdinalIgnoreCase) ||
219 name.Equals(
"INTEGER", StringComparison.OrdinalIgnoreCase) ||
220 name.Equals(
"INT", StringComparison.OrdinalIgnoreCase) ||
221 name.Equals(
"BIGINT", StringComparison.OrdinalIgnoreCase) ||
222 name.Equals(
"REAL", StringComparison.OrdinalIgnoreCase) ||
223 name.Equals(
"FLOAT", StringComparison.OrdinalIgnoreCase) ||
224 name.Equals(
"DOUBLE", StringComparison.OrdinalIgnoreCase) ||
225 name.Equals(
"DECIMAL", StringComparison.OrdinalIgnoreCase))
228 if (name.Equals(
"DATE", StringComparison.OrdinalIgnoreCase) ||
229 name.Equals(
"TIME", StringComparison.OrdinalIgnoreCase) ||
230 name.Equals(
"TIMESTAMP", StringComparison.OrdinalIgnoreCase))
233 if (name.Equals(
"YEAR TO MONTH", StringComparison.OrdinalIgnoreCase) ||
234 name.Equals(
"DAY TO SECOND", StringComparison.OrdinalIgnoreCase) ||
235 name.Equals(
"INTERVAL", StringComparison.OrdinalIgnoreCase))
238 if (name.Equals(
"CHAR", StringComparison.OrdinalIgnoreCase) ||
239 name.Equals(
"VARCHAR", StringComparison.OrdinalIgnoreCase) ||
240 name.Equals(
"LONGVARCHAR", StringComparison.OrdinalIgnoreCase) ||
241 name.Equals(
"CLOB", StringComparison.OrdinalIgnoreCase))
244 if (name.Equals(
"BINARY", StringComparison.OrdinalIgnoreCase) ||
245 name.Equals(
"VARBINARY", StringComparison.OrdinalIgnoreCase) ||
246 name.Equals(
"LONGVARBINARY", StringComparison.OrdinalIgnoreCase) ||
247 name.Equals(
"BLOB", StringComparison.OrdinalIgnoreCase))
254 if (!IsPrimitive(typeName))
257 if (
System.String.Equals(
"long varchar", typeName, StringComparison.OrdinalIgnoreCase))
258 typeName =
"longvarchar";
259 if (
System.String.Equals(
"long varbinary", typeName, StringComparison.OrdinalIgnoreCase))
260 typeName =
"longvarbinary";
266 }
catch (Exception) {
267 throw new ArgumentException(
System.String.Format(
"The name {0} is not a valid SQL type.", typeName));
270 return Resolve(typeCode, typeName, args);
274 if (
System.String.Equals(
"long varchar", typeName, StringComparison.OrdinalIgnoreCase))
275 typeName =
"longvarchar";
276 if (
System.String.Equals(
"long varbinary", typeName, StringComparison.OrdinalIgnoreCase))
277 typeName =
"longvarbinary";
283 }
catch (Exception) {
284 throw new ArgumentException(
System.String.Format(
"The name {0} is not a valid SQL type.", typeName));
287 if (!IsPrimitive(typeCode))
319 var precisionMeta = context.
GetMeta(
"Precision");
320 var scaleMeta = context.
GetMeta(
"Scale");
322 if (precisionMeta == null)
325 if (scaleMeta == null)
326 return Numeric(sqlType, precisionMeta.ToInt32());
328 return Numeric(sqlType, precisionMeta.ToInt32(), (byte) scaleMeta.ToInt32());
339 var maxSizeMeta = context.
GetMeta(
"MaxSize");
340 var localeMeta = context.
GetMeta(
"Locale");
341 var encodingMeta = context.
GetMeta(
"Encoding");
344 CultureInfo locale = null;
345 var encoding = Encoding.Unicode;
347 if (maxSizeMeta != null)
348 maxSize = maxSizeMeta.ToInt32();
349 if (localeMeta != null)
350 locale =
new CultureInfo(localeMeta.Value);
351 if (encodingMeta != null)
352 encoding = Encoding.GetEncoding(encodingMeta.Value);
354 return new StringType(sqlType, maxSize, encoding, locale);
365 var maxSizeMeta = context.
GetMeta(
"MaxSize");
366 if (maxSizeMeta != null)
367 maxSize = maxSizeMeta.
ToInt32();
369 return Binary(sqlType, maxSize);
379 return Null(sqlType);
383 throw new ArgumentException(
"Invalid number of arguments for %ROWTYPE type");
385 var tableNameMeta = context.
GetMeta(
"TableName");
386 if (tableNameMeta == null)
387 throw new ArgumentException();
395 throw new ArgumentException(
"Invalid number of arguments for %TYPE type");
397 var columnNameMeta = context.
GetMeta(
"ColumnName");
398 if (columnNameMeta == null)
399 throw new ArgumentException();
405 throw new ArgumentException(
System.String.Format(
"The SQL type {0} is not primitive.", sqlType));
409 if (type == typeof(
bool))
411 if (type == typeof(
string))
413 if (type == typeof (byte))
415 if (type == typeof (
short))
418 throw new NotSupportedException();
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static StringType String(SqlTypeCode sqlType)
static BinaryType Binary()
static StringType String(SqlTypeCode sqlType, Encoding encoding)
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
static NumericType Numeric(SqlTypeCode sqlType, int size)
static bool IsPrimitive(string name)
A long string in the system.
static SqlType Resolve(string typeName, params DataTypeMeta[] args)
static SqlType Resolve(TypeResolveContext context)
static BooleanType Boolean()
static DateType DateTime(SqlTypeCode sqlType)
A 8-bytes long integer type.
static BooleanType Boolean(SqlTypeCode sqlType)
static BinaryType Binary(int maxSize)
static StringType String(SqlTypeCode sqlType, CultureInfo locale)
static NumericType Integer()
An integer value that can span from 0 to 255.
static ColumnType ColumnType(ObjectName columnName)
Describes the name of an object within a database.
A generic numeric type. This is the main type used by the system to represent numbers.
static NumericType Numeric(int size, byte scale)
static NumericType Numeric(int size)
static StringType String(SqlTypeCode sqlType, int maxSize, Encoding encoding)
static StringType String(SqlTypeCode sqlType, int maxSize)
static DateType TimeStamp()
static StringType String(SqlTypeCode sqlType, int maxSize, CultureInfo locale)
static NumericType Numeric()
static IntervalType Interval(SqlTypeCode sqlType)
static DateType DateTime()
Defines the properties of a specific SQL Type and handles the values compatible.
static RowType RowType(ObjectName tableName)
static NumericType Numeric(SqlTypeCode sqlType)
A single byte that can have only 1 and 0 as values.
static SqlTypeCode ResolveTypeCode(string typeName)
static BinaryType Binary(SqlTypeCode sqlType)
DataTypeMeta GetMeta(string name)
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
static SqlType BigInt(int size)
static StringType String(SqlTypeCode sqlType, Encoding encoding, CultureInfo locale)
static NumericType TinyInt(int size)
static SqlType Resolve(SqlTypeCode sqlType, string typeName, params DataTypeMeta[] args)
static StringType String()
A data type that represents the NULL value of a given SQL data type.
static bool IsPrimitive(SqlTypeCode sqlType)
static NullType Null(SqlTypeCode sqlType)
static BinaryType Binary(SqlTypeCode sqlType, int maxSize)
static StringType String(SqlTypeCode sqlType, int maxSize, Encoding encoding, CultureInfo locale)
static SqlType FromType(Type type)
static NumericType Integer(int size)
static NumericType TinyInt()
static NumericType Numeric(SqlTypeCode sqlType, int size, byte scale)