Beispiel #1
0
        private void ExecuteExpressionCommand()
        {
            SQLExpression expression;
            bool          editExpression = InSQLExpression(out expression);
            string        expressionText = editExpression ? '=' + expression.ExpressionText : String.Empty;

            IExpression modifiedValue;

            if (designerContext.EditExpression(expressionText, out modifiedValue))
            {
                string wrappedExpression = string.Empty;
                if (!modifiedValue.IsEmpty)
                {
                    wrappedExpression = SqlStringHandler.CreateSqlExpression(modifiedValue.GetExpression());
                }

                if (editExpression)
                {
                    Regex replaceRegex = new Regex(SqlStringHandler.expressionPattern);
                    SQL = replaceRegex.Replace(SQL, wrappedExpression, 1, expression.StartIndex);
                }
                else
                {
                    SQL = SQL.Insert(SQLIndex, wrappedExpression);
                }
            }
        }
Beispiel #2
0
        public void Drop(IDropInfo dropInfo)
        {
            TextEditor editor   = dropInfo.VisualTarget as TextEditor;
            string     dragText = string.Empty;

            if (dropInfo.Data is NodeViewModel)
            {
                var draggedModel = dropInfo.Data as NodeViewModel;
                dragText = (string.IsNullOrEmpty(editor.Text.Trim())) ? draggedModel.GetExtendedDragText() : draggedModel.GetSimpleDragText();
            }
            else if (dropInfo.Data is string)
            {
                dragText = dropInfo.Data as string;

                if (dragText == VariablesEditor.ExpressionEditorText)
                {
                    ExecuteExpressionCommand();
                    dragText = string.Empty;
                }
                else
                {
                    SQLExpression expression;
                    if (!InSQLExpression(out expression))
                    {
                        dragText = SqlStringHandler.CreateSqlExpression(dragText);
                    }
                }
            }

            var caretIndex = editor.CaretOffset;

            editor.Text        = editor.Text.Insert(caretIndex, dragText);
            editor.CaretOffset = caretIndex + dragText.Length;
        }
Beispiel #3
0
        private void ExecuteExpressionCommand()
        {
            LinxExpression expression;
            bool           editExpression = InLinxExpression(out expression);
            string         expressionText = (editExpression) ? "=" + expression.ExpressionText : string.Empty;

            IExpression modifiedValue;

            if (designerContext.EditExpression(expressionText, out modifiedValue))
            {
                string wrappedExpression = string.Empty;
                if (!modifiedValue.IsEmpty)
                {
                    wrappedExpression = SqlStringHandler.CreateSqlExpression(modifiedValue.GetExpression());
                }

                if (editExpression)
                {
                    SegmentedDocument.Replace(expression.StartIndex, expression.EndIndex - expression.StartIndex + 1,
                                              wrappedExpression);
                }
                else
                {
                    SegmentedDocument.Replace(CaretIndex, 0, wrappedExpression);
                }
            }
        }
Beispiel #4
0
        public void Drop(IDropInfo dropInfo)
        {
            var  draggedModel         = dropInfo.Data as TemplateTreeItemViewModel;
            bool isStringDraggedModel = dropInfo.Data is string;

            if (draggedModel == null && !isStringDraggedModel)
            {
                return;
            }
            if (!isStringDraggedModel && draggedModel.Template == null)
            {
                return;
            }

            if (dropInfo.Data is string)
            {
                string dragText = dropInfo.Data as string;

                if (dragText == VariablesEditor.ExpressionEditorText)
                {
                    ExecuteExpressionCommand();
                    dragText = string.Empty;
                }
                else
                {
                    if (!this.CaretInExpression)
                    {
                        dragText = SqlStringHandler.CreateSqlExpression(dragText);
                    }
                    var editor     = dropInfo.VisualTarget as TextEditor;
                    var caretIndex = editor.CaretOffset;
                    editor.Text        = editor.Text.Insert(caretIndex, dragText);
                    editor.CaretOffset = caretIndex + dragText.Length;
                }
            }
            else
            {
                InsertTemplate(draggedModel.Template);
            }
        }
Beispiel #5
0
        public override void GenerateCode(IFunctionBuilder functionBuilder)
        {
            ExecuteSQL_Gen generator = new ExecuteSQL_Gen();

            generator.Session = new Dictionary <string, object>();
            generator.Session.Add("FunctionContextProperty", functionBuilder.ContextParamName);
            generator.Session.Add("GetParamName", new Func <string, string>(functionBuilder.GetParamName));

            // Function properties
            generator.Session.Add("Timeout", FunctionData.Properties[ExecuteSQLShared.TimeoutPropertyName].GetValue <int>());
            ConnectionTypeSelection connectionType = FunctionData.Properties[DbShared.ConnectionTypePropertyName].GetValue <ConnectionTypeSelection>();
            bool useTransaction = connectionType == ConnectionTypeSelection.UseTransaction;

            generator.Session.Add("UseTransaction", useTransaction);
            if (useTransaction)
            {
                generator.Session.Add("TransactionProperty", functionBuilder.GetParamName(DbShared.TransactionPropertyName));
            }
            else
            {
                generator.Session.Add("ConnectionType", connectionType.ToConnectionType());
                generator.Session.Add("ConnectionStringProperty", functionBuilder.GetParamName(DbShared.ConnectionStringPropertyName));
            }
            generator.Session.Add("Sql", functionBuilder.GetParamName(ExecuteSQLShared.SqlStatementPropertyName));
            ExecuteSQLShared.ReturnModeType returnMode = FunctionData.Properties[ExecuteSQLShared.ReturnOptionsPropertyName].GetValue <ExecuteSQLShared.ReturnModeType>();
            generator.Session.Add("ReturnMode", returnMode);

            // SQL placeholders
            SqlStringHandler sqlStringHandler = SqlStringHandler.GetSqlStringHandler(StaticSqlStatementValue);

            generator.Session.Add("SqlIdentifiers", CSharpUtilities.ArrayAsString(sqlStringHandler.Expressions.Select(ex => SqlStringHandler.CreateSqlExpression(ex.ExpressionText))));
            int parameterIndex = 0;

            generator.Session.Add("SqlValues", "new object[] { " + string.Join(", ", sqlStringHandler.Expressions.Select(ex => functionBuilder.GetParamName(ExecuteSQLShared.SqlValuePropertyPrefix + (++parameterIndex)))) + " }");

            // Output columns
            var resultType = FunctionData.Properties[ExecuteSQLShared.ResultTypePropertyName].GetValue <ResultType>();

            generator.Session.Add("ResultTypeFields", resultType.Fields);

            ITypeReference rowTypeReference = null;

            if (resultType.Fields.Count != 0)
            {
                switch (returnMode)
                {
                case ExecuteSQLShared.ReturnModeType.RowByRow:
                    rowTypeReference = FunctionData.ExecutionPaths[ExecuteSQLShared.ExecutionPathName].Output;
                    break;

                case ExecuteSQLShared.ReturnModeType.ListOfRows:
                    rowTypeReference = FunctionData.Output.GetEnumerableContentType();
                    break;

                case ExecuteSQLShared.ReturnModeType.FirstRow:
                case ExecuteSQLShared.ReturnModeType.FirstRowElseEmptyRow:
                    rowTypeReference = FunctionData.Output;
                    break;
                }
            }
            generator.Session.Add("RowTypeName", rowTypeReference == null ? null : functionBuilder.GetTypeName(rowTypeReference));
            generator.Session.Add("RowType", rowTypeReference);
            generator.Session.Add("ExecutionPathName", ExecuteSQLShared.ExecutionPathName);
            generator.Session.Add("ExecutionPathOutputName", functionBuilder.ExecutionPathOutParamName);

            generator.Initialize();
            functionBuilder.AddCode(generator.TransformText());
            functionBuilder.AddAssemblyReference(typeof(ExecuteSQL));
            functionBuilder.AddAssemblyReference(typeof(System.Data.IDataReader));
        }
Beispiel #6
0
        private DataView ExecuteSQL()
        {
            string[] expressionNames  = this.sqlStringHandler.ExpressionTexts.Select(et => SqlStringHandler.CreateSqlExpression(et)).ToArray();
            string[] expressionValues = this.sqlStringHandler.ExpressionTexts.Select(et => SQLParameters.First(sp => sp.Name == et).Value).ToArray();

            string parameterizedSql = SqlStringHandler.GetParameterizedSql(this.sqlStringHandler.SqlString, expressionNames);

            using (var adapter = GetAdapter(this.connectionType, this.connectionString, parameterizedSql, expressionValues))
            {
                DataTable dataTable = new DataTable();
                adapter.Fill(0, MaxTestResultCount + 1, dataTable);
                if ((MoreResults = dataTable.Rows.Count == MaxTestResultCount + 1))
                {
                    dataTable.Rows.RemoveAt(dataTable.Rows.Count - 1);
                }
                return(dataTable.DefaultView);
            }
        }