Exemple #1
0
        public bool RemoveKey(MetadataKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (!key.IsValid())
            {
                throw new ArgumentException(@"Key is invalid.", "key");
            }
            var typeId = (int)key.Type;

            if (typeId != -1)
            {
                lock (lockObject)
                {
                    if (connection != null)
                    {
                        string query = String.Format(@"DELETE FROM `Keys` WHERE `Keys`.`TypeId` = '{0}' AND `Keys`.`Name` = '{1}'", typeId, key.Name);
                        return(ExecuteNonQuery(query) == 1);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        public bool AddKey(MetadataKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (!key.IsValid())
            {
                throw new ArgumentException(@"Key is invalid.", "key");
            }
            var typeId = (int)key.Type;

            if (typeId != -1)
            {
                lock (lockObject)
                {
                    if (connection != null)
                    {
                        // TODO/Benlitz: a transaction that first try to fetch the key. If it exists, it should return false
                        string query = String.Format(@"INSERT INTO `Keys` (`TypeId`, `Name`) VALUES ('{0}', '{1}')", typeId, key.Name);
                        return(ExecuteNonQuery(query) == 1);
                    }
                }
            }
            return(false);
        }