Exemple #1
0
        public void CREATE_WEBSITE(string Nome, string Endereco, string Tipo)
        {
            try
            {
                GET_TYPE_ID(Tipo);

                MySqlCommand CMD_CREATE_WEBSITE = new MySqlCommand("site_tvtuga_app_admin_users._SP_INSERT_Websites", LigacaoDB);
                CMD_CREATE_WEBSITE.CommandType = CommandType.StoredProcedure;

                CMD_CREATE_WEBSITE.Parameters.AddWithValue("_nome", Nome);
                CMD_CREATE_WEBSITE.Parameters.AddWithValue("_endereco", Endereco);
                CMD_CREATE_WEBSITE.Parameters.AddWithValue("_tipo", TYPE_ID);

                if (LigacaoDB.State == ConnectionState.Closed)
                {
                    LigacaoDB.Open();
                }

                CMD_CREATE_WEBSITE.Prepare();

                IAsyncResult Working_CreateWebsite = CMD_CREATE_WEBSITE.BeginExecuteNonQuery(null, null);

                CMD_CREATE_WEBSITE.EndExecuteNonQuery(Working_CreateWebsite);
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.Close();
            }
        }
Exemple #2
0
        private static void QueryAsyncCallback(IAsyncResult iAr)
        {
            QueryObject <bool> qo = (QueryObject <bool>)iAr.AsyncState;

            try
            {
                MySqlConnection c = null;
                using (MySqlCommand cmd = qo.MySQLCommand)
                {
                    cmd.EndExecuteNonQuery(iAr);
                    c = cmd.Connection;
                }

                if (c != null)
                {
                    c.Dispose();
                }
                if (qo.OriginalCallback != null)
                {
                    qo.OriginalCallback(true);
                }
            }
            catch
            {
                if (qo.OriginalCallback != null)
                {
                    qo.OriginalCallback(false);
                }
            }
        }
        public void ExecuteNonQuery()
        {
            if (Version < new Version(5, 0)) return;

            execSQL("CREATE TABLE test (id int)");
            execSQL("CREATE PROCEDURE spTest() BEGIN SET @x=0; REPEAT INSERT INTO test VALUES(@x); " +
                "SET @x=@x+1; UNTIL @x = 300 END REPEAT; END");

            MySqlCommand proc = new MySqlCommand("spTest", conn);
            proc.CommandType = CommandType.StoredProcedure;
            IAsyncResult iar = proc.BeginExecuteNonQuery();
            int count = 0;
            while (!iar.IsCompleted)
            {
                count++;
                System.Threading.Thread.Sleep(20);
            }
            proc.EndExecuteNonQuery(iar);
            Assert.IsTrue(count > 0);

            proc.CommandType = CommandType.Text;
            proc.CommandText = "SELECT COUNT(*) FROM test";
            object cnt = proc.ExecuteScalar();
            Assert.AreEqual(300, cnt);
        }
Exemple #4
0
        public void FLUSH_PRIVILEGES(MySqlConnection LigacaoDB)
        {
            MySqlCommand CMD_FLUSH = new MySqlCommand();

            string QRY_FLUSH_PRIVILEGES = "FLUSH PRIVILEGES;";

            CMD_FLUSH.Connection  = LigacaoDB;
            CMD_FLUSH.CommandText = QRY_FLUSH_PRIVILEGES;

            try
            {
                IAsyncResult Working = CMD_FLUSH.BeginExecuteNonQuery(null, null);

                while (!Working.IsCompleted)
                {
                    // Accções Adicionais
                }

                CMD_FLUSH.EndExecuteNonQuery(Working);
            }

            catch
            {
                throw;
            }
        }
        public virtual string FinalizeOperation(MySqlCommand command, IInsertResultInternal result)
        {
            IColumnValuePair LastCreatedKeyId = null;
            string           Diagnostic;

            try
            {
                int InsertedLines = command.EndExecuteNonQuery(result.AsyncResult);

                if (InsertedLines > 0)
                {
                    LastCreatedKeyId = GetLastCreatedKeyId(command, result);
                    result.SetCompletedWithId(LastCreatedKeyId);
                    Diagnostic = $"succeeded, {InsertedLines} rows inserted";
                }
                else
                {
                    result.SetCompleted(false, ResultError.ErrorLineNotInserted);
                    Diagnostic = "failed";
                }

                return(Diagnostic);
            }
            catch
            {
                result.SetCompleted(false, ResultError.ErrorExceptionCompletingInsert);
                throw;
            }
        }
Exemple #6
0
        private static void QueryAsyncCallback(IAsyncResult iAr)
        {
            QueryObject <bool> qo = (QueryObject <bool>)iAr.AsyncState;

            try
            {
                MySqlConnection c = null;
                using (MySqlCommand cmd = qo.MySQLCommand)
                {
                    cmd.CommandTimeout = 0; // No timeout
                    cmd.EndExecuteNonQuery(iAr);
                    c = cmd.Connection;
                }

                if (c != null)
                {
                    c.Dispose();
                }
                if (qo.OriginalCallback != null)
                {
                    qo.OriginalCallback(true);
                }
            }
            catch (Exception ex)
            {
                if (qo.OriginalCallback != null)
                {
                    qo.OriginalCallback(false);
                }
                Log.WriteError("Error while executing query: " + ex.Message);
            }
        }
 public void AddUpdateVictimAccount(CSteamID id, decimal bounty, string lastDisplayName)
 {
     try
     {
         MySqlConnection connection = CreateConnection();
         MySqlCommand    command    = connection.CreateCommand();
         if (CheckExists(id))
         {
             command.CommandText = "UPDATE `" + FeexHitman.Instance.Configuration.Instance.FeexHitmanDatabase.DatabaseTableName + "` SET `bounty` = bounty + (" + bounty + "), `lastDisplayName` = @lastDisplayName, `lastUpdated` = NOW() WHERE `steamId` = '" + id.ToString() + "';";
         }
         else
         {
             command.CommandText = "INSERT IGNORE INTO `" + FeexHitman.Instance.Configuration.Instance.FeexHitmanDatabase.DatabaseTableName + "` (steamId,bounty,lastDisplayName,lastUpdated) VALUES('" + id.ToString() + "','" + bounty + "',@lastDisplayName,NOW());";
         }
         command.Parameters.AddWithValue("@lastDisplayName", lastDisplayName);
         connection.Open();
         IAsyncResult result = command.BeginExecuteNonQuery();
         command.EndExecuteNonQuery(result);
         connection.Close();
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
Exemple #8
0
        public void CREATE_TYPE(string Tipo)
        {
            try
            {
                MySqlCommand CMD_CREATE_TYPE = new MySqlCommand("site_tvtuga_app_admin_users._SP_INSERT_WebsiteTipo", LigacaoDB);
                CMD_CREATE_TYPE.CommandType = CommandType.StoredProcedure;

                CMD_CREATE_TYPE.Parameters.AddWithValue("_nome", Tipo);

                LigacaoDB.Open();

                CMD_CREATE_TYPE.Prepare();

                IAsyncResult Working_CreateType = CMD_CREATE_TYPE.BeginExecuteNonQuery(null, null);

                CMD_CREATE_TYPE.EndExecuteNonQuery(Working_CreateType);
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.Close();
            }
        }
Exemple #9
0
        public void CREATE_DB_USER(string Username, int Rank)
        {
            try
            {
                MySqlCommand CMD_CREATE_USER = new MySqlCommand("site_tvtuga_app_admin_users._SP_INSERT_AdminUsers", LigacaoDB.CONNECTION);
                CMD_CREATE_USER.CommandType = CommandType.StoredProcedure;

                CMD_CREATE_USER.Parameters.AddWithValue("_username", Username);
                CMD_CREATE_USER.Parameters.AddWithValue("_rank", Rank);

                LigacaoDB.OPEN_CONNECTION();

                CMD_CREATE_USER.Prepare();

                IAsyncResult Working_CreateUser = CMD_CREATE_USER.BeginExecuteNonQuery(null, null);

                //while (!Working_CreateUser.IsCompleted)
                //{
                // Accções Adicionais
                //}

                CMD_CREATE_USER.EndExecuteNonQuery(Working_CreateUser);
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.CLOSE_CONNECTION();
            }
        }
Exemple #10
0
 private void AsyncQueryCallback(IAsyncResult iAr)
 {
     try {
         MySqlCommand cmd = (MySqlCommand)iAr.AsyncState;
         cmd.EndExecuteNonQuery(iAr);
     } catch { }
 }
        private void _RunCommandAsynchronously(string query)
        {
            try
            {
                int count = 0;
                _commandExecutor = new MySqlCommand(query, _connectionHandle);

                IAsyncResult result = _commandExecutor.BeginExecuteNonQuery();
                while (!result.IsCompleted)
                {
                    Console.WriteLine("Waiting ({0})", count++);
                    System.Threading.Thread.Sleep(500);
                }
                Console.WriteLine("Command complete. Affected {0} rows.",
                                  _commandExecutor.EndExecuteNonQuery(result));
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                // You might want to pass these errors
                // back out to the caller.
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }
Exemple #12
0
        public void ExecuteNonQuery()
        {
            if (Version < new Version(5, 0))
            {
                return;
            }

            execSQL("CREATE TABLE test (id int)");
            execSQL("CREATE PROCEDURE spTest() BEGIN SET @x=0; REPEAT INSERT INTO test VALUES(@x); " +
                    "SET @x=@x+1; UNTIL @x = 300 END REPEAT; END");

            MySqlCommand proc = new MySqlCommand("spTest", conn);

            proc.CommandType = CommandType.StoredProcedure;
            IAsyncResult iar   = proc.BeginExecuteNonQuery();
            int          count = 0;

            while (!iar.IsCompleted)
            {
                count++;
                System.Threading.Thread.Sleep(20);
            }
            proc.EndExecuteNonQuery(iar);
            Assert.IsTrue(count > 0);

            proc.CommandType = CommandType.Text;
            proc.CommandText = "SELECT COUNT(*) FROM test";
            object cnt = proc.ExecuteScalar();

            Assert.AreEqual(300, cnt);
        }
Exemple #13
0
        public void DELETE_DB_USER(int UserID)
        {
            try
            {
                // REMOVER ADMIN
                MySqlCommand CMD_DELETE_ADMIN = new MySqlCommand("site_tvtuga_app_admin_users._SP_DELETE_AdminUsers", LigacaoDB.CONNECTION);
                CMD_DELETE_ADMIN.CommandType = CommandType.StoredProcedure;
                CMD_DELETE_ADMIN.Parameters.AddWithValue("_id", UserID);

                // REMOVER ADMIN CONFIG
                MySqlCommand CMD_DELETE_ADMIN_CONFIG = new MySqlCommand("site_tvtuga_app_admin_users._SP_DELETE_AdminConfig", LigacaoDB.CONNECTION);
                CMD_DELETE_ADMIN_CONFIG.CommandType = CommandType.StoredProcedure;
                CMD_DELETE_ADMIN_CONFIG.Parameters.AddWithValue("_id", UserID);


                // REMOVER ADMIN SQL
                MySqlCommand CMD_DELETE_ADMIN_SQL = new MySqlCommand("site_tvtuga_app_admin_users._SP_DELETE_SQLUsers", LigacaoDB.CONNECTION);
                CMD_DELETE_ADMIN_SQL.CommandType = CommandType.StoredProcedure;
                CMD_DELETE_ADMIN_SQL.Parameters.AddWithValue("_id", UserID);

                LigacaoDB.OPEN_CONNECTION();

                CMD_DELETE_ADMIN.Prepare();
                CMD_DELETE_ADMIN_CONFIG.Prepare();
                CMD_DELETE_ADMIN_SQL.Prepare();

                IAsyncResult Working_DeleteAdminSQL = CMD_DELETE_ADMIN_SQL.BeginExecuteNonQuery(null, null);
                CMD_DELETE_ADMIN_SQL.EndExecuteNonQuery(Working_DeleteAdminSQL);

                IAsyncResult Working_DeleteAdminConfig = CMD_DELETE_ADMIN_CONFIG.BeginExecuteNonQuery(null, null);
                CMD_DELETE_ADMIN_CONFIG.EndExecuteNonQuery(Working_DeleteAdminConfig);

                IAsyncResult Working_DeleteAdmin = CMD_DELETE_ADMIN.BeginExecuteNonQuery(null, null);
                CMD_DELETE_ADMIN.EndExecuteNonQuery(Working_DeleteAdmin);

                using (RegistryKey Chave = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Roaming\OptionsConfig\AppUsers", true))
                {
                    foreach (string User in Chave.GetValueNames())
                    {
                        if (User.Substring(2) == LISTVIEW_CONTAS.SelectedItems[0].Text)
                        {
                            Chave.DeleteValue(User);

                            Chave.SetValue(User, "");
                        }
                    }
                }
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.CLOSE_CONNECTION();
            }
        }
        public void UPDATE_USER(MySqlConnection LigacaoDB, string ID, string Username, string Password)
        {
            //MySqlCommand CMD_UPDATE_USER = new MySqlCommand("SP_UPDATE_UTILIZADOR", LigacaoDB);
            //CMD_UPDATE_USER.CommandType = CommandType.StoredProcedure;

            //CMD_UPDATE_USER.Parameters.AddWithValue("_username", ID);
            //CMD_UPDATE_USER.Parameters.AddWithValue("_newname", Username);
            //CMD_UPDATE_USER.Parameters.AddWithValue("_password", Password);

            MySqlCommand CMD_UPDATE_USER = new MySqlCommand();

            CMD_UPDATE_USER.Connection  = LigacaoDB;
            CMD_UPDATE_USER.CommandText = "RENAME USER '" + ID + "'@'%' TO '" + Username + "'@'%';";

            MySqlCommand CMD_UPDATE_PASS = new MySqlCommand();

            CMD_UPDATE_PASS.Connection  = LigacaoDB;
            CMD_UPDATE_PASS.CommandText = "SET PASSWORD FOR '" + Username + "'@'%' = PASSWORD('" + Password + "');";

            LigacaoDB.Open();

            CMD_UPDATE_USER.Prepare();

            try
            {
                IAsyncResult Working_UpdateUser = CMD_UPDATE_USER.BeginExecuteNonQuery(null, null);

                while (!Working_UpdateUser.IsCompleted)
                {
                    // Accções Adicionais
                }

                CMD_UPDATE_USER.EndExecuteNonQuery(Working_UpdateUser);

                FuncoesDB.FLUSH_PRIVILEGES(LigacaoDB);

                IAsyncResult Working_UpdatePass = CMD_UPDATE_PASS.BeginExecuteNonQuery(null, null);

                while (!Working_UpdatePass.IsCompleted)
                {
                    // Accções Adicionais
                }

                CMD_UPDATE_PASS.EndExecuteNonQuery(Working_UpdatePass);

                FuncoesDB.FLUSH_PRIVILEGES(LigacaoDB);
            }

            catch
            {
                throw;
            }
            finally
            {
                LigacaoDB.Close();
            }
        }
        public static IAsyncResult NonQuery(string sqlQuery)
        {
            MySqlCommand c      = new MySqlCommand(sqlQuery, con);
            IAsyncResult result = c.BeginExecuteNonQuery();

            while (!result.IsCompleted)
            {
                System.Threading.Thread.Sleep(100);
            }
            c.EndExecuteNonQuery(result);

            return(result);
        }
Exemple #16
0
        public static void ExecuteQueryAsnyc(string MySqlCommand)
        {
            if (MySqlCommand != null)
            {
                Console.WriteLine(MySqlCommand);
                MySqlCommand Command = new MySqlCommand(MySqlCommand, connection);

                IAsyncResult result = Command.BeginExecuteNonQuery();
                while (!result.IsCompleted)
                {
                    System.Threading.Thread.Sleep(10);
                }
                Command.EndExecuteNonQuery(result);
            }
        }
Exemple #17
0
        public void addMemberToContact(String query)
        {
            try
            {
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;
                IAsyncResult result = cmd.BeginExecuteNonQuery();
                cmd.EndExecuteNonQuery(result);
                con.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 public void UpdateVictimDisplayName(CSteamID id, string lastDisplayName)
 {
     try
     {
         MySqlConnection connection = CreateConnection();
         MySqlCommand    command    = connection.CreateCommand();
         command.CommandText = "UPDATE `" + FeexHitman.Instance.Configuration.Instance.FeexHitmanDatabase.DatabaseTableName + "` SET `lastDisplayName` = @lastDisplayName WHERE `steamId` = '" + id.ToString() + "';";
         command.Parameters.AddWithValue("@lastDisplayName", lastDisplayName);
         connection.Open();
         IAsyncResult result = command.BeginExecuteNonQuery();
         command.EndExecuteNonQuery(result);
         connection.Close();
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            if (!asyncResult.IsCompleted)
            {
                TimeSpan ts = DateTime.Now.Subtract(start);
                if (ts.TotalSeconds > nextTime)
                {
                    nonQueryOutput.Text += Convert.ToInt32(ts.TotalSeconds) + " seconds" + Environment.NewLine;
                    nextTime            += 5;
                }
                return;
            }

            int recordsAffected = cmd.EndExecuteNonQuery(asyncResult);

            nonQueryOutput.Text += "Records Affected = " + recordsAffected;
            conn.Close();
            timer1.Enabled = false;
        }
 public bool RemoveVictimAccount(CSteamID id)
 {
     try
     {
         MySqlConnection connection = CreateConnection();
         MySqlCommand    command    = connection.CreateCommand();
         command.CommandText = "DELETE FROM `" + FeexHitman.Instance.Configuration.Instance.FeexHitmanDatabase.DatabaseTableName + "` WHERE `steamId`='" + id.ToString() + "';";
         connection.Open();
         IAsyncResult result = command.BeginExecuteNonQuery();
         command.EndExecuteNonQuery(result);
         connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
         return(false);
     }
 }
    /// <summary>
    /// Raw write-to function for adding a string and EmotionIdeal to the database.
    /// This assumes that word is not too long (> 30 chars).
    /// </summary>
    /// <param name="word">The string to enter as the word</param>
    /// <param name="emotionIdeal">The emotion ideal to associate with word</param>
    private IEnumerator AddEntryToDatabase(string word, EmotionModel.EmotionIdeal emotionIdeal, WVObject <bool?> result)
    {
        Debug.Log("Adding entry " + word + " to db");
        using (MySqlCommand command = _connection.CreateCommand())
        {
            command.CommandText = "INSERT INTO " + TABLE_NAME + "(" + TABLE_WORD + ", " + TABLE_EMO_IDEAL + ")" +
                                  " VALUES" + "('" + word + "', " + "'" + ((int)emotionIdeal).ToString() + "');";

            System.IAsyncResult asyncResult = command.BeginExecuteNonQuery();

            while (!asyncResult.IsCompleted)
            {
                yield return(null);
            }

            command.EndExecuteNonQuery(asyncResult);

            result.value = true;
        }
    }
Exemple #22
0
        public void CREATE_DB_USER_CONFIG(int UserID, string DB_Host, int DB_Protocol, int DP_Port)
        {
            try
            {
                MySqlCommand CMD_CREATE_USER_CONFIG = new MySqlCommand("site_tvtuga_app_admin_users._SP_INSERT_AdminConfig", LigacaoDB.CONNECTION);
                CMD_CREATE_USER_CONFIG.CommandType = CommandType.StoredProcedure;

                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_admin_id", UserID);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_db_host", DB_Host);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_db_protocol", DB_Protocol);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_db_port", DP_Port);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_ftp_host", null);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_ftp_protocol", null);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_ftp_port", null);
                CMD_CREATE_USER_CONFIG.Parameters.AddWithValue("_ftp_directory", null);

                LigacaoDB.OPEN_CONNECTION();

                CMD_CREATE_USER_CONFIG.Prepare();


                IAsyncResult Working_CreateUserConfig = CMD_CREATE_USER_CONFIG.BeginExecuteNonQuery(null, null);

                //while (!Working_CreateUser.IsCompleted)
                //{
                // Accções Adicionais
                //}

                CMD_CREATE_USER_CONFIG.EndExecuteNonQuery(Working_CreateUserConfig);
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.CLOSE_CONNECTION();
            }
        }
 public virtual string FinalizeOperation(MySqlCommand command, IUpdateResultInternal result)
 {
     try
     {
         int ModifiedLines = command.EndExecuteNonQuery(result.AsyncResult);
         if (ModifiedLines > 0)
         {
             result.SetCompleted(true);
             return($"succeeded, {ModifiedLines} row(s) modified");
         }
         else
         {
             result.SetCompleted(false, ResultError.ErrorNoRowModified);
             return("failed");
         }
     }
     catch
     {
         result.SetCompleted(false, ResultError.ErrorExceptionCompletingUpdate);
         throw;
     }
 }
Exemple #24
0
        public virtual string FinalizeOperation(MySqlCommand command, IDeleteResultInternal result)
        {
            try
            {
                int DeletedRowCount = command.EndExecuteNonQuery(result.AsyncResult);

                if (DeletedRowCount >= Context.ExpectedDeletedCount)
                {
                    result.SetCompletedWithCount(DeletedRowCount);
                    return($"succeeded, {DeletedRowCount} row(s) deleted");
                }
                else
                {
                    result.SetCompleted(false, ResultError.ErrorMissingDeletedRows);
                    return("failed");
                }
            }
            catch
            {
                result.SetCompleted(false, ResultError.ErrorExceptionCompletingDelete);
                throw;
            }
        }
Exemple #25
0
            public bool Handle()
            {
                List <Dictionary <string, object> > list = null;
                var nonQueryResult  = 0;
                var lastInsertRowId = 0L;

                try
                {
                    if (Connection == null)
                    {
                        throw new Exception("Connection is null");
                    }
                    //if (_result == null)
                    //{
                    _connection = (MySqlConnection)Connection.Con;
                    if (_connection.State == ConnectionState.Closed)
                    {
                        _connection.Open();
                    }
                    _cmd             = _connection.CreateCommand();
                    _cmd.CommandText = Sql.SQL;
                    Sql.AddParams(_cmd, Sql.Arguments, "@");
                    _result = NonQuery ? _cmd.BeginExecuteNonQuery() : _cmd.BeginExecuteReader();
                    //}
                    _result.AsyncWaitHandle.WaitOne();
                    //if (!_result.IsCompleted) return false;
                    if (NonQuery)
                    {
                        nonQueryResult = _cmd.EndExecuteNonQuery(_result);
                    }
                    else
                    {
                        using (var reader = _cmd.EndExecuteReader(_result))
                        {
                            list = new List <Dictionary <string, object> >();
                            while (reader.Read())
                            {
                                var dict = new Dictionary <string, object>();
                                for (var i = 0; i < reader.FieldCount; i++)
                                {
                                    dict.Add(reader.GetName(i), reader.GetValue(i));
                                }
                                list.Add(dict);
                            }
                        }
                    }
                    lastInsertRowId = _cmd.LastInsertedId;
                    Cleanup();
                }
                catch (Exception ex)
                {
                    var message = "MySql handle raised an exception";
                    if (Connection?.Plugin != null)
                    {
                        message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
                    }
                    Interface.Oxide.LogException(message, ex);
                    Cleanup();
                }
                Interface.Oxide.NextTick(() =>
                {
                    Connection?.Plugin?.TrackStart();
                    try
                    {
                        if (Connection != null)
                        {
                            Connection.LastInsertRowId = lastInsertRowId;
                        }
                        if (!NonQuery)
                        {
                            Callback(list);
                        }
                        else
                        {
                            CallbackNonQuery?.Invoke(nonQueryResult);
                        }
                    }
                    catch (Exception ex)
                    {
                        var message = "MySql command callback raised an exception";
                        if (Connection?.Plugin != null)
                        {
                            message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
                        }
                        Interface.Oxide.LogException(message, ex);
                    }
                    Connection?.Plugin?.TrackEnd();
                });
                return(true);
            }
Exemple #26
0
        public void UPDATE_DB_USER(int UserID, string DB_Host, int DB_Protocol, int DP_Port, string Username, string Password)
        {
            try
            {
                using (RegistryKey Chave = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Roaming\OptionsConfig\AppUsers", true))
                {
                    foreach (string User in Chave.GetValueNames())
                    {
                        if (User.Substring(2) == LISTVIEW_CONTAS.SelectedItems[0].Text)
                        {
                            Chave.DeleteValue(User);

                            Chave.SetValue(User, "SERVER=" + DB_Host + ";UID=" + Username + ";PWD=" + Password + ";Use Procedure Bodies=false;");
                        }
                    }
                }

                UPDATE_CONNECTION_STRING(DB_Host, Username, Password);

                // ALTERAR ADMIN
                MySqlCommand CMD_UPDATE_ADMIN = new MySqlCommand("site_tvtuga_app_admin_users._SP_UPDATE_AdminUsers", LigacaoDB.CONNECTION);
                CMD_UPDATE_ADMIN.CommandType = CommandType.StoredProcedure;
                CMD_UPDATE_ADMIN.Parameters.AddWithValue("_id", UserID);
                CMD_UPDATE_ADMIN.Parameters.AddWithValue("_username", LocalUsername);
                CMD_UPDATE_ADMIN.Parameters.AddWithValue("_rank", LocalRank);

                // ALTERAR ADMIN CONFIG
                MySqlCommand CMD_UPDATE_ADMIN_CONFIG = new MySqlCommand("site_tvtuga_app_admin_users._SP_UPDATE_AdminConfig", LigacaoDB.CONNECTION);
                CMD_UPDATE_ADMIN_CONFIG.CommandType = CommandType.StoredProcedure;
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_admin_id", UserID);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_db_host", DB_Host);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_db_protocol", DB_Protocol);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_db_port", DP_Port);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_ftp_host", null);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_ftp_protocol", null);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_ftp_port", null);
                CMD_UPDATE_ADMIN_CONFIG.Parameters.AddWithValue("_ftp_directory", null);

                // ALTERAR ADMIN SQL
                MySqlCommand CMD_UPDATE_ADMIN_SQL = new MySqlCommand("site_tvtuga_app_admin_users._SP_UPDATE_SQLUsers   ", LigacaoDB.CONNECTION);
                CMD_UPDATE_ADMIN_SQL.CommandType = CommandType.StoredProcedure;
                CMD_UPDATE_ADMIN_SQL.Parameters.AddWithValue("_admin_id", UserID);
                CMD_UPDATE_ADMIN_SQL.Parameters.AddWithValue("_nome", Username);
                CMD_UPDATE_ADMIN_SQL.Parameters.AddWithValue("_password", Password);

                LigacaoDB.OPEN_CONNECTION();

                CMD_UPDATE_ADMIN.Prepare();
                CMD_UPDATE_ADMIN_CONFIG.Prepare();
                CMD_UPDATE_ADMIN_SQL.Prepare();

                IAsyncResult Working_UpdateAdmin = CMD_UPDATE_ADMIN.BeginExecuteNonQuery(null, null);
                CMD_UPDATE_ADMIN.EndExecuteNonQuery(Working_UpdateAdmin);

                IAsyncResult Working_UpdateAdminConfig = CMD_UPDATE_ADMIN_CONFIG.BeginExecuteNonQuery(null, null);
                CMD_UPDATE_ADMIN_CONFIG.EndExecuteNonQuery(Working_UpdateAdminConfig);

                IAsyncResult Working_UpdateAdminSQL = CMD_UPDATE_ADMIN_SQL.BeginExecuteNonQuery(null, null);
                CMD_UPDATE_ADMIN_SQL.EndExecuteNonQuery(Working_UpdateAdminSQL);
            }

            catch (Exception EX)
            {
                MessageBox.Show("Ocorreu um erro. Descrição do erro: \n\n " + EX.Message + "", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                LigacaoDB.CLOSE_CONNECTION();
            }
        }
Exemple #27
0
 private static void Callback(IAsyncResult ar)
 {
     _cmdAsync.EndExecuteNonQuery(ar);
     _exited = true;
 }
        private static void EndCreateAccount(IAsyncResult AR)
        {
            MySqlCommand Cmd = AR.AsyncState as MySqlCommand;

            Cmd.EndExecuteNonQuery(AR);
        }
Exemple #29
0
        public T EndInvoke()
        {
            T result = default(T);

            try {
                switch (CallbackType)
                {
                case CallbackType.DataReader:
                    if (DbType == IICDbType.SqlServer2005)
                    {
                        SqlCommand cmd = SqlCommand as SqlCommand;
                        try {
                            SqlDataReader retValue = cmd.EndExecuteReader(ar);
                            result = (T)Convert.ChangeType(new DataReader(retValue, cmd, SqlConnection), typeof(T));
                        } catch (Exception ex) {
                            SqlConnection.Close();
                            throw ex;
                        }
                    }
                    else if (DbType == IICDbType.Mysql)
                    {
                        MySqlCommand cmd = SqlCommand as MySqlCommand;
                        try {
                            MySqlDataReader retValue = cmd.EndExecuteReader(ar);
                            result = (T)Convert.ChangeType(new DataReader(retValue, cmd, SqlConnection), typeof(T));
                        } catch (Exception ex) {
                            SqlConnection.Close();
                            throw ex;
                        }
                    }
                    break;

                case CallbackType.NonQuery:
                    if (DbType == IICDbType.SqlServer2005)
                    {
                        SqlCommand cmd = SqlCommand as SqlCommand;
                        try {
                            int retValue = cmd.EndExecuteNonQuery(ar);
                            result = (T)Convert.ChangeType(retValue, typeof(T));
                        } catch (Exception ex) {
                            SqlConnection.Close();
                            throw ex;
                        }
                    }
                    else if (DbType == IICDbType.Mysql)
                    {
                        MySqlCommand cmd = SqlCommand as MySqlCommand;
                        try {
                            int retValue = cmd.EndExecuteNonQuery(ar);
                            result = (T)Convert.ChangeType(retValue, typeof(T));
                        } catch (Exception ex) {
                            SqlConnection.Close();
                            throw ex;
                        }
                    }
                    break;
                }
                return(result);
            } catch (System.Exception ex) {
                throw ex;
            }
        }
Exemple #30
0
        // todo to ensure thread-safe
        // todo one handle can associate one dataReader at most
        public async Task <ILoadDataContext> Query(string sql, object key)
        {
            var cmd = new MySqlCommand(sql, Handle);

            cmd.Parameters.AddWithValue("1", key);

            var ret = await Task.Factory.FromAsync(cmd.BeginExecuteNonQuery(), (ar => cmd.EndExecuteNonQuery(ar)), TaskCreationOptions.None);

            var reader = await Task.Factory.FromAsync(cmd.BeginExecuteReader(), (ar => cmd.EndExecuteReader(ar)), TaskCreationOptions.None);

            if (!reader.Read())
            {
                cmd.Dispose();
                reader.Dispose();
                return(null);
            }

            return(new MysqlLoadDataContext()
            {
                Reader = reader,
                MysqlAdaptor = this,
            });
        }
Exemple #31
0
            public bool Handle()
            {
                //вывести SQL запрос и параметры
                string GetCommandParams()
                {
                    StringBuilder ParamsVals = new StringBuilder();

                    int LastIndex = this._cmd.Parameters.Count;

                    for (int i = 0; i < LastIndex; ++i)
                    {
                        //не добавляем запятую в последую строку
                        string EndChar = "";
                        if (i != LastIndex - 1)
                        {
                            EndChar = ", ";
                        }
                        IDbDataParameter item = this._cmd.Parameters[i];
                        ParamsVals.AppendFormat("{0}={1}{2}", item.ParameterName, item.Value, EndChar);//пример: @0=value
                    }
                    return(ParamsVals.ToString());
                }

                List <Dictionary <string, object> > list = null;
                int  nonQueryResult  = 0;
                long lastInsertRowId = 0L;

                try {
                    if (Connection == null)
                    {
                        throw new Exception("Connection is null");
                    }
                    //if (_result == null)
                    //{
                    _connection = (MySqlConnection)Connection.Con;
                    if (_connection.State == ConnectionState.Closed)
                    {
                        _connection.Open();
                    }

                    _cmd = _connection.CreateCommand();
                    _cmd.CommandTimeout = 120;
                    _cmd.CommandText    = Sql.SQL;
                    Sql.AddParams(_cmd, Sql.Arguments, "@");
                    _result = NonQuery ? _cmd.BeginExecuteNonQuery() : _cmd.BeginExecuteReader();
                    //}
                    _result.AsyncWaitHandle.WaitOne();
                    //if (!_result.IsCompleted) return false;
                    if (NonQuery)
                    {
                        nonQueryResult = _cmd.EndExecuteNonQuery(_result);
                    }
                    else
                    {
                        using (MySqlDataReader reader = _cmd.EndExecuteReader(_result)) {
                            list = new List <Dictionary <string, object> >();
                            while (reader.Read())
                            {
                                if (Connection.ConnectionPersistent && (Connection.Con.State == ConnectionState.Closed || Connection.Con.State == ConnectionState.Broken))
                                {
                                    break;
                                }
                                var dict = new Dictionary <string, object>();
                                for (int i = 0; i < reader.FieldCount; i++)
                                {
                                    dict.Add(reader.GetName(i), reader.GetValue(i));
                                }
                                list.Add(dict);
                            }
                        }
                    }
                    lastInsertRowId = _cmd.LastInsertedId;
                    Cleanup();
                } catch (Exception ex) {
                    string message = "MySql handle raised an exception";
                    if (Connection?.Plugin != null)
                    {
                        message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin ";
                    }
                    //вывод в исключении текста команда и её параметров(должно помочь при отладке)
                    message += $"Command: \"{this._cmd.CommandText}\" Params: \"{GetCommandParams()}\"";

                    Interface.Oxide.LogException(message, ex);
                    Cleanup();
                }
                Interface.Oxide.NextTick(() => {
                    Connection?.Plugin?.TrackStart();
                    try {
                        if (Connection != null)
                        {
                            Connection.LastInsertRowId = lastInsertRowId;
                        }

                        if (!NonQuery)
                        {
                            Callback(list);
                        }
                        else
                        {
                            CallbackNonQuery?.Invoke(nonQueryResult);
                        }
                    } catch (Exception ex) {
                        string message = "MySql command callback raised an exception";
                        if (Connection?.Plugin != null)
                        {
                            message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin ";
                        }
                        message += $"Command: \"{this._cmd.CommandText}\" Params: \"{GetCommandParams()}\"";
                        Interface.Oxide.LogException(message, ex);
                    }
                    Connection?.Plugin?.TrackEnd();
                });
                return(true);
            }