示例#1
0
        public void Test_GoodMessage()
        {
            var msg = new UpdateValuesMessage();

            msg.WhereFields     = new string[] { "ff" };
            msg.HaveValues      = new string[] { null };  //where column ff has a null value
            msg.WriteIntoFields = new string[] { "ff" };
            msg.Values          = new string[] { "ddd" }; //write the value ddd

            msg.Validate();
        }
示例#2
0
        public int HandleUpdate(UpdateValuesMessage message)
        {
            message.Validate();

            ITableInfo[] tables;
            int          affectedRows = 0;

            if (message.ExplicitTableInfo != null && message.ExplicitTableInfo.Length != 0)
            {
                tables = _repository.GetAllObjectsInIDList(typeof(TableInfo), message.ExplicitTableInfo).Cast <ITableInfo>().ToArray();

                if (tables.Length != message.ExplicitTableInfo.Length)
                {
                    throw new Exception($"Could not find all TableInfos IDs={string.Join(",",message.ExplicitTableInfo)}.  Found {tables.Length}:{string.Join(",",tables.Select(t=>t.ID))}");
                }
            }
            else
            {
                tables = GetAllTables(message.WhereFields.Union(message.WriteIntoFields).ToArray()).ToArray();

                if (tables.Length == 0)
                {
                    throw new Exception($"Could not find any tables to update that matched the field set {message}");
                }
            }

            //TODO: Expose IsView in ITableInfo in RDMP so we don't need this cast
            //don't try to update views
            tables = tables.Where(t => !((TableInfo)t).IsView).ToArray();

            foreach (var t in tables)
            {
                var tbl = t.Discover(ReusableLibraryCode.DataAccess.DataAccessContext.DataLoad);

                if (!tbl.Exists())
                {
                    throw new Exception($"Table {tbl} did not exist");
                }

                affectedRows += UpdateTable(tbl, message);
            }

            return(affectedRows);
        }