public void Test_Param()
        {
            var text = new DbParam<string>() { Value = "xxx" };
            var query = Db<DB>.Sql(db =>
                Select(new SelectData
                {
                    Name = db.tbl_staff.name + text,
                }).
                From(db.tbl_staff));

            var datas = _connection.Query(query).ToList();
            Assert.IsTrue(0 < datas.Count);
            AssertEx.AreEqual(query, _connection,
@"SELECT
	(tbl_staff.name) " + _connection.GetStringAddExp() + @" (@text) AS Name
FROM tbl_staff",
 new DbParams() { { "@text", new DbParam() { Value = "xxx" } } });
        }
        public void Test_Param_Setting()
        {
            var param = new DbParam<string>()
            {        
                Value = "xxx",
                DbType = DbType.AnsiString,
                Direction = ParameterDirection.InputOutput,
                SourceColumn = "aaa",
                SourceVersion = DataRowVersion.Original,
                Precision = 10,
                Scale = 20,
                Size = 30,
            };

            var query = Db<DB>.Sql(db =>
                Select(new SelectData
                {
                    Name = db.tbl_staff.name + param,
                }).
                From(db.tbl_staff));

            //check parameter only.
            AssertEx.AreEqual(query, _connection,
@"SELECT
	(tbl_staff.name) " + _connection.GetStringAddExp() + @" (@param) AS Name
FROM tbl_staff",
 new DbParams() { { "@param", new DbParam()
 {
    Value = "xxx",
    DbType = DbType.AnsiString,
    Direction = ParameterDirection.InputOutput,
    SourceColumn = "aaa",
    SourceVersion = DataRowVersion.Original,
    Precision = 10,
    Scale = 20,
    Size = 30,
 } } });
        }
Beispiel #3
0
        static IDbDataParameter CreateParameter(IDbCommand com, string name, DbParam src)
        {
            var dst = com.CreateParameter();
            dst.ParameterName = name;
            dst.Value = src.Value;

            if (src.DbType != null) dst.DbType = src.DbType.Value;
            if (src.Direction != null) dst.Direction = src.Direction.Value;
            if (src.SourceColumn != null) dst.SourceColumn = src.SourceColumn;
            if (src.SourceVersion != null) dst.SourceVersion = src.SourceVersion.Value;
            if (src.Precision != null) dst.Precision = src.Precision.Value;
            if (src.Scale != null) dst.Scale = src.Scale.Value;
            if (src.Size != null) dst.Size = src.Size.Value;

            return dst;
        }