Exemplo n.º 1
0
 // Adds the given hype to the database.
 private static bool AddHype(Hype hype)
 {
     MySqlConnection conn = new MySqlConnection(connStr);
     try
     {
         conn.Open();
         AddHype(hype, conn);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return false;
     }
     conn.Close();
     return true;
 }
Exemplo n.º 2
0
 private static void AddHype(Hype hype, MySqlConnection conn)
 {
     string query = "REPLACE INTO old_hype VALUES (@url, @handle, @name, @date, @body)";
     MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
     adapter.InsertCommand = new MySqlCommand(query, conn);
     adapter.InsertCommand.Parameters.Add(new MySqlParameter("@handle", hype.handle));
     adapter.InsertCommand.Parameters.Add(new MySqlParameter("@name", hype.name));
     adapter.InsertCommand.Parameters.Add(new MySqlParameter("@url", hype.url));
     adapter.InsertCommand.Parameters.Add(new MySqlParameter("@body", hype.body));
     adapter.InsertCommand.Parameters.Add(new MySqlParameter("@date", hype.date));
     adapter.InsertCommand.ExecuteNonQuery();
 }
Exemplo n.º 3
0
 // Seaches the database for the given URL and returns the associated Hype if found.
 public static Hype GetHype(string url)
 {
     MySqlConnection conn = new MySqlConnection(connStr);
     try
     {
         conn.Open();
         string query = "SELECT * FROM old_hype WHERE url=@url";
         MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
         adapter.SelectCommand = new MySqlCommand(query, conn);
         adapter.SelectCommand.Parameters.AddWithValue("@url", url);
         DataSet dataSet = new DataSet();
         adapter.Fill(dataSet);
         DataTable table = dataSet.Tables[0];
         if (table.Rows.Count > 0)
         {
             DataRow r = table.Rows[0];
             Hype hype = new Hype((string)r["handle"], (string)r["name"], url, (string)r["body"], (DateTime)r["date"]);
             return hype;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
     conn.Close();
     return null;
 }