Class DataTypeConverter

This class provides static methods and an implementation of IDataTypeConverter that converts various sql data types into the right database specific database or into a .NET data type.

Inheritance
System.Object
DataTypeConverter
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ETLBox.Helper
Assembly: ETLBox.dll
Syntax
    public class DataTypeConverter : IDataTypeConverter

Methods

GetClrType(DbType)

Declaration
    public static Type GetClrType(DbType dbType)
Parameters
TypeNameDescription
System.Data.DbTypedbType
Returns
TypeDescription
System.Type

GetDatabaseType(Type, ConnectionManagerType)

Declaration
    public static string GetDatabaseType(Type clrType, ConnectionManagerType connectionType)
Parameters
TypeNameDescription
System.TypeclrType
ConnectionManagerTypeconnectionType
Returns
TypeDescription
System.String

GetDBType(String)

Returns the ADO.NET System.Data.DbType object for a specific sql type. E.g. the method would return the System.Data.DbType.String for the sql type 'CHAR(10)'

Declaration
    public static DbType GetDBType(string dbSpecificTypeName)
Parameters
TypeNameDescription
System.StringdbSpecificTypeName

The sql specific data type name

Returns
TypeDescription
System.Data.DbType

The corresponding ADO .NET database type

GetDBType(Type)

Declaration
    public static DbType GetDBType(Type clrType)
Parameters
TypeNameDescription
System.TypeclrType
Returns
TypeDescription
System.Data.DbType

GetStringLengthFromCharString(String)

Returns the string length that a sql char datatype has in it's definition. E.g. VARCHAR(40) would return 40, NVARCHAR2 ( 2 ) returns 2

Declaration
    public static int GetStringLengthFromCharString(string value)
Parameters
TypeNameDescription
System.Stringvalue

A sql character data type

Returns
TypeDescription
System.Int32

The string length defined in the data type - 0 if nothing could be found

GetTypeObject(String)

Returns the .NET type object for a specific sql type. E.g. the method would return the .NET type string for the sql type 'CHAR(10)'

Declaration
    public static Type GetTypeObject(string dbSpecificTypeName)
Parameters
TypeNameDescription
System.StringdbSpecificTypeName

The sql specific data type name

Returns
TypeDescription
System.Type

The corresponding .NET data type

TryConvertAliasName(String, ConnectionManagerType)

Converts a data type alias name (e.g. an alias name like "varchar(10)" ) to the original database type name ("character varying").

Declaration
    public static string TryConvertAliasName(string dataTypeName, ConnectionManagerType connectionType)
Parameters
TypeNameDescription
System.StringdataTypeName

The database alias type name

ConnectionManagerTypeconnectionType

Which database (e.g. Postgres, MySql, ...)

Returns
TypeDescription
System.String

The type name converted to an original database type name

TryConvertDbDataType(String, ConnectionManagerType)

Tries to convert the data type from the TableColumn into a database specific type.

Declaration
    public string TryConvertDbDataType(string dataTypeName, ConnectionManagerType connectionType)
Parameters
TypeNameDescription
System.StringdataTypeName

The specific type name from a table column

ConnectionManagerTypeconnectionType

The database connection type

Returns
TypeDescription
System.String

The type used in the CREATE TABLE statement

TryGetDbSpecificType(String, ConnectionManagerType)

Tries to convert the data type into a database specific type. E.g. the data type 'INT' would be converted to 'INTEGER' for SQLite connections.

Declaration
    public static string TryGetDbSpecificType(string dataTypeName, ConnectionManagerType connectionType)
Parameters
TypeNameDescription
System.StringdataTypeName

A data type name

ConnectionManagerTypeconnectionType

The database connection type

Returns
TypeDescription
System.String

The converted database specific type name

Implements