Esempio n. 1
0
        /// <see cref="NI.Data.IDalc.Update(NI.Data.Query,System.Collections.Generic.IDictionary<System.String,NI.Data.IQueryValue>)"/>
        public int Update(Query query, IDictionary <string, IQueryValue> data)
        {
            if (!PersistedDS.Tables.Contains(query.Table))
            {
                throw new Exception("Persisted dataset does not contain table with name " + query.Table);
            }

            string whereExpression = SqlBuilder.BuildExpression(query.Condition);

            DataRow[] result = PersistedDS.Tables[query.Table].Select(whereExpression);
            for (int i = 0; i < result.Length; i++)
            {
                foreach (var fieldValue in data)
                {
                    if (fieldValue.Value != null && !(fieldValue.Value is QConst))
                    {
                        throw new NotSupportedException(
                                  String.Format("DatasetDalc doesn't support {0} as value for Update", fieldValue.Value.GetType()));
                    }
                    result[i][fieldValue.Key] = fieldValue.Value != null ? ((QConst)fieldValue.Value).Value : DBNull.Value;
                }
            }
            PersistedDS.AcceptChanges();
            return(result.Length);
        }
Esempio n. 2
0
        /// <see cref="NI.Data.IDalc.Delete(NI.Data.Query)"/>
        public int Delete(Query query)
        {
            if (!PersistedDS.Tables.Contains(query.Table))
            {
                throw new Exception("Persisted dataset does not contain table with name " + query.Table);
            }

            string whereExpression = SqlBuilder.BuildExpression(query.Condition);

            DataRow[] result = PersistedDS.Tables[query.Table].Select(whereExpression);
            for (int i = 0; i < result.Length; i++)
            {
                result[i].Delete();
            }
            PersistedDS.AcceptChanges();
            return(result.Length);
        }
Esempio n. 3
0
        /// <see cref="NI.Data.IDalc.Insert(System.String,System.Collections.Generic.IDictionary<System.String,NI.Data.IQueryValue>)"/>
        public void Insert(string tableName, IDictionary <string, IQueryValue> data)
        {
            if (!PersistedDS.Tables.Contains(tableName))
            {
                throw new Exception("Persisted dataset does not contain table with name " + tableName);
            }

            DataRow row = PersistedDS.Tables[tableName].NewRow();

            foreach (var fldVal in data)
            {
                if (fldVal.Value != null && !(fldVal.Value is QConst))
                {
                    throw new NotSupportedException(
                              String.Format("DatasetDalc doesn't support {0} as value for Insert", fldVal.Value.GetType()));
                }
                row[fldVal.Key] = fldVal.Value != null ? ((QConst)fldVal.Value).Value : DBNull.Value;
            }
            PersistedDS.Tables[tableName].Rows.Add(row);
            PersistedDS.AcceptChanges();
        }