/// <summary> /// Sql命令进行格式化,把对应的ID={i}转化成对应的ID=? /// </summary> /// <param name="cmd"></param> /// <param name="provider">访问管理器</param> /// <param name="sql">格式化的Sql文本</param> /// <param name="paramers">格式化的参数集</param> static string Format(SqlParamer pfx, DbProvider provider, bool autoPfx, DbCommand cmd, String sql, object[] paramers) { pfx.autoPfx = autoPfx; pfx.provider = provider; pfx.cmd = cmd; pfx.paramers = paramers; pfx.paramPfx = "A"; string prefixion = provider.Prefixion; if (String.IsNullOrEmpty(prefixion) == false) { switch (provider.Delimiter) { case ".": pfx.Prefixion = String.Format("{0}{1}{2}.{0}", provider.QuotePrefix, prefixion, provider.QuoteSuffix); break; default: pfx.Prefixion = String.Format("{0}{1}{2}", provider.QuotePrefix, prefixion, provider.Delimiter); break; } } else { pfx.Prefixion = provider.QuotePrefix; } return(pfx.Do(sql).ToString()); }
object Progress(CommandRun cmdAcs, string sqlText, params object[] paramers) { return(Command(cmd => { cmd.Parameters.Clear(); this.script = Script.Create(sqlText, paramers); switch (paramers.Length) { case 1: if (paramers[0] is System.Collections.IDictionary) { cmd.CommandText = SqlParamer.Format(this.dbProvider, this.isAutoPfx, cmd, sqlText, (System.Collections.IDictionary)paramers[0]); } else { goto default; } break; default: cmd.CommandText = SqlParamer.Format(this.dbProvider, this.isAutoPfx, cmd, sqlText, paramers); break; } return cmdAcs(cmd); })); }
int[] ISqler.ExecuteNonQuery(IDictionary paramKeys, params string[] sqlTexts) { var list = new List <int>(); this.Command(cmd => { for (var i = 0; i < sqlTexts.Length; i++) { var sqlText = sqlTexts[i]; try { cmd.Parameters.Clear(); cmd.CommandText = SqlParamer.Format(this.dbProvider, this.isAutoPfx, cmd, sqlText, paramKeys); list.Add(cmd.ExecuteNonQuery()); } catch { list.Add(-1); } } return(0); }); return(list.ToArray()); }
public static string Format(DbProvider provider, bool autoPfx, DbCommand cmd, String sql, System.Collections.IDictionary diction) { var parms = new List <object>(); SqlParamer pfx = new SqlParamer(); AppendDictionary(diction, provider.Prefixion); System.Collections.IDictionaryEnumerator em = diction.GetEnumerator(); while (em.MoveNext()) { if (em.Key is String) { pfx.keys.Add(em.Key as string); parms.Add(em.Value); } } return(Format(pfx, provider, autoPfx, cmd, sql, parms.ToArray())); }
void ISqler.Execute(System.Predicate <Script> predicate, System.Action <DbCommand> action) { this.Command(cmd => { this.script = Script.Create(String.Empty, new object[0]); while (predicate(this.script)) { if (String.IsNullOrEmpty(this.script.Text)) { break; } else { cmd.Parameters.Clear(); cmd.CommandText = SqlParamer.Format(this.dbProvider, this.isAutoPfx, cmd, this.script.Text, this.script.Arguments); action(cmd); this.script.Reset(String.Empty); } } return(0); }); }