Example #1
0
File: Update.cs Project: bazer/Modl
        protected Sql GetWith(Sql sql, string paramPrefix)
        {
            int length = withList.Count;
            if (length == 0)
                return sql;

            int i = 0;
            foreach (var with in withList)
            {
                DatabaseProvider.GetParameter(sql, paramPrefix + "v" + i, with.Value);
                DatabaseProvider.GetParameterComparison(sql, with.Key, Relation.Equal, paramPrefix + "v" + i);

                if (i + 1 < length)
                    sql.AddText(",");

                i++;
            }

            return sql;

            //int i = 0, j = 0;

            //return sql
            //    .Join(",", withList.Select(x => DatabaseProvider.GetParameterComparison(x.Key, Relation.Equal, paramPrefix + "v" + i++)).ToArray())
            //    .AddParameters(withList.Select(x => DatabaseProvider.GetParameter(paramPrefix + "v" + j++, x.Value)).ToArray());

            //return new Sql(
            //    string.Join(",", withList.Select(x => DatabaseProvider.GetParameterComparison(x.Key, Relation.Equal, paramPrefix + "v" + i++))),
            //    withList.Select(x => DatabaseProvider.GetParameter(paramPrefix + "v" + j++, x.Value)).ToArray());
        }
Example #2
0
File: Insert.cs Project: bazer/Modl
        protected Sql GetWith(Sql sql, string paramPrefix)
        {
            int length = withList.Count;
            if (length == 0)
                return sql.AddFormat("VALUES (NULL)");

            sql.AddFormat("({0}) VALUES (", string.Join(",", withList.Keys));

            int i = 0;
            foreach (var with in withList)
            {
                DatabaseProvider.GetParameter(sql, paramPrefix + "v" + i, with.Value);
                DatabaseProvider.GetParameterValue(sql, paramPrefix + "v" + i);

                if (i + 1 < length)
                    sql.AddText(",");
                else
                    sql.AddText(")");

                i++;
            }

            return sql;

            //int i = 0, j = 0;

            //return sql
            //    .AddFormat("({0}) VALUES ({1})",
            //        string.Join(",", withList.Keys),
            //        string.Join(",", withList.Values.Select(x => DatabaseProvider.GetParameterValue(paramPrefix + "v" + i++))))
            //    .AddParameters(withList.Select(x => DatabaseProvider.GetParameter(paramPrefix + "v" + j++, x.Value)).ToArray());

            //return new Sql(
            //    string.Format("({0}) VALUES ({1})",
            //        string.Join(",", withList.Keys),
            //        string.Join(",", withList.Values.Select(x => DatabaseProvider.GetParameterValue(paramPrefix + "v" + i++)))),
            //    withList.Select(x => DatabaseProvider.GetParameter(paramPrefix + "v" + j++, x.Value)).ToArray());

            //return string.Format("({0}) VALUES ({1})",
            //    string.Join(",", withList.Keys),
            //    string.Join(",", withList.Values.Select(x => "'" + x + "'"))
            //);
        }
Example #3
0
 internal abstract Sql GetParameterValue(Sql sql, string key);
Example #4
0
 internal abstract Sql GetParameterComparison(Sql sql, string field, Relation relation, string key);
Example #5
0
 internal abstract Sql GetParameter(Sql sql, string key, object value);
Example #6
0
 internal override Sql GetParameterValue(Sql sql, string key)
 {
     return sql.AddFormat("@{0}", key);
 }
Example #7
0
 internal override Sql GetParameterComparison(Sql sql, string field, Relation relation, string key)
 {
     return sql.AddFormat("{0} {1} @{2}", field, relation.ToSql(), key);
 }
Example #8
0
 internal override Sql GetParameter(Sql sql, string key, object value)
 {
     return sql.AddParameters(new SqlCeParameter("@" + key, value ?? DBNull.Value));
 }
Example #9
0
 public abstract Sql GetCommandString(Sql sql, string prefix, int number);
Example #10
0
 public abstract Sql GetCommandParameter(Sql sql, string prefix, int number);