コード例 #1
0
        public void Add(TKey key, TValue value)
        {
            var stm = string.Format("INSERT INTO {0} ({1}, {2}) VALUES ({3}, {4})",
                                    _tableName,
                                    DBFields <TKey> .Fields, DBFields <TValue> .Fields,
                                    DBFields <TKey> .Values(key), DBFields <TValue> .Values(value));

            if (ExecuteNonQuery(stm))
            {
                try
                {
                    _dict.Add(key, value);
                }
                catch (ArgumentException) // dup keys, np
                {
                }
            }
        }
コード例 #2
0
 public TValue this[TKey key]
 {
     get { return(_dict[key]); }
     set
     {
         if (!_dict.ContainsKey(key))
         {
             Add(key, value);
         }
         else
         {
             var stm = string.Format("UPDATE {0} SET {1} WHERE {2}",
                                     _tableName,
                                     DBFields <TValue> .FieldsAndValues(value, " , "),
                                     DBFields <TKey> .FieldsAndValues(key, " AND "));
             if (ExecuteNonQuery(stm))
             {
                 _dict[key] = value;
             }
         }
     }
 }
コード例 #3
0
        public bool Remove(TKey key)
        {
            var stm = string.Format("DELETE FROM {0} WHERE {1}", _tableName, DBFields <TKey> .FieldsAndValues(key, " AND "));

            return(ExecuteNonQuery(stm) && _dict.Remove(key));
        }