Esempio n. 1
0
        /// <summary>
        /// Returns the translated T-SQL script. For testing only.
        /// </summary>
        /// <returns>The translated T-SQL script</returns>
        internal string GetTsqlQuery()
        {
            var sr     = new StringReader(CommandText);
            var parser = new GraphViewParser();
            IList <ParseError> errors;
            var script = parser.Parse(sr, out errors) as WSqlScript;

            if (errors.Count > 0)
            {
                throw new SyntaxErrorException(errors);
            }

            if (errors.Count > 0)
            {
                throw new SyntaxErrorException(errors);
            }

            // Translation and Check CheckInvisibleColumn
            using (SqlTransaction tx = GraphViewConnection.BeginTransaction())
            {
                var visitor = new TranslateMatchClauseVisitor(tx);
                visitor.Invoke(script);

                return(script.ToString());
            }
        }
Esempio n. 2
0
        public int ExecuteNonQuery()
        {
            try
            {
                if (CommandType == CommandType.StoredProcedure)
                {
                    if (Tx != null)
                    {
                        Command.Transaction = Tx;
                    }
                    Command.CommandText = CommandText;
                    return(Command.ExecuteNonQuery());
                }

                var sr     = new StringReader(CommandText);
                var parser = new GraphViewParser();
                IList <ParseError> errors;
                var script = parser.Parse(sr, out errors) as WSqlScript;
                if (errors.Count > 0)
                {
                    throw new SyntaxErrorException(errors);
                }

                bool externalTransaction = true;
                if (Tx == null)
                {
                    externalTransaction = false;
                    Tx = GraphViewConnection.BeginTransaction();
                }

                // Translation
                var modVisitor = new TranslateDataModificationVisitor(Tx);
                modVisitor.Invoke(script);
                var matchVisitor = new TranslateMatchClauseVisitor(Tx);
                matchVisitor.Invoke(script);

                Command.CommandText = script.ToString();
                Command.Transaction = Tx;
#if DEBUG
                // For debugging
                OutputResult(CommandText, Command.CommandText);
#endif
                int res = Command.ExecuteNonQuery();
                if (!externalTransaction)
                {
                    Tx.Commit();
                    Tx.Dispose();
                    Tx = null;
                }
                return(res);
            }
            catch (SqlException e)
            {
                throw new SqlExecutionException("An error occurred when executing the query", e);
            }
        }
        public SqlDataReader ExecuteReader()
        {
            try
            {
                if (CommandType == CommandType.StoredProcedure)
                {
                    Command.CommandText = CommandText;
                    return(Command.ExecuteReader());
                }

                var sr     = new StringReader(CommandText);
                var parser = new GraphViewParser();
                IList <ParseError> errors;
                var script = parser.Parse(sr, out errors) as WSqlScript;
                if (errors.Count > 0)
                {
                    throw new SyntaxErrorException(errors);
                }

                // Translation and Check CheckInvisibleColumn
                var visitor = new TranslateMatchClauseVisitor(Connection.Conn);
                visitor.Invoke(script);
                // Executes translated SQL
                Command.CommandText = script.ToString();
#if DEBUG
                // For debugging
                OutputResult(CommandText, Command.CommandText);
                // For debugging
                //if (!File.Exists(@"D:\GraphView Patter Matching Exp\SqlScript\Test.sql"))
                //{
                //    File.Create(@"D:\GraphView Patter Matching Exp\SqlScript\Test.sql");
                //}
                //FileStream file = new FileStream(@"D:\GraphView Patter Matching Exp\SqlScript\Test.sql", FileMode.Append, FileAccess.Write);
                //StreamWriter sw = new StreamWriter(file, Encoding.UTF8, 20480);
                //sw.WriteLine();
                //sw.WriteLine("go");
                //sw.Flush();
                //sw.WriteLine(cmd.CommandText);
                //sw.WriteLine();
                //sw.Flush();


                //throw new GraphViewException("No Execution");
#endif


                var reader = Command.ExecuteReader();
                return(reader);
            }
            catch (SqlException e)
            {
                throw new SqlExecutionException("An error occurred when executing the query", e);
            }
        }
        public int ExecuteNonQuery()
        {
            try
            {
                if (CommandType == CommandType.StoredProcedure)
                {
                    Command.CommandText = CommandText;
                    return(Command.ExecuteNonQuery());
                }

                var sr     = new StringReader(CommandText);
                var parser = new GraphViewParser();
                IList <ParseError> errors;
                var script = parser.Parse(sr, out errors) as WSqlScript;
                if (errors.Count > 0)
                {
                    throw new SyntaxErrorException(errors);
                }

                // Translation
                var modVisitor = new TranslateDataModificationVisitor(Connection.Conn);
                modVisitor.Invoke(script);
                var matchVisitor = new TranslateMatchClauseVisitor(Connection.Conn);
                matchVisitor.Invoke(script);

                Command.CommandText = script.ToString();
#if DEBUG
                // For debugging
                OutputResult(CommandText, Command.CommandText);
#endif
                return(Command.ExecuteNonQuery());
            }
            catch (SqlException e)
            {
                throw new SqlExecutionException("An error occurred when executing the query", e);
            }
        }
Esempio n. 5
0
        public SqlDataReader ExecuteReader()
        {
            try
            {
                if (CommandType == CommandType.StoredProcedure)
                {
                    if (Tx != null)
                    {
                        Command.Transaction = Tx;
                    }
                    Command.CommandText = CommandText;
                    return(Command.ExecuteReader());
                }

                var sr     = new StringReader(CommandText);
                var parser = new GraphViewParser();
                IList <ParseError> errors;
                var script = parser.Parse(sr, out errors) as WSqlScript;
                if (errors.Count > 0)
                {
                    throw new SyntaxErrorException(errors);
                }

                if (Tx == null)
                {
                    var translationConnection = GraphViewConnection.TranslationConnection;

                    using (SqlTransaction translationTx = translationConnection.BeginTransaction(System.Data.IsolationLevel.RepeatableRead))
                    {
                        var visitor = new TranslateMatchClauseVisitor(translationTx);
                        visitor.Invoke(script);

                        // Executes translated SQL
                        Command.CommandText = script.ToString();
#if DEBUG
                        // For debugging
                        OutputResult(CommandText, Command.CommandText);
                        //throw new GraphViewException("No Execution");
#endif
                        var reader = Command.ExecuteReader();
                        translationTx.Commit();
                        return(reader);
                    }
                }
                else
                {
                    var visitor = new TranslateMatchClauseVisitor(Tx);
                    visitor.Invoke(script);
                    // Executes translated SQL
                    Command.CommandText = script.ToString();
#if DEBUG
                    // For debugging
                    OutputResult(CommandText, Command.CommandText);
                    //throw new GraphViewException("No Execution");
#endif
                    var reader = Command.ExecuteReader();
                    return(reader);
                }
            }
            catch (SqlException e)
            {
                throw new SqlExecutionException("An error occurred when executing the query", e);
            }
        }