Beispiel #1
0
        public virtual void Update(string tableName, Dictionary<string, object> dataFields, Dictionary<string, object> keyFields)
        {
            if (!Analyzer.TableExists(tableName))
                if (StrictTables)
                    throw new NotATableException(tableName);
                else
                    return;

            var sql = MakeUpdateSql(tableName, dataFields, keyFields);

            var data = dataFields.SelectKeys(key => "data" + key);
            var keys = keyFields.SelectKeys(key => "key" + key);

            sqlUpdate(sql, data.Union(keys));
        }
Beispiel #2
0
        /// <summary>Like Update, but less magic. Does not require an autokey prime number.</summary>
        /// <param name="dataFields">The fields with data to be udpated in the affected records</param>
        /// <param name="keyFields">The identifying fields for which records to update</param>
        public void RealUpdate(string tableName, Dictionary<string, object> dataFields, Dictionary<string, object> keyFields, ITransaction transaction = null)
        {
            var sql = "UPDATE " + tableName + " SET " + dataFields.Keys.Select(x => x + " = @data" + x).Join(", ") + "\n";
            sql += "WHERE " + keyFields.Select(x => x.Key + " = @key" + x.Key).Join(" AND ");

            var data = dataFields.SelectKeys(key => "data" + key);
            var keys = keyFields.SelectKeys(key => "key" + key);

            sqlUpdate(sql, transaction, data.Union(keys));
        }
Beispiel #3
0
        /// <param name="dataFields">The fields with data to be udpated in the affected records</param>
        /// <param name="keyFields">The identifying fields for which records to update</param>
        public void Update(string tableName, Dictionary<string, object> dataFields, Dictionary<string, object> keyFields, ITransaction transaction = null)
        {
            var autoKey = _dbAnalyzer.GetAutoNumberKey(tableName);

            var dataFieldNames = dataFields.Keys.Where(key => key != autoKey);
            var dbFields = _dbAnalyzer.GetFields(tableName);
            // Don't try to set fields that don't exist in the database
            if (dbFields.Any()) // If we don't get anything back, that means we don't know what the DB fields are
                dataFieldNames = dataFieldNames.Intersect(dbFields);

            var sql = "UPDATE " + tableName + " SET " + dataFieldNames.Select(x => x + " = @data" + x).Join(", ") + "\n";
            sql += "WHERE " + keyFields.Select(x => x.Key + " = @key" + x.Key).Join(" AND ");

            var data = dataFields.SelectKeys(key => "data" + key);
            var keys = keyFields.SelectKeys(key => "key" + key);

            sqlUpdate(sql, transaction, data.Union(keys));
        }
 public void SelectKeysTest()
 {
     Dictionary<int, int> dict = new Dictionary<int, int>();
     dict.Add(1, 1);
     dict.Add(2, 2);
     dict.Add(3, 3);
     Dictionary<decimal, int> dictCopy = new Dictionary<decimal, int>();
     dictCopy.Add(1, 1);
     dictCopy.Add(2, 2);
     dictCopy.Add(3, 3);
     Assert.AreEqual(dictCopy, dict.SelectKeys(k => k.ConvertTo<decimal>()));
 }