Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Triger <kostat@mono-cvs.ximian.com>2005-12-15 17:17:30 +0300
committerKonstantin Triger <kostat@mono-cvs.ximian.com>2005-12-15 17:17:30 +0300
commit2dd47010c89a5c39f27aa6756b598cf6bb616937 (patch)
treead431e0560b68150b546ad49df1b40181bddaf61 /mcs/class/System.Data/System.Data.Common
parent749ec9f7bd04c02d0d0c1e8020f9a9030274eaee (diff)
fix index updates
svn path=/trunk/mcs/; revision=54453
Diffstat (limited to 'mcs/class/System.Data/System.Data.Common')
-rw-r--r--mcs/class/System.Data/System.Data.Common/ChangeLog8
-rw-r--r--mcs/class/System.Data/System.Data.Common/Index.cs41
-rw-r--r--mcs/class/System.Data/System.Data.Common/Key.cs86
3 files changed, 105 insertions, 30 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/ChangeLog b/mcs/class/System.Data/System.Data.Common/ChangeLog
index 3d97317380f..a33733f1c38 100644
--- a/mcs/class/System.Data/System.Data.Common/ChangeLog
+++ b/mcs/class/System.Data/System.Data.Common/ChangeLog
@@ -1,3 +1,11 @@
+2005-12-12 Konstantin Triger <kostat@mainsoft.com>
+
+ * Key.cs: Added ContainsVersion function, refactoring.
+ * Index.cs: Fixed Reset() to be ready for Update() calls.
+ Otherwise the index can be rebuilt with new values inside the
+ Update() call itself.
+ Fixed FindIndexExact(), Update(), Delete().
+
2005-11-22 Konstantin Triger <kostat@mainsoft.com>
* DbProviderFactory.cs: TARGET_JVM ifdef.
diff --git a/mcs/class/System.Data/System.Data.Common/Index.cs b/mcs/class/System.Data/System.Data.Common/Index.cs
index cfe1170c96e..21c87478f9b 100644
--- a/mcs/class/System.Data/System.Data.Common/Index.cs
+++ b/mcs/class/System.Data/System.Data.Common/Index.cs
@@ -162,6 +162,7 @@ namespace System.Data.Common
internal void Reset()
{
_array = null;
+ RebuildIndex();
}
private void RebuildIndex()
@@ -333,8 +334,11 @@ namespace System.Data.Common
*/
private int FindIndexExact(int record)
{
- int index = System.Array.BinarySearch(Array,record);
- return (index > 0) ? index : -1;
+ for (int i = 0, size = Size; i < size; i++)
+ if (Array[i] == record)
+ return i;
+
+ return -1;
}
/*
@@ -359,7 +363,7 @@ namespace System.Data.Common
if (oldRecord == -1)
return;
- int index = FindIndex(oldRecord);
+ int index = FindIndexExact(oldRecord);
if (index != -1) {
if ((_hasDuplicates == IndexDuplicatesState.True)) {
int c1 = 1;
@@ -388,18 +392,29 @@ namespace System.Data.Common
_size--;
}
- internal void Update(DataRow row,int newRecord)
- {
- int oldRecord = Key.GetRecord(row);
- if (oldRecord == -1 || Size == 0) {
- Add(row,newRecord);
+ internal void Update(DataRow row,int oldRecord, DataRowVersion oldVersion, DataRowState oldState)
+ {
+ bool contains = Key.ContainsVersion (oldState, oldVersion);
+ int newRecord = Key.GetRecord(row);
+ // the record did not appeared in the index before update
+ if (oldRecord == -1 || Size == 0 || !contains) {
+ if (newRecord >= 0) {
+ if (FindIndexExact(newRecord) < 0)
+ Add(row,newRecord);
+ }
+ return;
+ }
+
+ // the record will not appeare in the index after update
+ if (newRecord < 0 || !Key.CanContain (newRecord)) {
+ Delete (oldRecord);
return;
}
- int oldIdx = FindIndex(oldRecord);
+ int oldIdx = FindIndexExact(oldRecord);
- if( oldIdx == -1 || Key.Table.RecordCache[Array[oldIdx]] != row ) {
+ if( oldIdx == -1 ) {
Add(row,newRecord);
return;
}
@@ -477,11 +492,15 @@ namespace System.Data.Common
}
}
+ internal void Add(DataRow row) {
+ Add(row, Key.GetRecord(row));
+ }
+
private void Add(DataRow row,int newRecord)
{
int newIdx;
- if (!Key.CanContain (newRecord))
+ if (newRecord < 0 || !Key.CanContain (newRecord))
return;
if (Size == 0) {
diff --git a/mcs/class/System.Data/System.Data.Common/Key.cs b/mcs/class/System.Data/System.Data.Common/Key.cs
index 989e8631678..4c1d26a2d2b 100644
--- a/mcs/class/System.Data/System.Data.Common/Key.cs
+++ b/mcs/class/System.Data/System.Data.Common/Key.cs
@@ -163,29 +163,77 @@ namespace System.Data.Common
return _filter.EvalBoolean(_tmpRow);
}
- internal static int GetRecord(DataRow row, DataViewRowState rowStateFilter)
+ internal bool ContainsVersion (DataRowState state, DataRowVersion version)
{
+ switch (state) {
+ case DataRowState.Unchanged: {
+ if ((_rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) {
+ return ((version & DataRowVersion.Default) != 0);
+ }
- if (row.Original == row.Current) {
- if ((rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) {
- return row.Current;
- }
- }
- else if (row.Original == -1) {
- if ((rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) {
- return row.Current;
- }
+ break;
+ }
+ case DataRowState.Added: {
+ if ((_rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) {
+ return ((version & DataRowVersion.Default) != 0);
+ }
+
+ break;
+ }
+ case DataRowState.Deleted: {
+ if ((_rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) {
+ return (version == DataRowVersion.Original);
+ }
+
+ break;
+ }
+ default:
+ if ((_rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) {
+ return ((version & DataRowVersion.Default) != 0);
+ }
+ else if ((_rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) {
+ return (version == DataRowVersion.Original);
+ }
+
+ break;
}
- else if (row.Current == -1) {
- if ((rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) {
+
+ return false;
+ }
+
+ internal static int GetRecord(DataRow row, DataViewRowState rowStateFilter)
+ {
+ switch (row.RowState) {
+ case DataRowState.Unchanged: {
+ if ((rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) {
+ return row.Proposed >= 0 ? row.Proposed : row.Current;
+ }
+
+ break;
+ }
+ case DataRowState.Added: {
+ if ((rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) {
+ return row.Proposed >= 0 ? row.Proposed : row.Current;
+ }
+
+ break;
+ }
+ case DataRowState.Deleted: {
+ if ((rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) {
return row.Original;
- }
- }
- else if ((rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) {
- return row.Current;
- }
- else if ((rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) {
- return row.Original;
+ }
+
+ break;
+ }
+ default:
+ if ((rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) {
+ return row.Proposed >= 0 ? row.Proposed : row.Current;
+ }
+ else if ((rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) {
+ return row.Original;
+ }
+
+ break;
}
return -1;