Ejemplo n.º 1
0
        public int AddDataToDeadlockTable(string lockType, string lockTable, int lockObject, int idTransaction, List <int> transWait)
        {
            int    nextDeadlockId = GetNextDeadlockId();
            string transWaitLock  = GetStringForm(transWait);

            if (dbCon.OpenConnection() == true)
            {
                String query = "INSERT INTO `deadlock` (`id`, `lockType`, `lockTable`, `lockObject`, `transThisLock`, `transWaitsLock`) VALUES (@id, @lockType, @lockTable, @lockObject, @transThisLock, @transWaitsLock)";
                var    cmd   = new MySqlCommand(query, dbCon.Connection);

                cmd.Parameters.AddWithValue("@lockType", lockType);
                cmd.Parameters.AddWithValue("@lockObject", lockObject);
                cmd.Parameters.AddWithValue("@lockTable", lockTable);
                cmd.Parameters.AddWithValue("@transThisLock", idTransaction);
                cmd.Parameters.AddWithValue("@transWaitsLock", transWaitLock);
                try
                {
                    cmd.Parameters.AddWithValue("@id", nextDeadlockId);
                    int result = cmd.ExecuteNonQuery();
                    dbCon.CloseConnection();
                    if (result < 0)
                    {
                        Console.WriteLine("Error inserting data into Database!");
                    }
                    else
                    {
                        return(nextDeadlockId);
                    }
                }
                catch (Exception)
                {
                    nextDeadlockId = nextDeadlockId + idTransaction;
                    cmd.Parameters.RemoveAt("@id");
                    cmd.Parameters.AddWithValue("@id", nextDeadlockId);
                    int result = cmd.ExecuteNonQuery();
                    dbCon.CloseConnection();
                    if (result < 0)
                    {
                        Console.WriteLine("Error inserting data into Database!");
                    }
                    else
                    {
                        return(nextDeadlockId);
                    }
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
        public List <Student> GetAllStudents()
        {
            string         query    = "SELECT * FROM student";
            List <Student> students = new List <Student>();

            if (dbCon.OpenConnection() == true)
            {
                var cmd    = new MySqlCommand(query, dbCon.Connection);
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        string  idString         = reader["id"].ToString();
                        string  nume             = reader["Nume"].ToString();
                        string  varstaString     = reader["Varsta"].ToString();
                        string  nrMatricolString = reader["NrMatricol"].ToString();
                        int     id         = Convert.ToInt32(idString);
                        int     varsta     = Convert.ToInt32(varstaString);
                        int     nrMatricol = Convert.ToInt32(nrMatricolString);
                        Student student    = new Student(id, nume, varsta, nrMatricol);
                        students.Add(student);
                    }
                }
                dbCon.CloseConnection();
            }
            return(students);
        }
Ejemplo n.º 3
0
 public bool checkIfTableExists()
 {
     if (dbCon.OpenConnection() == true)
     {
         String query  = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'management' AND table_name = 'lock'";
         var    cmd    = new MySqlCommand(query, dbCon.Connection);
         var    reader = cmd.ExecuteReader();
         if (reader.HasRows == true)
         {
             dbCon.CloseConnection();
             return(true);
         }
         else
         {
             dbCon.CloseConnection();
             return(false);
         }
     }
     return(false);
 }