using System;
using System.Collections.Generic;
using System.Text;
namespace Apewer.Source
{
/// 表示在执行 SQL 语句执行过程中发生的错误。
[Serializable]
public sealed class SqlException : Exception
{
const string EmptyMessage = "(无消息)";
string _msg = null;
string _sql = null;
/// 获取描述当前异常的消息。
public override string Message { get => _msg; }
/// 获取引发异常的 SQL 语句。
public string Statement { get => _sql; }
/// 初始化 类的新实例。
/// 描述当前异常的消息。
/// 附带 SQL 语句。
public SqlException(string message, string statement = null)
{
_msg = string.IsNullOrEmpty(message) ? EmptyMessage : message;
_sql = statement;
}
/// 初始化 类的新实例。
/// 用于获取消息的查询结果。
/// 附带 SQL 语句。
public SqlException(IQuery query, string statement = null)
{
if (query == null)
{
_msg = "查询结果实例无效。";
_sql = statement;
return;
}
_msg = query.Message;
if (string.IsNullOrEmpty(_msg)) _msg = EmptyMessage;
_sql = statement;
}
/// 初始化 类的新实例。
/// 用于获取消息的执行结果。
/// 附带 SQL 语句。
public SqlException(IExecute execute, string statement = null)
{
if (execute == null)
{
_msg = "执行结果实例无效。";
return;
}
_msg = execute.Message;
if (string.IsNullOrEmpty(_msg)) _msg = EmptyMessage;
_sql = statement;
}
}
}