public object Clone() { ParameterStore obj = MemberwiseClone() as ParameterStore; obj._target = null; return(obj); }
public void CopyTo(ParameterStore destination) { if (destination == null) { return; } destination.DbType = DbType; destination.Direction = Direction; destination.IsNullable = IsNullable; destination.ParameterName = ParameterName; destination.SourceColumn = SourceColumn; destination.SourceVersion = SourceVersion; destination.Value = Value; }
public static ParameterStoreCollection GetParameterStores(string[] paramNames, ParameterStoreCollection stores, out bool modified) { modified = false; ParameterStoreCollection l = new ParameterStoreCollection(); foreach (string param in paramNames) { ParameterStore ps = stores[param]; ParameterStore psAll = AllParameters[param]; if (ps != null) { ps = ps.Clone() as ParameterStore; ps.Target = null; } else if (psAll != null) { ps = psAll.Clone() as ParameterStore; ps.Target = null; modified = true; } else { ps = new ParameterStore(param); modified = true; } l.Add(ps); if (psAll != null) { ps.CopyTo(psAll); } else { AllParameters.Add(ps.Clone() as ParameterStore); } } return(l); }
public static ParameterStoreCollection GetParameterStores(IDbCommand command, ParameterStoreCollection stores, out bool modified) { modified = false; ParameterStoreCollection l = new ParameterStoreCollection(); foreach (DbParameter p in command.Parameters) { ParameterStore ps = stores[p.ParameterName]; ParameterStore psAll = AllParameters[p.ParameterName]; if (ps != null) { ps = ps.Clone() as ParameterStore; ps.Target = p; } else if (psAll != null) { ps = psAll.Clone() as ParameterStore; ps.Target = p; modified = true; } else { ps = new ParameterStore(p); modified = true; } l.Add(ps); if (psAll != null) { ps.CopyTo(psAll); } else { AllParameters.Add(ps.Clone() as ParameterStore); } } return(l); }
private void UpdateDataGridResult(SQLParts sqls) { Db2SourceContext ctx = CurrentDataSet; using (IDbConnection conn = ctx.NewConnection(true)) { bool modified; Parameters = ParameterStore.GetParameterStores(sqls.ParameterNames, Parameters, out modified); if (modified) { return; } foreach (ParameterStore p in Parameters) { if (p.IsError) { dataGridParameters.Focus(); dataGridParameters.SelectedItem = p; MessageBox.Show(string.Format("パラメータ{0}の値が不正です", p.ParameterName), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); return; } } foreach (SQLPart sql in sqls.Items) { IDbCommand cmd = ctx.GetSqlCommand(sql.SQL, Command_Log, conn); ParameterStoreCollection stores = ParameterStore.GetParameterStores(cmd, Parameters, out modified); DateTime start = DateTime.Now; try { using (IDataReader reader = cmd.ExecuteReader()) { DataGridControllerResult.Load(reader); if (0 <= reader.RecordsAffected) { AddLog(string.Format("{0}行反映しました。", reader.RecordsAffected), null, null, LogStatus.Normal, true); } else if (0 < reader.FieldCount) { tabControlResult.SelectedItem = tabItemDataGrid; } } AddToHistory(sql, stores); } catch (Exception t) { Tuple <int, int> errPos = CurrentDataSet.GetErrorPosition(t, sql.SQL, 0); AddLog(CurrentDataSet.GetExceptionMessage(t), sql.SQL, stores, LogStatus.Error, true, errPos); Db2SrcDataSetController.ShowErrorPosition(t, textBoxSql, CurrentDataSet, sql.Offset); return; } finally { ParameterStore.GetParameterStores(cmd, stores, out modified); UpdateDataGridParameters(); DateTime end = DateTime.Now; TimeSpan time = end - start; string s = string.Format("{0}:{1:00}:{2:00}.{3:000}", (int)time.TotalHours, time.Minutes, time.Seconds, time.Milliseconds); AddLog(string.Format("実行しました (所要時間 {0})", s), cmd.CommandText, stores, LogStatus.Aux, false); textBlockGridResult.Text = string.Format("{0}件見つかりました。 所要時間 {1}", DataGridControllerResult.Rows.Count, s); } } } }
public QueryStore(TextReader reader) { StringBuilder buf = new StringBuilder(); for (string s = reader.ReadLine(); s != null && s.StartsWith(ParamSeparator); s = reader.ReadLine()) { buf.AppendLine(s); } _sql = buf.ToString(); Parameters = new ParameterStoreCollection(); while (reader.Peek() != -1) { string pName = GetWord(reader, false); if (pName == null) { break; } if (pName.StartsWith(ParamSeparator)) { return; } if (!pName.StartsWith("--")) { throw new ApplicationException("パラメータ宣言が -- で開始されていません"); } if (pName == "--") { pName = GetWord(reader, false); } else { pName = pName.Substring(2); } string s = GetWord(reader, false); if (s == null || s != ":") { throw new ApplicationException(":が見つかりません"); } string typeStr = GetWord(reader, false); s = GetWord(reader, false); if (s == null || s != "=") { throw new ApplicationException("=が見つかりません"); } string val = GetWord(reader, true); ParameterStore param = new ParameterStore(pName); DbTypeInfo info = DbTypeInfo.GetDbTypeInfo(typeStr); if (info == null) { throw new ApplicationException(string.Format("不明な型です: {0}", typeStr)); } param.DbType = info.DbType; if (string.IsNullOrEmpty(val) || string.Compare(val, "null", true) == 0) { param.Value = DBNull.Value; } else { val = DequoteStr(val); param.Value = info.Parse(val); } Parameters.Add(param); } }