コード例 #1
0
ファイル: MainForm.cs プロジェクト: mmakowski/inquisitor
 private void ExecuteCurrentBlock()
 {
     Cursor = Cursors.WaitCursor;
     string currentBlock = FindCurrentBlock();
     SetStatusMarquee("running query...");
     SqlResult result = sqlRunner.RunSql(currentBlock);
     ClearStatus();
     if (result.Exception != null)
     {
         MessageBox.Show(result.Exception.Message);
     }
     if (result.Message != null)
     {
         SetStatus(result.Message);
     }
     if (result.HasData)
     {
         // set columns
         binding.DataSource = null; // adding columns while bound to the view is very slow. Do the work and then re-bind
         dataGridModel.Clear();
         dataGridModel.Columns.Clear();
         dataGridModel.Columns.AddRange(result.Columns);
         // populate
         if (currentResult != null) currentResult.Dispose();
         currentResult = result;
         LoadNextBatchOfRows();
         binding.DataSource = dataGridModel; // re-bind
         dataGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
     }
     Cursor = Cursors.Default;
 }
コード例 #2
0
ファイル: SqlRunner.cs プロジェクト: mmakowski/inquisitor
        /// <summary>
        /// Runs given SQL block
        /// </summary>
        /// <param name="sqlBlock"></param>
        /// <returns>result of the execution</returns>
        public SqlResult RunSql(string sqlBlock)
        {
            sqlBlock = SanitiseSql(sqlBlock);
            log.Debug("executing block in [" + connDetails.Name + "]:\n" + sqlBlock);

            SqlResult result = null;
            try
            {
                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;
                cmd.CommandText = sqlBlock;
                if (sqlBlock.ToLower().StartsWith("select"))
                {
                    OracleDataReader reader = cmd.ExecuteReader();
                    result = new SqlResult(reader);
                }
                else
                {
                    int rowsAffected = cmd.ExecuteNonQuery();
                    if (rowsAffected >= 0)
                    {
                        result = new SqlResult(rowsAffected.ToString() + " row" + (rowsAffected == 1 ? "" : "s") + " affected");
                    }
                    else
                    {
                        result = new SqlResult("command executed");
                    }
                }
            }
            catch (OracleException e)
            {
                result = new SqlResult(e);
            }
            return result;
        }