示例#1
0
        public static string GetMySqlColumnSqlString(EDataType dataType, string attributeName, int length)
        {
            string retval;
            var    sqlDbType = EDataTypeUtils.ToSqlDbType(dataType);

            switch (sqlDbType)
            {
            case SqlDbType.Char:
                retval = $"{attributeName} VARCHAR({length})";
                break;

            case SqlDbType.DateTime:
                retval = $"{attributeName} DATETIME";
                break;

            case SqlDbType.Decimal:
                retval = $"{attributeName} DECIMAL(18, 2)";
                break;

            case SqlDbType.Float:
                retval = $"{attributeName} FLOAT(18, 2)";
                break;

            case SqlDbType.Int:
                retval = $"{attributeName} INT";
                break;

            case SqlDbType.NChar:
                retval = $"{attributeName} VARCHAR({length})";
                break;

            case SqlDbType.NText:
                retval = $"{attributeName} LONGTEXT";
                break;

            case SqlDbType.NVarChar:
                retval = $"{attributeName} VARCHAR({length})";
                break;

            case SqlDbType.Text:
                retval = $"{attributeName} LONGTEXT";
                break;

            case SqlDbType.VarChar:
                retval = $"{attributeName} VARCHAR({length})";
                break;

            default:
                retval = $"{attributeName} VARCHAR({length})";
                break;
            }
            return(retval);
        }
示例#2
0
        public static IDbDataParameter GetIDbDataParameter(string parameterName, EDataType dataType, int size)
        {
            IDbDataParameter parameter;

            if (WebConfigUtils.IsMySql)
            {
                parameter = new MySqlParameter(parameterName, EDataTypeUtils.ToMySqlDbType(dataType), size);
            }
            else
            {
                parameter = new SqlParameter(parameterName, EDataTypeUtils.ToSqlDbType(dataType), size);
            }

            return(parameter);
        }
示例#3
0
        public static string GetSqlServerColumnSqlString(EDataType dataType, string attributeName, int length)
        {
            var retval    = string.Empty;
            var sqlDbType = EDataTypeUtils.ToSqlDbType(dataType);

            switch (sqlDbType)
            {
            case SqlDbType.BigInt:
                retval = $"[{attributeName}] [bigint]";
                break;

            case SqlDbType.Binary:
                retval = $"[{attributeName}] [binary] ({length})";
                break;

            case SqlDbType.Bit:
                retval = $"[{attributeName}] [bit]";
                break;

            case SqlDbType.Char:
                retval = $"[{attributeName}] [char] ({length})";
                break;

            case SqlDbType.DateTime:
                retval = $"[{attributeName}] [datetime]";
                break;

            case SqlDbType.Decimal:
                retval = $"[{attributeName}] [decimal] (18, 2)";
                break;

            case SqlDbType.Float:
                retval = $"[{attributeName}] [float]";
                break;

            case SqlDbType.Image:
                retval = $"[{attributeName}] [image]";
                break;

            case SqlDbType.Int:
                retval = $"[{attributeName}] [int]";
                break;

            case SqlDbType.Money:
                retval = $"[{attributeName}] [money]";
                break;

            case SqlDbType.NChar:
                retval = $"[{attributeName}] [nchar] ({length})";
                break;

            case SqlDbType.NText:
                retval = $"[{attributeName}] [ntext]";
                break;

            case SqlDbType.NVarChar:
                retval = $"[{attributeName}] [nvarchar] ({length})";
                break;

            case SqlDbType.Real:
                retval = $"[{attributeName}] [real]";
                break;

            case SqlDbType.SmallDateTime:
                retval = $"[{attributeName}] [smalldatetime]";
                break;

            case SqlDbType.SmallInt:
                retval = $"[{attributeName}] [smallint]";
                break;

            case SqlDbType.SmallMoney:
                retval = $"[{attributeName}] [smallmoney]";
                break;

            case SqlDbType.Text:
                retval = $"[{attributeName}] [text]";
                break;

            case SqlDbType.Timestamp:
                retval = $"[{attributeName}] [timestamp]";
                break;

            case SqlDbType.TinyInt:
                retval = $"[{attributeName}] [tinyint]";
                break;

            case SqlDbType.VarBinary:
                retval = $"[{attributeName}] [varbinary] ({length})";
                break;

            case SqlDbType.VarChar:
                retval = $"[{attributeName}] [varchar] ({length})";
                break;
            }
            retval += " NULL";
            return(retval);
        }