public void Test(GeneralDbType inpuType, SqlDbType expectedType)
        {
            // Arrange

            // Act
            var result = SqlClientConnManager.MapGeneralDbTypeToSqlDbType(inpuType);

            // Assert
            Assert.AreEqual(expectedType, result);
        }
        public void Test(GeneralDbType inpuType, NpgsqlDbType expectedType)
        {
            // Arrange

            // Act
            var result = PostgresConnManager.MapGeneralDbTypeToNpgsqlDbType(inpuType);

            // Assert
            Assert.AreEqual(expectedType, result);
        }
コード例 #3
0
        /// <summary>
        /// Map the general database parameter data type to it's SQLClient relative
        /// </summary>
        /// <param name="dataType">Gernal database data type</param>
        /// <returns>SQql data type</returns>
        public static SqlDbType MapGeneralDbTypeToSqlDbType(GeneralDbType dataType)
        {
            var t = dataType.ToString().Replace("GeneralDbType", "SqlDbType");

            var sucess = Enum.TryParse(t, out SqlDbType sqlDataType);

            if (sucess)
            {
                return(sqlDataType);
            }

            throw new ArgumentException($"Type not implemented: {dataType}");
        }
        /// <summary>
        /// Map the general database parameter data type to it's SQLClient relative
        /// </summary>
        /// <param name="dataType">Gernal database data type</param>
        /// <returns>Npgsql data type</returns>
        public static NpgsqlDbType MapGeneralDbTypeToNpgsqlDbType(GeneralDbType dataType)
        {
            switch (dataType)
            {
            case GeneralDbType.BigInt:
                return(NpgsqlDbType.Bigint);

            //case GeneralDbType.Binary:
            //    break;
            case GeneralDbType.Bit:
                return(NpgsqlDbType.Bit);

            case GeneralDbType.Char:
                return(NpgsqlDbType.Char);

            case GeneralDbType.DateTime:
                return(NpgsqlDbType.Date);

            case GeneralDbType.Decimal:
                return(NpgsqlDbType.Numeric);

            case GeneralDbType.Float:
                return(NpgsqlDbType.Double);

            //case GeneralDbType.Image:
            //    break;
            case GeneralDbType.Int:
                return(NpgsqlDbType.Integer);

            case GeneralDbType.Money:
                return(NpgsqlDbType.Money);

            case GeneralDbType.NChar:
                return(NpgsqlDbType.Char);

            case GeneralDbType.NText:
                return(NpgsqlDbType.Text);

            case GeneralDbType.NVarChar:
                return(NpgsqlDbType.Text);

            case GeneralDbType.Real:
                return(NpgsqlDbType.Double);

            case GeneralDbType.UniqueIdentifier:
                return(NpgsqlDbType.Uuid);

            case GeneralDbType.SmallDateTime:
                return(NpgsqlDbType.Date);

            case GeneralDbType.SmallInt:
                return(NpgsqlDbType.Smallint);

            case GeneralDbType.SmallMoney:
                return(NpgsqlDbType.Money);

            case GeneralDbType.Text:
                return(NpgsqlDbType.Text);

            case GeneralDbType.Timestamp:
                return(NpgsqlDbType.Timestamp);

            case GeneralDbType.TinyInt:
                return(NpgsqlDbType.Smallint);

            //case GeneralDbType.VarBinary:
            //    break;
            case GeneralDbType.VarChar:
                return(NpgsqlDbType.Varchar);

            //case GeneralDbType.Variant:
            //    break;
            case GeneralDbType.Xml:
                return(NpgsqlDbType.Text);

            //case GeneralDbType.Udt:
            //    break;
            //case GeneralDbType.Structured:
            //    break;
            case GeneralDbType.Date:
                return(NpgsqlDbType.Date);

            case GeneralDbType.Time:
                return(NpgsqlDbType.Date);

            case GeneralDbType.DateTime2:
                return(NpgsqlDbType.Date);

            case GeneralDbType.DateTimeOffset:
                return(NpgsqlDbType.TimeTz);

            default:
                throw new ArgumentOutOfRangeException(nameof(dataType), dataType, null);
            }
        }
        /// <summary>
        /// Get a parameter for the provided command
        /// </summary>
        /// <param name="cmd">Current command type</param>
        /// <param name="parameterName">Name of the parameter</param>
        /// <param name="dataType">General database data typeof the parameter</param>
        /// <returns>Parameter object to set value for</returns>
        public override DbParameter GetParameter(DbCommand cmd, string parameterName, GeneralDbType dataType)
        {
            var sqlCmd = (NpgsqlCommand)cmd;

            var sqlType = MapGeneralDbTypeToNpgsqlDbType(dataType);

            var p = new NpgsqlParameter(parameterName, sqlType);

            sqlCmd.Parameters.Add(p);

            return(p);
        }
コード例 #6
0
 /// <summary>
 /// Get a parameter for the provided command
 /// </summary>
 /// <param name="cmd">Current command type</param>
 /// <param name="parameterName">Name of the parameter</param>
 /// <param name="dataType">General database data typeof the parameter</param>
 /// <returns>Parameter object to set value for</returns>
 public virtual DbParameter GetParameter(DbCommand cmd, string parameterName, GeneralDbType dataType)
 {
     throw new DbConnException(NotImplementedMessage, DbConnErrorCode.ERC_NOTIMPLEMENTED);
 }