public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } string csv = value.ToString(); if (string.IsNullOrEmpty(csv)) { return(csv); } if (csv[0] == '(') { csv = csv.Substring(1); } if (csv[csv.Length - 1] == ')') { csv = csv.Substring(0, csv.Length - 1); } string[] strs = csv.Split(','); for (int i = 0; i < strs.Length; i++) { strs[i] = Db2SourceContext.DequoteIdentifier(strs[i].Trim()); } return(strs); }
private void UpdateDataGridResult(IDbCommand command) { dataGridResult.CancelEdit(); DateTime start = DateTime.Now; try { IDataReader reader = null; try { reader = command.ExecuteReader(); DataGridControllerResult.Load(reader, Target); } catch (Exception t) { Db2SourceContext ctx = Target.Context; ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, command.CommandText); return; } } finally { 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); textBlockGridResult.Text = string.Format("{0}件見つかりました。 所要時間 {1}", DataGridControllerResult.Rows.Count, s); } }
private void buttonApplySchema_Click(object sender, RoutedEventArgs e) { Db2SourceContext ctx = Target.Context; List <string> sqls = new List <string>(); if ((Target.Comment != null) && Target.Comment.IsModified()) { sqls.AddRange(ctx.GetSQL(Target.Comment, string.Empty, string.Empty, 0, false)); } for (int i = 0; i < Target.Columns.Count; i++) { Column newC = Target.Columns[i, false]; if (newC.IsModified()) { Column oldC = Target.Columns[i, true]; sqls.AddRange(ctx.GetAlterColumnSQL(newC, oldC)); } if ((newC.Comment != null) && newC.Comment.IsModified()) { sqls.AddRange(ctx.GetSQL(newC.Comment, string.Empty, string.Empty, 0, false)); } } if (sqls.Count != 0) { ctx.ExecSqlsWithLog(sqls); } ctx.Revert(Target); IsEditing = false; }
private void buttonRevertSchema_Click(object sender, RoutedEventArgs e) { Db2SourceContext ctx = Target.Context; ctx.Revert(Target); IsEditing = false; }
private void Fetch() { Db2SourceContext ctx = CurrentDataSet; if (ctx == null) { AddLog("データベースに接続していません。", null, null, LogStatus.Error, true); return; } string sql = textBoxSql.Text.TrimEnd(); if (string.IsNullOrEmpty(sql)) { AddLog("SQLがありません。", null, null, LogStatus.Error, true); return; } SQLParts parts = ctx.SplitSQL(sql); if (parts.Count == 0) { AddLog("SQLがありません。", null, null, LogStatus.Error, true); return; } listBoxErrors.Items.Clear(); listBoxErrors.Visibility = Visibility.Collapsed; UpdateDataGridResult(parts); }
private Dictionary <string, bool> GetActiveSchemaDict(Db2SourceContext dataSet, List <string> schemas, List <string> excludedSchemas) { Dictionary <string, bool> ret = new Dictionary <string, bool>(); foreach (Schema s in dataSet.Schemas) { string sn = s.Name.ToLower(); if (_schemas.Count != 0) { if (schemas.IndexOf(sn) == -1) { continue; } } else { if (s.IsHidden) { continue; } if (excludedSchemas.IndexOf(sn) != -1) { continue; } } ret[sn] = true; } return(ret); }
internal View(Db2SourceContext context, string owner, string schema, string viewName, string defintion, bool isLoaded) : base(context, owner, schema, viewName) { _definition = defintion; if (isLoaded) { _oldDefinition = _definition; } }
private void Connect(ConnectionInfo info) { Db2SourceContext ds = info.NewDataSet(); IDbConnection conn = info.NewConnection(true); ds.SchemaLoaded += CurrentDataSet_SchemaLoaded; LoadSchema(ds, conn); }
public ForeignKeyConstraint(Db2SourceContext context, string owner, string schema, string name, string tableSchema, string tableName, string refSchema, string refConstraint, ForeignKeyRule updateRule, ForeignKeyRule deleteRule, bool isNoName, bool deferrable, bool deferred) : base(context, owner, schema, name, tableSchema, tableName, isNoName, deferrable, deferred) { ReferenceSchemaName = refSchema; ReferenceConstraintName = refConstraint; UpdateRule = updateRule; DeleteRule = deleteRule; }
internal SchemaObject(Db2SourceContext context, string owner, string schema, string objectName, Schema.CollectionIndex index) : base(context.RequireSchema(schema)?.GetCollection(index)) { Context = context; Owner = owner; _schema = context.RequireSchema(schema); Name = objectName; Triggers = new TriggerCollection(this); }
internal Constraint(Db2SourceContext context, string owner, string schema, string name, string tableSchema, string tableName, bool isNoName, bool deferrable, bool deferred) : base(context, owner, schema, name, Schema.CollectionIndex.Constraints) { _tableSchema = tableSchema; _tableName = tableName; _table = null; _isTemporaryName = isNoName; _deferrable = deferrable; _deferred = deferred; }
private void UpdateTextBoxSource() { if (textBoxSource == null) { return; } if (Target == null) { textBoxSource.Text = string.Empty; return; } Db2SourceContext ctx = Target.Context; try { StringBuilder buf = new StringBuilder(); if (IsChecked(checkBoxSourceMain)) { foreach (string s in ctx.GetSQL(Target, string.Empty, ";", 0, true)) { buf.AppendLine(s); } } int lastLength = buf.Length; if (IsChecked(checkBoxSourceComment)) { lastLength = buf.Length; if (!string.IsNullOrEmpty(Target.CommentText)) { foreach (string s in ctx.GetSQL(Target.Comment, string.Empty, ";", 0, true)) { buf.Append(s); } } foreach (Column c in Target.Columns) { if (!string.IsNullOrEmpty(c.CommentText)) { foreach (string s in ctx.GetSQL(c.Comment, string.Empty, ";", 0, true)) { buf.Append(s); } } } if (lastLength < buf.Length) { buf.AppendLine(); } } textBoxSource.Text = buf.ToString(); } catch (Exception t) { textBoxSource.Text = t.ToString(); } }
//[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public StoredFunction(Db2SourceContext context, string owner, string schema, string objectName, string internalName, string definition, bool isLoaded) : base(context, owner, schema, objectName, Schema.CollectionIndex.Objects) { Parameters = new ParameterCollection(this); _internalName = internalName; _definition = definition; if (isLoaded) { _oldDefinition = _definition; } }
private void UpdateDataGridResult(IDbCommand command) { DateTime start = DateTime.Now; try { IDbTransaction txn = command.Connection.BeginTransaction(); try { command.Transaction = txn; using (IDataReader reader = command.ExecuteReader()) { IEnumerable l = dataGridParameters.ItemsSource; dataGridParameters.ItemsSource = null; dataGridParameters.ItemsSource = l; DataGridControllerResult.Load(reader); if (0 <= reader.RecordsAffected) { AddLog(string.Format("{0}行反映しました。", reader.RecordsAffected), null, LogStatus.Normal, true); } else { tabControlResult.SelectedItem = tabItemDataGrid; } } txn.Commit(); } catch { txn.Rollback(); throw; } finally { command.Transaction = null; txn.Dispose(); } } catch (Exception t) { Db2SourceContext ctx = Target.Context; string msg = ctx.GetExceptionMessage(t); AddLog(msg, command.CommandText, LogStatus.Error, true); //MessageBox.Show(msg, "エラー", MessageBoxButton.OK, MessageBoxImage.Error); return; } finally { 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), command.CommandText, LogStatus.Aux, false); textBlockGridResult.Text = string.Format("{0}件見つかりました。 所要時間 {1}", DataGridControllerResult.Rows.Count, s); } }
internal Trigger(Db2SourceContext context, string owner, string triggerSchema, string triggerName, string tableSchema, string tableName, string defintion, bool isLoaded) : base(context, owner, triggerSchema, triggerName, Schema.CollectionIndex.Triggers) { _updateEventColumns = new StringCollection(this); _tableSchema = tableSchema; _tableName = tableName; _definition = defintion; //if (isLoaded) //{ // _oldDefinition = _definition; //} }
internal Comment(Db2SourceContext context, string schema, string target, string comment, bool isLoaded) : base(context.RequireSchema(schema)?.Comments) { Context = context; Schema = context.RequireSchema(schema); Target = target; Text = comment; if (isLoaded) { _oldText = Text; } }
private void ButtonApply_Click(object sender, RoutedEventArgs e) { try { DataGridControllerResult.Save(); } catch (Exception t) { Db2SourceContext ctx = Target.Context; ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, Target.Context.LastSql); return; } }
public async Task LoadSchemaAsync(Db2SourceContext dataSet) { try { await dataSet.LoadSchemaAsync(); GC.Collect(); } catch (Exception t) { App.HandleThreadException(t); } return; }
public static void ShowErrorPosition(Exception t, TextBox textBox, Db2SourceContext dataSet, int offset) { Tuple <int, int> ret = dataSet.GetErrorPosition(t, textBox.Text, offset); if (ret == null) { return; } textBox.Select(ret.Item1, ret.Item2); int l = textBox.GetLineIndexFromCharacterIndex(ret.Item1); textBox.ScrollToLine(l); textBox.Focus(); }
private void menuItemDropProcedue_Click(object sender, RoutedEventArgs e) { Window owner = App.FindVisualParent <Window>(this); MessageBoxResult ret = MessageBox.Show(owner, (string)Resources["messageDropSequence"], Properties.Resources.MessageBoxCaption_Drop, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Cancel); if (ret != MessageBoxResult.Yes) { return; } Db2SourceContext ctx = Target.Context; string[] sql = ctx.GetDropSQL(Target, string.Empty, string.Empty, 0, false, false); SqlLogger logger = new SqlLogger(); bool failed = false; try { ctx.ExecSqls(sql, logger.Log); } catch (Exception t) { logger.Buffer.AppendLine(ctx.GetExceptionMessage(t)); failed = true; } string s = logger.Buffer.ToString().TrimEnd(); if (!string.IsNullOrEmpty(s)) { if (failed) { MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Error, MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Result, MessageBoxButton.OK, MessageBoxImage.Information); } } if (failed) { return; } TabItem tab = App.FindLogicalParent <TabItem>(this); if (tab != null) { (tab.Parent as TabControl).Items.Remove(tab); Target.Release(); MainWindow.Current.FilterTreeView(true); } }
public void Fetch() { if (Target == null) { return; } Db2SourceContext ctx = Target.Context; if (ctx == null) { return; } int?limit = null; if (IsChecked(checkBoxLimitRow) && !string.IsNullOrEmpty(textBoxLimitRow.Text)) { int l; if (!int.TryParse(textBoxLimitRow.Text, out l)) { MessageBox.Show("件数が数字ではありません", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); textBoxLimitRow.Focus(); } limit = l; } int offset; string sql = Target.GetSelectSQL(null, textBoxCondition.Text, string.Empty, limit, HiddenLevel.Visible, out offset); try { using (IDbConnection conn = ctx.NewConnection(true)) { using (IDbCommand cmd = ctx.GetSqlCommand(sql, null, conn)) { UpdateDataGridResult(cmd); } } } catch (Exception t) { ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, sql); Db2SrcDataSetController.ShowErrorPosition(t, textBoxCondition, ctx, offset); } finally { UpdateTextBlockWarningLimit(); } }
private bool TryConnect(ConnectionInfo info) { Db2SourceContext ds = info.NewDataSet(); IDbConnection conn = null; try { conn = info.NewConnection(true); } catch { return(false); } ds.SchemaLoaded += CurrentDataSet_SchemaLoaded; LoadSchema(ds, conn); return(true); }
public void DropTarget(bool cascade) { Window owner = App.FindVisualParent <Window>(this); Db2SourceContext ctx = Target.Context; string[] sql = ctx.GetDropSQL(Target, string.Empty, string.Empty, 0, cascade, false); SqlLogger logger = new SqlLogger(); bool failed = false; try { ctx.ExecSqls(sql, logger.Log); } catch (Exception t) { logger.Buffer.AppendLine(ctx.GetExceptionMessage(t)); failed = true; } string s = logger.Buffer.ToString().TrimEnd(); if (!string.IsNullOrEmpty(s)) { if (failed) { MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Error, MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Result, MessageBoxButton.OK, MessageBoxImage.Information); } } if (failed) { return; } TabItem tab = App.FindLogicalParent <TabItem>(this); if (tab != null) { (tab.Parent as TabControl).Items.Remove(tab); Target.Release(); MainWindow.Current.FilterTreeView(true); } }
//#pragma warning disable 1998 public async Task LoadSchemaAsync(Db2SourceContext dataSet, IDbConnection connection) { try { await dataSet.LoadSchemaAsync(connection); GC.Collect(); } catch (Exception t) { App.HandleThreadException(t); } finally { connection.Close(); connection.Dispose(); } return; }
public void Execute() { if (Target == null) { return; } Db2SourceContext ctx = Target.Context; if (ctx == null) { return; } try { foreach (ParamEditor p in dataGridParameters.ItemsSource) { p.SetValue(); } using (IDbConnection conn = ctx.NewConnection(true)) { IDbCommand cmd = Target.DbCommand; try { cmd.Connection = conn; UpdateDataGridResult(cmd); } catch (Exception t) { ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, Target.FullName); } finally { cmd.Connection = null; } } } catch (Exception t) { MessageBox.Show(ctx.GetExceptionMessage(t), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void buttonApplyTrigger_Click(object sender, RoutedEventArgs e) { if (Target == null) { IsEditing = false; return; } Db2SourceContext ctx = Target.Context; string[] sqls = Target.GetAlterSQL(string.Empty, string.Empty, 0, false); if (sqls == null || sqls.Length == 0) { return; } try { ctx.ExecSqlsWithLog(sqls); } catch (Exception t) { string recoverMsg = "(修復しました)"; string[] s = Target.GetRecoverSQL(string.Empty, string.Empty, 0, false); if (s != null && s.Length != 0) { try { ctx.ExecSqlsWithLog(s); } catch (Exception t2) { recoverMsg = string.Format("(修復失敗: {0})", ctx.GetExceptionMessage(t2)); } } MessageBox.Show(string.Format("エラー: {0}{1}", ctx.GetExceptionMessage(t), recoverMsg)); } }
public void LoadSchema(Db2SourceContext dataSet) { gridLoading.Visibility = Visibility.Visible; Task t = LoadSchemaAsync(dataSet); }
public void LoadSchema(Db2SourceContext dataSet, IDbConnection connection) { gridLoading.Visibility = Visibility.Visible; Task t = LoadSchemaAsync(dataSet, connection); }
private void CurrentDataSet_SchemaLoaded(object sender, EventArgs e) { _dataSetTemp = sender as Db2SourceContext; Dispatcher.Invoke(SetSchema, DispatcherPriority.Normal); App.SaveConnectionInfoToRegistry(_dataSetTemp.ConnectionInfo); }
private void SetSchema() { CurrentDataSet = null; CurrentDataSet = _dataSetTemp; Resources["WindowBackground"] = GetBackgroundColor(); }