/// <summary> /// 获取所有符合条件的字符串 /// </summary> /// <param name="condition">条件</param> /// <param name="key">键</param> /// <returns>符合条件的列表</returns> public List <Int32> getIntegerList(MySqlCondition condition, String key) { lock (this) { try { this.Command = new MySqlCommand("SELECT " + key + " FROM " + this.Schema + "." + this.Table + " WHERE " + condition.condition + ";", this.Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); List <Int32> temp = new List <Int32>(); while (this.Reader.Read()) { temp.Add(this.Reader.GetInt32(key)); } return(temp); } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return(null); } finally { this.closeReader(); this.Connection.Close(); } } }
/// <summary> /// 更新数据 /// </summary> /// <param name="condition">条件</param> /// <param name="key">键</param> /// <param name="value">值</param> /// <returns>数量</returns> public int update(MySqlCondition condition, String key, String value) { lock (this) { try { this.Command = new MySqlCommand("Update " + this.Schema + "." + this.Table + " SET" + key + "='" + value + "' WHERE " + condition.condition + ";", this.Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); int i = 0; while (this.Reader.Read()) { i++; } return(i); } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return(0); } finally { this.closeReader(); this.Connection.Close(); } } }
/// <summary> /// 删除行 /// </summary> /// <param name="condition">条件</param> /// <returns>数量</returns> public int delete(MySqlCondition condition) { lock (this) { try { this.Command = new MySqlCommand("DELETE FROM " + this.Schema + "." + this.Table + " WHERE " + condition.condition + ";", Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); int i = 0; while (this.Reader.Read()) { i++; } return(i); } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return(0); } finally { this.closeReader(); this.Connection.Close(); } } }
/// <summary> /// 更新数据 /// </summary> /// <param name="condition">条件</param> /// <param name="key">键</param> /// <param name="value">值</param> /// <returns>数量</returns> public int update(MySqlCondition condition, String key, String value) { lock (this) { try { this.Command = new MySqlCommand("Update " + this.Schema + "." + this.Table + " SET" + key + "='" + value + "' WHERE " + condition.condition + ";", this.Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); int i = 0; while (this.Reader.Read()) { i++; } return i; } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return 0; } finally { this.closeReader(); this.Connection.Close(); } } }
/// <summary> /// 获取所有符合条件的字符串 /// </summary> /// <param name="condition">条件</param> /// <param name="key">键</param> /// <returns>符合条件的列表</returns> public List<String> getStringList(MySqlCondition condition,String key) { lock (this) { try { this.Command = new MySqlCommand("SELECT " + key + " FROM " + this.Schema + "." + this.Table + " WHERE " + condition.condition + ";", this.Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); List<String> temp = new List<String>(); while (this.Reader.Read()) { temp.Add(this.Reader.GetString(key)); } return temp; } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return null; } catch(SqlNullValueException) { return null; } finally { this.closeReader(); this.Connection.Close(); } } }
/// <summary> /// 删除行 /// </summary> /// <param name="condition">条件</param> /// <returns>数量</returns> public int delete(MySqlCondition condition) { lock (this) { try { this.Command = new MySqlCommand("DELETE FROM " + this.Schema + "." + this.Table + " WHERE " + condition.condition + ";", Connection); this.Connection.Open(); this.Reader = this.Command.ExecuteReader(); int i = 0; while (this.Reader.Read()) { i++; } return i; } catch (MySqlException ex) { ConsolePlusLib.Console.Out.println(Level.Severe, ex.ToString()); return 0; } finally { this.closeReader(); this.Connection.Close(); } } }
public MySqlConditionAttribute(MySqlCondition conditions) { Conditions = conditions; }