BeginTransaction() 공개 메소드

Starts a database transaction.
public BeginTransaction ( ) : SqlTransaction
리턴 System.Data.SqlClient.SqlTransaction
예제 #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());
            }
        }
예제 #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);
            }
        }