Exemplo n.º 1
0
        /// <summary>
        /// Gets the differences between this set of table data and another.
        /// </summary>
        /// <param name="other">The other set of table data.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="scripts">A set of scripts to fill with the differences.</param>
        /// <returns>True if the two sets are different; otherwise false.</returns>
        private bool GetDifferences(TableData other, Name tableName, ScriptSet scripts)
        {
            if (Count == 0)
            {
                return(false);
            }

            if (other == null)
            {
                other = new TableData(Name);
            }

            StringBuilder   addScript    = new StringBuilder();
            StringBuilder   deleteScript = new StringBuilder();
            List <TableRow> testing      = new List <TableRow>(this);

            //this may not be the most efficient algorithm, but we have no index
            foreach (TableRow existing in other)
            {
                TableRow found = null;
                foreach (TableRow adding in testing)
                {
                    if (existing.Equals(adding))
                    {
                        found = adding;
                        break;
                    }
                }

                if (found == null)
                {
                    if (scripts == null)
                    {
                        return(true);
                    }

                    existing.GenerateDelete(deleteScript, tableName);
                }
                else
                {
                    testing.Remove(found);
                }
            }

            foreach (TableRow adding in testing)
            {
                if (scripts == null)
                {
                    return(true);
                }

                adding.GenerateInsert(addScript, tableName);
            }

            if (addScript.Length > 0)
            {
                scripts.Add(new Script(addScript.ToString(), tableName.Unescaped + "Data", ScriptType.TableData));
            }
            if (deleteScript.Length > 0)
            {
                scripts.Add(new Script(deleteScript.ToString(), tableName + "Data", ScriptType.TableRemoveData));
            }
            return(scripts != null && scripts.Count > 0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Is this set of table data the same as another?
 /// </summary>
 /// <param name="other">The other set of table data.</param>
 /// <returns></returns>
 public bool AreEqual(TableData other)
 {
     return(!GetDifferences(other, null, null));
 }