예제 #1
0
 public bool TryGetValue(string key, [MaybeNullWhen(false)] out string value)
 {
     if (SQLiteUtility.IsNull(key))
     {
         throw new ArgumentNullException();
     }
     else if (!ContainsKey(key))
     {
         value = default(string);
         return(false);
     }
     else
     {
         value = this[key];
         return(true);
     }
 }
예제 #2
0
 public bool Remove(string key)
 {
     if (SQLiteUtility.IsNull(key))
     {
         throw new ArgumentNullException();
     }
     if (!ContainsKey(key))
     {
         return(false);
     }
     else
     {
         string commandText = $"DELETE FROM {tableName} WHERE Key = @key";
         List <SqliteParameter> parameters = new List <SqliteParameter>();
         parameters.Add(new SqliteParameter("@key", key));
         SQLiteUtility.ExecuteCommand(connectionString, commandText, parameters);
         return(true);
     }
 }
예제 #3
0
 public void Add(string key, string value)
 {
     if (SQLiteUtility.IsNull(key))
     {
         throw new ArgumentNullException();
     }
     else if (ContainsKey(key))
     {
         throw new ArgumentException();
     }
     else
     {
         string commandText = $"INSERT INTO {tableName} (Key, Value) VALUES (@key, @value)";
         List <SqliteParameter> parameters = new List <SqliteParameter>();
         parameters.Add(new SqliteParameter("@key", key));
         parameters.Add(new SqliteParameter("@value", value));
         SQLiteUtility.ExecuteCommand(connectionString, commandText, parameters);
     }
 }
예제 #4
0
 public bool Remove(KeyValuePair <string, string> item)
 {
     if (SQLiteUtility.IsNull(item.Key))
     {
         throw new ArgumentNullException();
     }
     if (!Contains(item))
     {
         return(false);
     }
     else
     {
         string commandText = $"DELETE FROM {tableName} WHERE Key = @key AND Value = @value";
         List <SqliteParameter> parameters = new List <SqliteParameter>();
         parameters.Add(new SqliteParameter("@key", item.Key));
         parameters.Add(new SqliteParameter("@value", item.Value));
         SQLiteUtility.ExecuteCommand(connectionString, commandText, parameters);
         return(true);
     }
 }
예제 #5
0
 public string this[string key]
 {
     get
     {
         if (SQLiteUtility.IsNull(key))
         {
             throw new ArgumentNullException();
         }
         else if (!ContainsKey(key))
         {
             throw new KeyNotFoundException();
         }
         else
         {
             string query = $"SELECT Value FROM {tableName} WHERE Key = @key";
             List <SqliteParameter> parameters = new List <SqliteParameter>();
             parameters.Add(new SqliteParameter("@key", key));
             return(SQLiteUtility.GetQueryResult(connectionString, query, parameters).Rows[0][0]);
         }
     }
     set
     {
         if (SQLiteUtility.IsNull(key))
         {
             throw new ArgumentNullException();
         }
         else if (!ContainsKey(key))
         {
             Add(key, value);
         }
         else
         {
             string commandText = $"UPDATE TABLE {tableName} SET Value = @value WHERE Key = @key";
             List <SqliteParameter> parameters = new List <SqliteParameter>();
             parameters.Add(new SqliteParameter("@key", key));
             parameters.Add(new SqliteParameter("@value", value));
             SQLiteUtility.ExecuteCommand(connectionString, commandText, parameters);
         }
     }
 }