コード例 #1
0
        public virtual bool Execute <T>(MySqlBase <T> mySqlBase)
        {
            MySqlErrorCode errorCode = TryExecute(mySqlBase);

            if (errorCode == MySqlErrorCode.None)
            {
                return(true);
            }

            if (errorCode == MySqlErrorCode.LockDeadlock)
            {
                // Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other
                lock (_deadlockLock)
                {
                    byte loopBreaker = 5;  // Handle MySQL Errno 1213 without extending deadlock to the core itself
                    for (byte i = 0; i < loopBreaker; ++i)
                    {
                        if (TryExecute(mySqlBase) == MySqlErrorCode.None)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #2
0
 internal MySqlException(MySqlErrorCode errorCode, string?sqlState, string message, Exception?innerException)
     : base(message, innerException)
 {
     ErrorCode = errorCode;
     Number    = (int)errorCode;
     SqlState  = sqlState;
 }
コード例 #3
0
ファイル: MySqlBase.cs プロジェクト: hassiumsoft/CypherCore
        MySqlErrorCode HandleMySQLException(MySqlException ex, string query = "")
        {
            MySqlErrorCode code = (MySqlErrorCode)ex.Number;

            if (ex.InnerException != null)
            {
                if (ex.InnerException is MySqlException)
                {
                    code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number;
                }
            }

            switch (code)
            {
            case MySqlErrorCode.BadFieldError:
            case MySqlErrorCode.NoSuchTable:
                Log.outError(LogFilter.Sql, "Your database structure is not up to date. Please make sure you've executed all queries in the sql/updates folders.");
                break;

            case MySqlErrorCode.ParseError:
                Log.outError(LogFilter.Sql, "Error while parsing SQL. Core fix required.");
                break;
            }

            Log.outError(LogFilter.Sql, $"SqlException: {ex.Message} SqlQuery: {query}");
            return(code);
        }
コード例 #4
0
ファイル: MySqlBase.cs プロジェクト: spadd/CypherCore
        MySqlErrorCode HandleMySQLException(MySqlException ex, string query = "", Dictionary <int, object> parameters = null)
        {
            MySqlErrorCode code = (MySqlErrorCode)ex.Number;

            if (ex.InnerException is MySqlException)
            {
                code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number;
            }

            StringBuilder stringBuilder = new StringBuilder($"SqlException: MySqlErrorCode: {code} Message: {ex.Message} SqlQuery: {query} ");

            if (parameters != null)
            {
                stringBuilder.Append("Parameters: ");
                foreach (var pair in parameters)
                {
                    stringBuilder.Append($"{pair.Key} : {pair.Value}");
                }
            }

            Log.outError(LogFilter.Sql, stringBuilder.ToString());

            switch (code)
            {
            case MySqlErrorCode.BadFieldError:
            case MySqlErrorCode.NoSuchTable:
                Log.outError(LogFilter.Sql, "Your database structure is not up to date. Please make sure you've executed all queries in the sql/updates folders.");
                break;

            case MySqlErrorCode.ParseError:
                Log.outError(LogFilter.Sql, "Error while parsing SQL. Core fix required.");
                break;
            }

            return(code);
        }
コード例 #5
0
        MySqlErrorCode HandleMySQLException(MySqlException ex, string query = "", Dictionary <int, object> parameters = null)
        {
            MySqlErrorCode code = (MySqlErrorCode)ex.Number;

            if (ex.InnerException is MySqlException)
            {
                code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number;
            }

            StringBuilder stringBuilder = new StringBuilder($"SqlException: MySqlErrorCode: {code} Message: {ex.Message} SqlQuery: {query} ");

            if (parameters != null)
            {
                stringBuilder.Append("Parameters: ");
                foreach (var pair in parameters)
                {
                    stringBuilder.Append($"{pair.Key} : {pair.Value}");
                }
            }

            Loggers.Sql?.Error(stringBuilder.ToString());

            switch (code)
            {
            case MySqlErrorCode.BadFieldError:
            case MySqlErrorCode.NoSuchTable:
                Loggers.Sql?.Error("Your database structure is not up to date. Please check your sql queries.");
                break;

            case MySqlErrorCode.ParseError:
                Loggers.Sql?.Error("Error while parsing SQL. Please check your sql queries.");
                break;
            }

            return(code);
        }
コード例 #6
0
 internal MySqlException(MySqlErrorCode errorCode, string message, Exception innerException)
     : this((int)errorCode, null, message, innerException)
 {
 }
コード例 #7
0
 internal MySqlException(MySqlErrorCode errorCode, string message)
     : this((int)errorCode, null, message, null)
 {
 }
コード例 #8
0
 internal MySqlException(MySqlErrorCode errorCode, string sqlState, string message)
     : this(errorCode, sqlState, message, null)
 {
 }