**** Merged from MCS ****
[mono-project.git] / mcs / class / IBM.Data.DB2 / IBM.Data.DB2 / DB2ErrorCollection.cs
blobb37501c7fcc126bbc87cd7b264035be2a6c8f129
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 using System;
23 using System.Collections;
24 using System.Text;
26 namespace IBM.Data.DB2
28 [Serializable()]
29 public class DB2ErrorCollection : CollectionBase
32 public DB2ErrorCollection(short sqlHandleType, IntPtr sqlHandle)
34 StringBuilder sqlState = new StringBuilder(10);
35 StringBuilder errorMessage = new StringBuilder(1025);
37 int sqlReturn;
38 short recNum=1;
42 int nativeError;
43 short errorMessageLength;
44 sqlReturn = DB2CLIWrapper.SQLGetDiagRec(sqlHandleType, sqlHandle, recNum++, sqlState, out nativeError, errorMessage, errorMessage.Capacity - 1, out errorMessageLength);
45 if(sqlReturn == 0)
47 Add(new DB2Error(errorMessage.ToString(), sqlState.ToString(), nativeError));
50 while (sqlReturn == 0);
53 public DB2Error this[int index]
55 get
57 return ((DB2Error)(List[index]));
60 internal int Add(DB2Error value)
62 return List.Add(value);
65 public void CopyTo(DB2Error[] array, int index)
67 List.CopyTo(array, index);
70 /// <summary>
71 /// <para>Returns an enumerator that can iterate through
72 /// the <see cref='d.DB2ErrorCollection'/> .</para>
73 /// </summary>
74 /// <returns><para>None.</para></returns>
75 /// <seealso cref='System.Collections.IEnumerator'/>
76 public new DB2ErrorEnumerator GetEnumerator()
78 return new DB2ErrorEnumerator(this);
81 public class DB2ErrorEnumerator : object, IEnumerator
84 private IEnumerator baseEnumerator;
86 private IEnumerable temp;
88 public DB2ErrorEnumerator(DB2ErrorCollection mappings)
90 this.temp = ((IEnumerable)(mappings));
91 this.baseEnumerator = temp.GetEnumerator();
94 public DB2Error Current
96 get
98 return ((DB2Error)(baseEnumerator.Current));
102 object IEnumerator.Current
104 get
106 return baseEnumerator.Current;
110 public bool MoveNext()
112 return baseEnumerator.MoveNext();
115 bool IEnumerator.MoveNext()
117 return baseEnumerator.MoveNext();
120 public void Reset()
122 baseEnumerator.Reset();
125 void IEnumerator.Reset()
127 baseEnumerator.Reset();