Merge branch 'master' of http://github.com/mono/mono
[mono.git] / mcs / class / IBM.Data.DB2 / IBM.Data.DB2 / DB2ErrorCollection.cs
1 \r
2 //\r
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
10 // \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
13 // \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
21 //\r
22 using System;\r
23 using System.Collections;\r
24 using System.Text;\r
25 \r
26 namespace IBM.Data.DB2\r
27 {\r
28         [Serializable()]\r
29         public class DB2ErrorCollection : CollectionBase \r
30         {\r
31         \r
32                 public DB2ErrorCollection(short sqlHandleType, IntPtr sqlHandle) \r
33                 {\r
34                         StringBuilder sqlState = new StringBuilder(10);\r
35                         StringBuilder errorMessage = new StringBuilder(1025);\r
36 \r
37                         int sqlReturn;\r
38                         short recNum=1;\r
39 \r
40                         do\r
41                         {\r
42                                 int nativeError;\r
43                                 short errorMessageLength;\r
44                                 sqlReturn = DB2CLIWrapper.SQLGetDiagRec(sqlHandleType, sqlHandle, recNum++, sqlState, out nativeError, errorMessage, errorMessage.Capacity - 1, out errorMessageLength);\r
45                                 if(sqlReturn == 0)\r
46                                 {\r
47                                         Add(new DB2Error(errorMessage.ToString(), sqlState.ToString(), nativeError));\r
48                                 }\r
49                         }\r
50                         while (sqlReturn == 0);\r
51                 }\r
52         \r
53                 public DB2Error this[int index] \r
54                 {\r
55                         get \r
56                         {\r
57                                 return ((DB2Error)(List[index]));\r
58                         }\r
59                 }\r
60                 internal int Add(DB2Error value) \r
61                 {\r
62                         return List.Add(value);\r
63                 }\r
64         \r
65                 public void CopyTo(DB2Error[] array, int index) \r
66                 {\r
67                         List.CopyTo(array, index);\r
68                 }\r
69         \r
70                 /// <summary>\r
71                 ///    <para>Returns an enumerator that can iterate through \r
72                 ///       the <see cref='d.DB2ErrorCollection'/> .</para>\r
73                 /// </summary>\r
74                 /// <returns><para>None.</para></returns>\r
75                 /// <seealso cref='System.Collections.IEnumerator'/>\r
76                 public new DB2ErrorEnumerator GetEnumerator() \r
77                 {\r
78                         return new DB2ErrorEnumerator(this);\r
79                 }\r
80         \r
81                 public class DB2ErrorEnumerator : object, IEnumerator \r
82                 {\r
83             \r
84                         private IEnumerator baseEnumerator;\r
85             \r
86                         private IEnumerable temp;\r
87             \r
88                         public DB2ErrorEnumerator(DB2ErrorCollection mappings) \r
89                         {\r
90                                 this.temp = ((IEnumerable)(mappings));\r
91                                 this.baseEnumerator = temp.GetEnumerator();\r
92                         }\r
93             \r
94                         public DB2Error Current \r
95                         {\r
96                                 get \r
97                                 {\r
98                                         return ((DB2Error)(baseEnumerator.Current));\r
99                                 }\r
100                         }\r
101             \r
102                         object IEnumerator.Current \r
103                         {\r
104                                 get \r
105                                 {\r
106                                         return baseEnumerator.Current;\r
107                                 }\r
108                         }\r
109             \r
110                         public bool MoveNext() \r
111                         {\r
112                                 return baseEnumerator.MoveNext();\r
113                         }\r
114             \r
115                         bool IEnumerator.MoveNext() \r
116                         {\r
117                                 return baseEnumerator.MoveNext();\r
118                         }\r
119             \r
120                         public void Reset() \r
121                         {\r
122                                 baseEnumerator.Reset();\r
123                         }\r
124             \r
125                         void IEnumerator.Reset() \r
126                         {\r
127                                 baseEnumerator.Reset();\r
128                         }\r
129                 }\r
130         \r
131         }\r
132 }\r