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