Example #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);
        }
Example #2
0
 public DatabaseWorker(ProducerConsumerQueue <ISqlOperation> newQueue, MySqlBase <T> mySqlBase)
 {
     _queue            = newQueue;
     _mySqlBase        = mySqlBase;
     _cancelationToken = false;
     _workerThread     = new Thread(WorkerThread);
     _workerThread.Start();
 }
Example #3
0
        public bool Execute <T>(MySqlBase <T> mySqlBase)
        {
            if (m_holder == null)
            {
                return(false);
            }

            // execute all queries in the holder and pass the results
            foreach (var pair in m_holder.m_queries)
            {
                m_holder.SetResult(pair.Key, mySqlBase.Query(pair.Value));
            }

            return(m_result.TrySetResult(m_holder));
        }
Example #4
0
        public bool Execute <T>(MySqlBase <T> mySqlBase)
        {
            if (_needsResult)
            {
                SQLResult result = mySqlBase.Query(m_stmt);
                if (result == null)
                {
                    m_result.SetResult(new SQLResult());
                    return(false);
                }

                m_result.SetResult(result);
                return(true);
            }

            return(mySqlBase.DirectExecute(m_stmt));
        }
 public DatabaseUpdater(MySqlBase <T> database)
 {
     _database = database;
 }
Example #6
0
        public void AddDatabase <T>(MySqlBase <T> database, string baseDBName)
        {
            bool updatesEnabled = database.IsAutoUpdateEnabled(_updateFlags);

            _open.Add(() =>
            {
                MySqlConnectionInfo connectionObject = new MySqlConnectionInfo
                {
                    Host     = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Host", ""),
                    Port     = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Port", ""),
                    Username = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Username", ""),
                    Password = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Password", ""),
                    Database = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Database", "")
                };

                var error = database.Initialize(connectionObject);
                if (error != MySqlErrorCode.None)
                {
                    // Database does not exist
                    if (error == MySqlErrorCode.UnknownDatabase && updatesEnabled && _autoSetup)
                    {
                        Log.outInfo(LogFilter.ServerLoading, $"Database \"{connectionObject.Database}\" does not exist, do you want to create it? [yes (default) / no]: ");

                        string answer = Console.ReadLine();
                        if (string.IsNullOrEmpty(answer) || answer[0] != 'y')
                        {
                            return(false);
                        }

                        Log.outInfo(LogFilter.ServerLoading, $"Creating database \"{connectionObject.Database}\"...");
                        string sqlString = $"CREATE DATABASE `{connectionObject.Database}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
                        // Try to create the database and connect again if auto setup is enabled
                        if (database.Apply(sqlString) && database.Initialize(connectionObject) == MySqlErrorCode.None)
                        {
                            error = MySqlErrorCode.None;
                        }
                    }

                    // If the error wasn't handled quit
                    if (error != MySqlErrorCode.None)
                    {
                        Log.outError(LogFilter.ServerLoading, $"\nDatabase {connectionObject.Database} NOT opened. There were errors opening the MySQL connections. Check your SQLErrors for specific errors.");
                        return(false);
                    }

                    Log.outInfo(LogFilter.ServerLoading, "Done.");
                }
                return(true);
            });

            if (updatesEnabled)
            {
                // Populate and update only if updates are enabled for this pool
                _populate.Add(() =>
                {
                    if (!database.GetUpdater().Populate())
                    {
                        Log.outError(LogFilter.ServerLoading, $"Could not populate the {database.GetDatabaseName()} database, see log for details.");
                        return(false);
                    }
                    return(true);
                });

                _update.Add(() =>
                {
                    if (!database.GetUpdater().Update())
                    {
                        Log.outError(LogFilter.ServerLoading, $"Could not update the {database.GetDatabaseName()} database, see log for details.");
                        return(false);
                    }
                    return(true);
                });
            }

            _prepare.Add(() =>
            {
                database.LoadPreparedStatements();
                return(true);
            });
        }
Example #7
0
 public bool Execute <T>(MySqlBase <T> mySqlBase)
 {
     return(mySqlBase.DirectCommitTransaction(m_trans));
 }
Example #8
0
 public MySqlErrorCode TryExecute <T>(MySqlBase <T> mySqlBase)
 {
     return(mySqlBase.DirectCommitTransaction(m_trans));
 }