Example #1
0
        private void SaveInFile()
        {
            // Save the query text to file
            if (QBuilder.ActiveUnionSubQuery == null)
            {
                return;
            }

            var saveFileDialog1 = new SaveFileDialog()
            {
                DefaultExt = "sql",
                FileName   = "query",
                Filter     = "SQL query files (*.sql)|*.sql|All files|*.*"
            };

            if (saveFileDialog1.ShowDialog() != true)
            {
                return;
            }

            using (var sw = new StreamWriter(saveFileDialog1.FileName))
            {
                sw.Write(FormattedSQLBuilder.GetSQL(QBuilder.ActiveUnionSubQuery.QueryRoot, QBuilder.SQLFormattingOptions));
            }
        }
Example #2
0
        private void ApplyText()
        {
            var sqlFormattingOptions = queryBuilder1.SQLFormattingOptions;

            switch (_mode)
            {
            case ModeEditor.Entire:
                textBox1.Text = queryBuilder1.FormattedSQL;
                break;

            case ModeEditor.SubQuery:
                if (queryBuilder1.ActiveUnionSubQuery == null)
                {
                    break;
                }
                var subQuery = queryBuilder1.ActiveUnionSubQuery.ParentSubQuery;
                textBox1.Text = FormattedSQLBuilder.GetSQL(subQuery, sqlFormattingOptions);
                break;

            case ModeEditor.Expression:
                if (queryBuilder1.ActiveUnionSubQuery == null)
                {
                    break;
                }
                var unionSubQuery = queryBuilder1.ActiveUnionSubQuery;
                textBox1.Text = FormattedSQLBuilder.GetSQL(unionSubQuery, sqlFormattingOptions);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private void sqlQuery_SQLUpdated(object sender, EventArgs e)
        {
            // Handle the event raised by SQL Builder object that the text of SQL query is changed

            // Hide error banner if any
            errorBox1.Show(null, sqlContext1.SyntaxProvider);

            // update the text box with formatted query text created with default formatting options
            _lastValidSql = sqlTextEditor1.Text = FormattedSQLBuilder.GetSQL(sqlQuery1.QueryRoot, new SQLFormattingOptions());
        }
Example #4
0
        private void _query_SQLUpdated(object sender, EventArgs e)
        {
            // at this stage you can get simple unformatted query text...
            //SqlBox.Text = _query.SQL;

            // ... or format the query text with SQL formatter
            SQLFormattingOptions formattingOptions = new SQLFormattingOptions {
                KeywordFormat = KeywordFormat.UpperCase
            };
            var sql = FormattedSQLBuilder.GetSQL(_query.QueryRoot, formattingOptions);

            // put the result SQL query text to the text box
            SqlBox.Text = sql;
        }
Example #5
0
        private void ApplyText()
        {
            var sqlFormattingOptions = Builder.SQLFormattingOptions;

            if (TextEditor == null)
            {
                return;
            }

            switch (_mode)
            {
            case ModeEditor.Entire:
                _lastValidSql = TextEditor.Text = Builder.FormattedSQL;
                break;

            case ModeEditor.SubQuery:
                if (Builder.ActiveUnionSubQuery == null)
                {
                    break;
                }
                var subQuery = Builder.ActiveUnionSubQuery.ParentSubQuery;
                _lastValidSql = TextEditor.Text = FormattedSQLBuilder.GetSQL(subQuery, sqlFormattingOptions);
                break;

            case ModeEditor.Expression:
                if (Builder.ActiveUnionSubQuery == null)
                {
                    break;
                }
                var unionSubQuery = Builder.ActiveUnionSubQuery;
                _lastValidSql = TextEditor.Text = FormattedSQLBuilder.GetSQL(unionSubQuery, sqlFormattingOptions);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public void OnSQLUpdated(object sender, EventArgs e)
        {
            var qb = QueryBuilderStore.Get("AlternateNames");

            var opts = new SQLFormattingOptions();

            opts.Assign(qb.SQLFormattingOptions);
            opts.KeywordFormat = KeywordFormat.UpperCase;

            // get SQL query with real object names
            opts.UseAltNames = false;
            var plainSql = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts);

            // get SQL query with alternate names
            opts.UseAltNames = true;
            var sqlWithAltNames = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts);

            // prepare additional data to be sent to the client
            qb.ExchangeData = new
            {
                SQL          = plainSql,
                AlternateSQL = sqlWithAltNames
            };
        }
        public void OnSQLUpdated(object sender, EventArgs e)
        {
            var qb = QueryBuilderStore.Get(InstanceId);

            var opts = new SQLFormattingOptions();

            opts.Assign(qb.SQLFormattingOptions);
            opts.KeywordFormat = KeywordFormat.UpperCase;

            // get query with virtual objects and fields
            opts.ExpandVirtualObjects = false;
            var sqlWithVirtObjects = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts);

            // get SQL query with real object names
            opts.ExpandVirtualObjects = true;
            var plainSql = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts);

            // prepare additional data to be sent to the client
            qb.ExchangeData = new
            {
                SQL = plainSql,
                VirtualObjectsSQL = sqlWithVirtObjects
            };
        }
 private void sqlQuery_SQLUpdated(object sender, EventArgs e)
 {
     // Text of SQL query has been updated.
     // To get the query text, ready for execution on SQL server with real object names just use SQL property.
     _lastValidSql = sqlTextEditor.Text = FormattedSQLBuilder.GetSQL(_sqlQuery.QueryRoot, new SQLFormattingOptions());
 }
 private void sqlQuery1_SQLUpdated(object sender, EventArgs e)
 {
     sqlTextEditor1.Text = _builder.GetSQL(sqlQuery1.QueryRoot);
 }