using Apewer;
using System;

namespace Apewer.Source
{

    /// <summary>数据库引擎的执行结果。</summary>
    public class Execute : IExecute
    {

        private bool _success = false;
        private int _rows = 0;
        private string _error = "";
        private string _message = "";
        private Exception _exception = new Exception();

        /// <summary>语句执行成功。</summary>
        public bool Success
        {
            get { return _success; }
            set { _success = value; }
        }

        /// <summary>执行失败时的异常。</summary>
        public Exception Exception
        {
            get { return _exception; }
            set { _exception = value; }
        }

        /// <summary>受影响的行数。</summary>
        public int Rows
        {
            get { return _rows; }
            set { _rows = value; }
        }

        /// <summary>错误信息。</summary>
        public string Error
        {
            get
            {
                if (!string.IsNullOrEmpty(_error))
                {
                    return _error;
                }
                else
                {
                    if (_exception != null)
                    {
                        try
                        {
                            return _exception.Message;
                        }
                        catch
                        {
                            return _exception.GetType().FullName;
                        }
                    }
                }
                return "";
            }
            set { _error = value ?? ""; }
        }

        /// <summary>消息。</summary>
        public string Message
        {
            get { return _message ?? ""; }
            set { _message = value ?? ""; }
        }

    }

}