HasVersion() public method

Gets a value indicating whether a specified version exists.
public HasVersion ( DataRowVersion version ) : bool
version DataRowVersion
return bool
        //Journalise les données d'un élement
        public CVersionDonneesObjet JournaliseDonnees(System.Data.DataRow row, CVersionDonnees version)
        {
            CVersionDonneesObjet versionObjet = null;

            if (row.RowState != DataRowState.Added &&
                row.RowState != DataRowState.Modified &&
                row.RowState != DataRowState.Deleted)
            {
                return(null);
            }
            Type typeElement = CContexteDonnee.GetTypeForTable(row.Table.TableName);

            versionObjet = version.GetVersionObjetAvecCreation(row);
            if (versionObjet == null)
            {
                return(null);
            }
            if (row.HasVersion(DataRowVersion.Original))
            {
                CStructureTable structure = CStructureTable.GetStructure(typeElement);

                foreach (CInfoChampTable info in structure.Champs)
                {
                    if (info.m_bIsInDB)
                    {
                        new CJournaliseurChampDb().JournaliseDonneeInContexte(versionObjet, info.NomChamp, row);
                    }
                }
            }
            return(versionObjet);
        }
Exemplo n.º 2
0
        internal override void AssertConstraint(DataRow row)
        {
            if (IsPrimaryKey && row.HasVersion(DataRowVersion.Default))
            {
                for (int i = 0; i < Columns.Length; i++)
                {
                    if (row.IsNull(Columns[i]))
                    {
                        throw new NoNullAllowedException("Column '" + Columns[i].ColumnName + "' does not allow nulls.");
                    }
                }
            }

#if NOT_PFX
            if (Index == null)
            {
                Index = Table.GetIndex(Columns, null, DataViewRowState.None, null, false);
            }

            if (Index.HasDuplicates)
            {
                throw new ConstraintException(GetErrorMessage(row));
            }
#endif
        }
Exemplo n.º 3
0
        internal static DataRow?GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version)
        {
            if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current))
            {
                if (childRow._tempRecord == -1)
                {
                    return(null);
                }
            }

            object[] values = childRow.GetKeyValues(childKey, version);
            if (IsKeyNull(values))
            {
                return(null);
            }

            Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);
            Range range = index.FindRecords(values);

            if (range.IsNull)
            {
                return(null);
            }

            if (range.Count > 1)
            {
                throw ExceptionBuilder.MultipleParents();
            }

            return(parentKey.Table._recordManager[index.GetRecord(range.Min)]);
        }
Exemplo n.º 4
0
        internal override void CheckConstraint(DataRow childRow, DataRowAction action)
        {
            if ((action == DataRowAction.Change ||
                 action == DataRowAction.Add ||
                 action == DataRowAction.Rollback) &&
                Table.DataSet != null && Table.DataSet.EnforceConstraints &&
                childRow.HasKeyChanged(_childKey))
            {
                // This branch is for cascading case verification.
                DataRowVersion version        = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
                object[]       childKeyValues = childRow.GetKeyValues(_childKey);
                // check to see if this is just a change to my parent's proposed value.
                if (childRow.HasVersion(version))
                {
                    // this is the new proposed value for the parent.
                    DataRow parentRow = DataRelation.GetParentRow(ParentKey, ChildKey, childRow, version);
                    if (parentRow != null && parentRow._inCascade)
                    {
                        object[] parentKeyValues = parentRow.GetKeyValues(_parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);

                        int parentKeyValuesRecord = childRow.Table.NewRecord();
                        childRow.Table.SetKeyValues(_childKey, parentKeyValues, parentKeyValuesRecord);
                        if (_childKey.RecordsEqual(childRow._tempRecord, parentKeyValuesRecord))
                        {
                            return;
                        }
                    }
                }

                // now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
                object[] childValues = childRow.GetKeyValues(_childKey);
                if (!IsKeyNull(childValues))
                {
                    Index parentIndex = _parentKey.GetSortIndex();
                    if (!parentIndex.IsKeyInIndex(childValues))
                    {
                        // could be self-join constraint
                        if (_childKey.Table == _parentKey.Table && childRow._tempRecord != -1)
                        {
                            int lo = 0;
                            for (lo = 0; lo < childValues.Length; lo++)
                            {
                                DataColumn column = _parentKey.ColumnsReference[lo];
                                object     value  = column.ConvertValue(childValues[lo]);
                                if (0 != column.CompareValueTo(childRow._tempRecord, value))
                                {
                                    break;
                                }
                            }
                            if (lo == childValues.Length)
                            {
                                return;
                            }
                        }
                        throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
            if ((this.column == null) || (this.relation == null))
            {
                throw ExprException.ExpressionUnbound(this.ToString());
            }
            DataRow parentRow = row.GetParentRow(this.relation, version);

            if (parentRow == null)
            {
                return(DBNull.Value);
            }
            return(parentRow[this.column, parentRow.HasVersion(version) ? version : DataRowVersion.Current]);
        }
Exemplo n.º 6
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
            if (_column == null || _relation == null)
            {
                throw ExprException.ExpressionUnbound(ToString());
            }

            DataRow parent = row.GetParentRow(_relation, version);

            if (parent == null)
            {
                return(DBNull.Value);
            }

            return(parent[_column, parent.HasVersion(version) ? version : DataRowVersion.Current]);
        }
Exemplo n.º 7
0
 internal override void CheckConstraint(DataRow childRow, DataRowAction action)
 {
     if (((((action == DataRowAction.Change) || (action == DataRowAction.Add)) || (action == DataRowAction.Rollback)) && ((this.Table.DataSet != null) && this.Table.DataSet.EnforceConstraints)) && childRow.HasKeyChanged(this.childKey))
     {
         DataRowVersion version   = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
         object[]       keyValues = childRow.GetKeyValues(this.childKey);
         if (childRow.HasVersion(version))
         {
             DataRow row = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
             if ((row != null) && row.inCascade)
             {
                 object[] objArray2 = row.GetKeyValues(this.parentKey, (action == DataRowAction.Rollback) ? version : DataRowVersion.Default);
                 int      record    = childRow.Table.NewRecord();
                 childRow.Table.SetKeyValues(this.childKey, objArray2, record);
                 if (this.childKey.RecordsEqual(childRow.tempRecord, record))
                 {
                     return;
                 }
             }
         }
         object[] values = childRow.GetKeyValues(this.childKey);
         if (!this.IsKeyNull(values) && !this.parentKey.GetSortIndex().IsKeyInIndex(values))
         {
             if ((this.childKey.Table == this.parentKey.Table) && (childRow.tempRecord != -1))
             {
                 int index = 0;
                 index = 0;
                 while (index < values.Length)
                 {
                     DataColumn column = this.parentKey.ColumnsReference[index];
                     object     obj2   = column.ConvertValue(values[index]);
                     if (column.CompareValueTo(childRow.tempRecord, obj2) != 0)
                     {
                         break;
                     }
                     index++;
                 }
                 if (index == values.Length)
                 {
                     return;
                 }
             }
             throw ExceptionBuilder.ForeignKeyViolation(this.ConstraintName, keyValues);
         }
     }
 }
Exemplo n.º 8
0
        internal override object Eval(DataRow row, DataRowVersion version)
        {
#if DEBUG
            if (CompModSwitches.LookupNode.TraceVerbose)
            {
                Debug.WriteLine("Eval " + this.ToString());
            }
#endif

            if (table == null || column == null || relation == null)
            {
                throw ExprException.ExpressionUnbound(this.ToString());
            }

            DataRow parent = row.GetParentRow(relation, version);
            if (parent == null)
            {
                return(DBNull.Value);
            }

            return(parent[column, parent.HasVersion(version) ? version : DataRowVersion.Current]); // haroona : Bug 76154
        }
Exemplo n.º 9
0
		internal void CopyRow (DataRow fromRow, DataRow toRow)
		{
			if (fromRow.HasErrors)
				fromRow.CopyErrors (toRow);

			if (fromRow.HasVersion (DataRowVersion.Original))
				toRow.Original = toRow.Table.RecordCache.CopyRecord (this, fromRow.Original, -1);

			if (fromRow.HasVersion (DataRowVersion.Current)) {
				if (fromRow.Original != fromRow.Current)
					toRow.Current = toRow.Table.RecordCache.CopyRecord (this, fromRow.Current, -1);
				else
					toRow.Current = toRow.Original;
			}
		}
 internal int[] InsertRecordToIndexes(DataRow row, DataRowVersion version)
 {
     int count = this.LiveIndexes.Count;
     int[] numArray = new int[count];
     int recordFromVersion = row.GetRecordFromVersion(version);
     DataViewRowState recordState = row.GetRecordState(recordFromVersion);
     while (--count >= 0)
     {
         if (row.HasVersion(version))
         {
             if ((recordState & this.indexes[count].RecordStates) != DataViewRowState.None)
             {
                 numArray[count] = this.indexes[count].InsertRecordToIndex(recordFromVersion);
             }
             else
             {
                 numArray[count] = -1;
             }
         }
     }
     return numArray;
 }
Exemplo n.º 11
0
		private void CheckRowVersion(DataRow dr)
		{
			Console.WriteLine("");
			if (dr.HasVersion(DataRowVersion.Current)) Console.WriteLine("Has " + DataRowVersion.Current.ToString());
			if (dr.HasVersion(DataRowVersion.Default)) Console.WriteLine("Has " + DataRowVersion.Default.ToString());
			if (dr.HasVersion(DataRowVersion.Original)) Console.WriteLine("Has " + DataRowVersion.Original.ToString());
			if (dr.HasVersion(DataRowVersion.Proposed)) Console.WriteLine("Has " + DataRowVersion.Proposed.ToString());
		}
 internal override void CheckConstraint(DataRow childRow, DataRowAction action)
 {
     if (((((action == DataRowAction.Change) || (action == DataRowAction.Add)) || (action == DataRowAction.Rollback)) && ((this.Table.DataSet != null) && this.Table.DataSet.EnforceConstraints)) && childRow.HasKeyChanged(this.childKey))
     {
         DataRowVersion version = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
         object[] keyValues = childRow.GetKeyValues(this.childKey);
         if (childRow.HasVersion(version))
         {
             DataRow row = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
             if ((row != null) && row.inCascade)
             {
                 object[] objArray2 = row.GetKeyValues(this.parentKey, (action == DataRowAction.Rollback) ? version : DataRowVersion.Default);
                 int record = childRow.Table.NewRecord();
                 childRow.Table.SetKeyValues(this.childKey, objArray2, record);
                 if (this.childKey.RecordsEqual(childRow.tempRecord, record))
                 {
                     return;
                 }
             }
         }
         object[] values = childRow.GetKeyValues(this.childKey);
         if (!this.IsKeyNull(values) && !this.parentKey.GetSortIndex().IsKeyInIndex(values))
         {
             if ((this.childKey.Table == this.parentKey.Table) && (childRow.tempRecord != -1))
             {
                 int index = 0;
                 index = 0;
                 while (index < values.Length)
                 {
                     DataColumn column = this.parentKey.ColumnsReference[index];
                     object obj2 = column.ConvertValue(values[index]);
                     if (column.CompareValueTo(childRow.tempRecord, obj2) != 0)
                     {
                         break;
                     }
                     index++;
                 }
                 if (index == values.Length)
                 {
                     return;
                 }
             }
             throw ExceptionBuilder.ForeignKeyViolation(this.ConstraintName, keyValues);
         }
     }
 }
 internal int[] RemoveRecordFromIndexes(DataRow row, DataRowVersion version)
 {
     int count = this.LiveIndexes.Count;
     int[] numArray = new int[count];
     int recordFromVersion = row.GetRecordFromVersion(version);
     DataViewRowState recordState = row.GetRecordState(recordFromVersion);
     while (--count >= 0)
     {
         if (row.HasVersion(version) && ((recordState & this.indexes[count].RecordStates) != DataViewRowState.None))
         {
             int index = this.indexes[count].GetIndex(recordFromVersion);
             if (index > -1)
             {
                 numArray[count] = index;
                 this.indexes[count].DeleteRecordFromIndex(index);
             }
             else
             {
                 numArray[count] = -1;
             }
         }
         else
         {
             numArray[count] = -1;
         }
     }
     return numArray;
 }
Exemplo n.º 14
0
// RemoveRecordFromIndexes removes the given record (using row and version) from all indexes and it  stores and returns the position of deleted
// record from each index
// IT SHOULD NOT CAUSE ANY EVENT TO BE FIRED
        internal int[] RemoveRecordFromIndexes(DataRow row, DataRowVersion  version) {
            int    indexCount          =  LiveIndexes.Count;
            int [] positionIndexes =  new int[indexCount];

            int recordNo = row.GetRecordFromVersion(version);
            DataViewRowState states = row.GetRecordState(recordNo);

            while (--indexCount >= 0) {
                if (row.HasVersion(version) && ((states & indexes[indexCount].RecordStates) != DataViewRowState.None)) {
                    int index = indexes[indexCount].GetIndex(recordNo);
                    if (index > -1) {
                        positionIndexes [indexCount] = index;
                        indexes[indexCount].DeleteRecordFromIndex(index); // this will delete the record from index and MUSt not fire event
                    }
                    else {
                        positionIndexes [indexCount] = -1; // this means record was not in index
                    }
                }
                else {
                    positionIndexes [indexCount] = -1; // this means record was not in index
                }
            }
            return positionIndexes;
        }
Exemplo n.º 15
0
        internal void SilentlySetValue(DataRow dr, DataColumn dc, DataRowVersion version, object newValue) {
            // get record for version
            int record = dr.GetRecordFromVersion(version);

            bool equalValues = false;
            if (DataStorage.IsTypeCustomType(dc.DataType) && newValue != dc[record]) {
                // if UDT storage, need to check if reference changed. See bug 385182
                equalValues = false;
            }
            else {
                equalValues = dc.CompareValueTo(record, newValue, true);
            }

            // if expression has changed
            if (!equalValues) {
                int[] oldIndex = dr.Table.RemoveRecordFromIndexes(dr, version);// conditional, if it exists it will try to remove with no event fired
                dc.SetValue(record, newValue);
                int[] newIndex = dr.Table.InsertRecordToIndexes(dr, version);// conditional, it will insert if it qualifies, no event will be fired
                if (dr.HasVersion(version)) {
                    if (version != DataRowVersion.Original) {
                        dr.Table.RecordChanged(oldIndex, newIndex);
                    }
                    if (dc.dependentColumns != null) {
                        //BugBug - passing in null for cachedRows.  This means expression columns as keys does not work when key changes.
                        dc.Table.EvaluateDependentExpressions(dc.dependentColumns, dr, version, null);
                    }
                }
             }
             dr.ResetLastChangedColumn();
        }
Exemplo n.º 16
0
		internal override void AssertConstraint(DataRow row)
		{	
			if (IsPrimaryKey && row.HasVersion(DataRowVersion.Default)) {
				for (int i = 0; i < Columns.Length; i++) {
					if (row.IsNull(Columns[i])) {
						throw new NoNullAllowedException("Column '" + Columns[i].ColumnName + "' does not allow nulls.");
					}
				}
			}
			
			if (Index == null) {
				Index = Table.GetIndex(Columns,null,DataViewRowState.None,null,false);
			}

			if (Index.HasDuplicates) {
				throw new ConstraintException(GetErrorMessage(row));
			}
		}
Exemplo n.º 17
0
        internal static DataRow GetParentRow(DataKey parentKey, DataKey childKey, DataRow childRow, DataRowVersion version) {
            if (!childRow.HasVersion((version == DataRowVersion.Original) ? DataRowVersion.Original : DataRowVersion.Current))
                if (childRow.tempRecord == -1)
                    return null;

            object[] values = childRow.GetKeyValues(childKey, version);
            if (IsKeyNull(values)) {
                return null;
            }

            Index index = parentKey.GetSortIndex((version == DataRowVersion.Original) ? DataViewRowState.OriginalRows : DataViewRowState.CurrentRows);
            Range range = index.FindRecords(values);
            if (range.IsNull) {
                return null;
            }

            if (range.Count > 1) {
                throw ExceptionBuilder.MultipleParents();
            }
            return parentKey.Table.recordManager[index.GetRecord(range.Min)];
        }
Exemplo n.º 18
0
        /// <summary>
        /// Checks, if value of given column of given row is changed.
        /// </summary>
        /// <param name="row">DataRow with values to check.</param>
        /// <param name="column">Column name.</param>
        /// <returns>
        /// If original value is not null, use returns Equals. Otherwise returns 
        /// true if current value is null too.
        /// </returns>
        public static bool HasChanged(DataRow row, string column)
        {
            if (row == null)
                throw new ArgumentNullException("row");
            if (String.IsNullOrEmpty(column))
                throw new ArgumentException(Resources.Error_EmptyString, "column");

            // If new row or deleted row, then it definetelly changed
            if (row.RowState == DataRowState.Deleted || row.RowState == DataRowState.Added)
                return true;

            // Check for availble versions
            if (!row.HasVersion(DataRowVersion.Original)
                || !row.HasVersion(DataRowVersion.Current))
            {
                // Nothing to compare
                return false;
            }

            // Get values
            object original = row[column, DataRowVersion.Original];
            object current = row[column, DataRowVersion.Current];

            // If original is not null, use Equals. Otherwise current should be null to.
            return !CompareObjects(original, current);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Builds DROP FOREIGN KEY statement
        /// </summary>
        /// <param name="target">String builder, used to build query.</param>
        /// <param name="key">DataRow with foreign key data.</param>
        private void BuildDropForeignKey(StringBuilder target, DataRow key)
        {
            target.Append("\nDROP FOREIGN KEY ");
            QueryBuilder.WriteOldIdentifier(key, ForeignKey.Name, target);

            // Write trailing ","
            target.Append(",");

            // If we have index with same name, drop it too
            if (key.HasVersion(DataRowVersion.Original))
            {
                DataRow index = FindIndex(DataInterpreter.GetStringNotNull(key, ForeignKey.Name, DataRowVersion.Original));
                if (index != null)
                    BuildDropIndex(target, index);
            }
        }
Exemplo n.º 20
0
        //-------------------------------------------------------------------------
        public CVersionDonneesObjet JournaliseDonnees(System.Data.DataRow row, CVersionDonnees version)
        {
            if (row.RowState == DataRowState.Modified ||
                row.RowState == DataRowState.Added ||
                row.RowState == DataRowState.Deleted)
            {
                Type tp = CContexteDonnee.GetTypeForTable(row.Table.TableName);
                if (!typeof(CRelationElementAChamp_ChampCustom).IsAssignableFrom(tp))
                {
                    return(null);
                }
                //Récupère l'objet associé
                DataRowVersion rowVersion = DataRowVersion.Current;
                if (row.RowState == DataRowState.Deleted)
                {
                    if (row.HasVersion(DataRowVersion.Original))
                    {
                        rowVersion = DataRowVersion.Original;
                    }
                    else
                    {
                        return(null);
                    }
                }
                CRelationElementAChamp_ChampCustom rel = (CRelationElementAChamp_ChampCustom)Activator.CreateInstance(tp, new object[] { row });
                rel.VersionToReturn = rowVersion;
                try
                {
                    IElementAChamps objet = rel.ElementAChamps;
                    //Si l'objet est ajouté, on n'archive pas !
                    if (objet is CObjetDonneeAIdNumerique &&
                        ((CObjetDonneeAIdNumerique)objet).Row.RowState != DataRowState.Added)
                    {
                        CObjetDonneeAIdNumerique objetAId = (CObjetDonneeAIdNumerique)objet;
                        if (objetAId != null)
                        {
                            //Récupère un version pour l'objet
                            CVersionDonneesObjet versionObjet = version.GetVersionObjetAvecCreation(objetAId.Row.Row);
                            if (versionObjet == null)
                            {
                                return(null);
                            }

                            //Stef 14082008 : en cas d'ajout, on ne fait rien. le datarow de l'objet n'est pas added
                            //car l'objet a déjà été sauvé quand on passe par là !
                            if (versionObjet.CodeTypeOperation == (int)CTypeOperationSurObjet.TypeOperation.Ajout)
                            {
                                return(null);
                            }

                            new CJournaliseurValeurChampCustom().JournaliseDonneeInContexte(versionObjet, rel.ChampCustom, row);
                            return(versionObjet);
                        }
                    }
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 21
0
		/// <summary>
		/// Copies a DataRow into a DataTable, preserving any
		/// property settings, as well as original and current values.
		/// </summary>
		public void ImportRow (DataRow row)
		{
			if (row.RowState == DataRowState.Detached)
				return;

			DataRow newRow = NewNotInitializedRow ();

			int original = -1;
			if (row.HasVersion (DataRowVersion.Original)) {
				original = row.IndexFromVersion (DataRowVersion.Original);
				newRow.Original = RecordCache.NewRecord ();
				RecordCache.CopyRecord (row.Table, original, newRow.Original);
			}

			if (row.HasVersion (DataRowVersion.Current)) {
				int current = row.IndexFromVersion (DataRowVersion.Current);
				if (current == original) {
					newRow.Current = newRow.Original;
				} else {
					newRow.Current = RecordCache.NewRecord ();
					RecordCache.CopyRecord (row.Table, current, newRow.Current);
				}
			}

			//Import the row only if RowState is not detached
			//Validation for Deleted Rows happens during Accept/RejectChanges
			if (row.RowState != DataRowState.Deleted)
				newRow.Validate ();
			else
				AddRowToIndexes (newRow);
			Rows.AddInternal(newRow);

			if (row.HasErrors)
				row.CopyErrors (newRow);
		}
Exemplo n.º 22
0
		/// <summary>
		/// Copies a DataRow into a DataTable, preserving any 
		/// property settings, as well as original and current values.
		/// </summary>
		public void ImportRow (DataRow row) 
		{
			DataRow newRow = NewNotInitializedRow();

			int original = -1;
			if (row.HasVersion(DataRowVersion.Original)) {
				original = row.IndexFromVersion(DataRowVersion.Original);
				newRow.Original = RecordCache.NewRecord();
				RecordCache.CopyRecord(row.Table,original,newRow.Original);
			}

			if (row.HasVersion(DataRowVersion.Current)) {
				int current = row.IndexFromVersion(DataRowVersion.Current);
				if (current == original)
					newRow.Current = newRow.Original;
				else {
					newRow.Current = RecordCache.NewRecord();
					RecordCache.CopyRecord(row.Table,current,newRow.Current);
				}
			}

			if (EnforceConstraints)
				// we have to check that the new row doesn't colide with existing row
				Rows.ValidateDataRowInternal(newRow);

			Rows.AddInternal(newRow);		
	
			if (row.HasErrors) {
				row.CopyErrors(newRow);
			}
		}
Exemplo n.º 23
0
        internal override void CheckConstraint(DataRow childRow, DataRowAction action) {
            if ((action == DataRowAction.Change ||
                 action == DataRowAction.Add ||
                 action == DataRowAction.Rollback) &&
                Table.DataSet != null && Table.DataSet.EnforceConstraints &&
                childRow.HasKeyChanged(childKey)) {

                // This branch is for cascading case verification.
                DataRowVersion version = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
                object[] childKeyValues = childRow.GetKeyValues(childKey);
                // check to see if this is just a change to my parent's proposed value.
                if (childRow.HasVersion(version)) {
                    // this is the new proposed value for the parent.
                    DataRow parentRow = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
                    if(parentRow != null && parentRow.inCascade) {
                        object[] parentKeyValues = parentRow.GetKeyValues(parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);

                        int parentKeyValuesRecord = childRow.Table.NewRecord();
                        childRow.Table.SetKeyValues(childKey, parentKeyValues, parentKeyValuesRecord);
                        if (childKey.RecordsEqual(childRow.tempRecord, parentKeyValuesRecord)) {
                            return;
                        }
                    }
                }

                // now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
                object[] childValues = childRow.GetKeyValues(childKey);
                if (!IsKeyNull(childValues)) {
                    Index parentIndex = parentKey.GetSortIndex();
                    if (!parentIndex.IsKeyInIndex(childValues)) {
                        // could be self-join constraint
                        if (childKey.Table == parentKey.Table && childRow.tempRecord != -1) {
                            int lo = 0;
                            for (lo = 0; lo < childValues.Length; lo++) {
                                DataColumn column = parentKey.ColumnsReference[lo];
                                object value = column.ConvertValue(childValues[lo]);
                                if (0 != column.CompareValueTo(childRow.tempRecord, value)) {
                                    break;
                                }
                            }
                            if (lo == childValues.Length) {
                                return;
                            }
                        }
                        throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
                    }
                }
            }
        }
Exemplo n.º 24
0
    private bool IsChanged(DataRow row, DataColumn col, out object newValue)
    {
      newValue = null;
      if (!row.HasVersion(DataRowVersion.Original) || !row.HasVersion(DataRowVersion.Current))
        return false;
      var orig = row[col, DataRowVersion.Original];
      var curr = row[col, DataRowVersion.Current];

      if (orig == DBNull.Value && curr == DBNull.Value)
        return false;

      newValue = curr;
      if (orig == DBNull.Value && curr == DBNull.Value)
        return true;

      return !orig.Equals(curr);
    }
Exemplo n.º 25
0
 private string GetDataRowInfo(DataRow row, string columnName)
 {
     string retVal = string.Format(
         "RowState: {0} \r\n",
         row.RowState);
     foreach (string versionString in Enum.GetNames(typeof (DataRowVersion)))
     {
         DataRowVersion version = (
                                  DataRowVersion) Enum.Parse(
                                      typeof (DataRowVersion), versionString);
         if (row.HasVersion(version))
         {
             retVal += string.Format(
                 "Version: {0} Value: {1} \r\n",
                 version, row[columnName, version]);
         }
         else
         {
             retVal += string.Format(
                 "Version: {0} does not exist.\r\n",
                 version);
         }
     }
     return retVal;
 }
 internal void SilentlySetValue(DataRow dr, DataColumn dc, DataRowVersion version, object newValue)
 {
     int recordFromVersion = dr.GetRecordFromVersion(version);
     bool flag = false;
     if (DataStorage.IsTypeCustomType(dc.DataType) && (newValue != dc[recordFromVersion]))
     {
         flag = false;
     }
     else
     {
         flag = dc.CompareValueTo(recordFromVersion, newValue, true);
     }
     if (!flag)
     {
         int[] oldIndex = dr.Table.RemoveRecordFromIndexes(dr, version);
         dc.SetValue(recordFromVersion, newValue);
         int[] newIndex = dr.Table.InsertRecordToIndexes(dr, version);
         if (dr.HasVersion(version))
         {
             if (version != DataRowVersion.Original)
             {
                 dr.Table.RecordChanged(oldIndex, newIndex);
             }
             if (dc.dependentColumns != null)
             {
                 dc.Table.EvaluateDependentExpressions(dc.dependentColumns, dr, version, null);
             }
         }
     }
     dr.ResetLastChangedColumn();
 }
Exemplo n.º 27
0
// InsertRecordToIndexes inserts the given record (using row and version) to all indexes and it  stores and returns the position of inserted
// record to each index
// IT SHOULD NOT CAUSE ANY EVENT TO BE FIRED
        internal int[] InsertRecordToIndexes(DataRow row, DataRowVersion  version) {
            int    indexCount          =  LiveIndexes.Count;
            int [] positionIndexes =  new int[indexCount];

            int recordNo = row.GetRecordFromVersion(version);
            DataViewRowState states = row.GetRecordState(recordNo);

            while (--indexCount >= 0) {
                if (row.HasVersion(version)) {
                    if ((states & indexes[indexCount].RecordStates) != DataViewRowState.None) {
                        positionIndexes [indexCount] = indexes[indexCount].InsertRecordToIndex(recordNo);
                    }
                    else {
                        positionIndexes [indexCount] = -1;
                    }
                }
            }
            return positionIndexes;
        }
        private void BuildRowInfo(StringBuilder builder, DataRow row)
        {
            if (row==null)
            {
                return;
            }
            builder.AppendLine("Row State :" + row.RowState );
            builder.AppendLine("Columns: ");
            foreach (DataColumn column in row.Table.Columns)
            {
                object value ;
                if (row.HasVersion(DataRowVersion.Current))
                {
                    value = row[column];
                }
                else
                {
                    value = row[column, DataRowVersion.Original];
                }

                builder.AppendLine(string.Format("{0} = {1};", column.ColumnName, value));

            }
        }
Exemplo n.º 29
0
        internal override void CheckConstraint(DataRow childRow, DataRowAction action)
        {
            Debug.Assert(Table.DataSet != null, "Relation " + ConstraintName + " isn't part of a DataSet, so this check shouldn't be happening.");
            if ((action == DataRowAction.Change ||
                 action == DataRowAction.Add ||
                 action == DataRowAction.Rollback) &&
                Table.DataSet != null && Table.DataSet.EnforceConstraints &&
                childRow.HasKeyChanged(childKey))
            {
                // This branch is for cascading case verification.
                DataRowVersion version        = (action == DataRowAction.Rollback) ? DataRowVersion.Original : DataRowVersion.Current;
                object[]       childKeyValues = childRow.GetKeyValues(childKey);
                // check to see if this is just a change to my parent's proposed value.
                if (childRow.HasVersion(version))
                {
                    // this is the new proposed value for the parent.
                    DataRow parentRow = DataRelation.GetParentRow(this.ParentKey, this.ChildKey, childRow, version);
                    if (parentRow != null && parentRow.inCascade)
                    {
                        object[] parentKeyValues = parentRow.GetKeyValues(parentKey, action == DataRowAction.Rollback ? version : DataRowVersion.Default);

#if DEBUG
                        if (CompModSwitches.Data_Constraints.TraceVerbose)
                        {
                            Debug.WriteLine("Parent and Child values on constraint check.");
                            for (int i = 0; i < childKeyValues.Length; i++)
                            {
                                Debug.WriteLine("... " + i.ToString() + ": " + Convert.ToString(parentKeyValues[i]) +
                                                ", " + Convert.ToString(childKeyValues[i]));
                            }
                        }
#endif

                        int parentKeyValuesRecord = childRow.Table.NewRecord();
                        childRow.Table.SetKeyValues(childKey, parentKeyValues, parentKeyValuesRecord);
                        if (childKey.RecordsEqual(childRow.tempRecord, parentKeyValuesRecord))
                        {
                            return;
                        }
                    }
                }

                // now check to see if someone exists... it will have to be in a parent row's current, not a proposed.
                object[] childValues = childRow.GetKeyValues(childKey);
                if (!IsKeyNull(childValues))
                {
                    Index parentIndex = parentKey.GetSortIndex();
                    if (!parentIndex.IsKeyInIndex(childValues))
                    {
                        // could be self-join constraint
                        if (childKey.Table == parentKey.Table && childRow.tempRecord != -1)
                        {
                            int lo = 0;
                            for (lo = 0; lo < childValues.Length; lo++)
                            {
                                if (parentKey.Columns[lo].CompareToValue(childRow.tempRecord, childValues[lo]) != 0)
                                {
                                    break;
                                }
                            }
                            if (lo == childValues.Length)
                            {
                                return;
                            }
                        }

                        throw ExceptionBuilder.ForeignKeyViolation(ConstraintName, childKeyValues);
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// checks if row has status "Added" or if field value is modified compared to original value
        /// </summary>
        /// <param name="ARow"></param>
        /// <param name="AFieldDbName">db name of field to be checked</param>
        /// <returns></returns>
        public static bool IsRowAddedOrFieldModified(DataRow ARow, string AFieldDbName)
        {
            if (ARow.RowState == DataRowState.Added)
            {
                return true;
            }

            if ((ARow.RowState == DataRowState.Modified)
                && ARow.HasVersion(DataRowVersion.Original)
                && ((TTypedDataAccess.GetSafeValue(ARow, AFieldDbName, DataRowVersion.Original)).ToString()
                    != (TTypedDataAccess.GetSafeValue(ARow, AFieldDbName, DataRowVersion.Current)).ToString()))
            {
                return true;
            }

            return false;
        }