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()); }
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 + "'")) //); }
internal abstract Sql GetParameterValue(Sql sql, string key);
internal abstract Sql GetParameterComparison(Sql sql, string field, Relation relation, string key);
internal abstract Sql GetParameter(Sql sql, string key, object value);
internal override Sql GetParameterValue(Sql sql, string key) { return sql.AddFormat("@{0}", key); }
internal override Sql GetParameterComparison(Sql sql, string field, Relation relation, string key) { return sql.AddFormat("{0} {1} @{2}", field, relation.ToSql(), key); }
internal override Sql GetParameter(Sql sql, string key, object value) { return sql.AddParameters(new SqlCeParameter("@" + key, value ?? DBNull.Value)); }
public abstract Sql GetCommandString(Sql sql, string prefix, int number);
public abstract Sql GetCommandParameter(Sql sql, string prefix, int number);