2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / IBM.Data.DB2 / IBM.Data.DB2 / DB2ParameterCollection.cs
1
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.
21 //
22 using System;\r
23 using System.Data;\r
24 using System.Collections;\r
25 using System.Globalization;\r
26 \r
27 \r
28 namespace IBM.Data.DB2\r
29 {\r
30 \r
31         public class DB2ParameterCollection : ArrayList, IDataParameterCollection\r
32         {\r
33                 IntPtr hwndStmt = IntPtr.Zero;\r
34                 \r
35                 internal IntPtr HwndStmt\r
36                 {\r
37                         set\r
38                         {\r
39                                 hwndStmt = value;\r
40                         }\r
41                 }\r
42                 public new DB2Parameter this[int index]\r
43                 {\r
44                         get \r
45                         {\r
46                                 return (DB2Parameter)base[index];\r
47                         }\r
48                         set\r
49                         {\r
50                                 base[index] = value;\r
51                         }\r
52                 }\r
53                 public DB2Parameter this[string index]\r
54                 {\r
55                         get \r
56                         {\r
57                                 return (DB2Parameter)base[IndexOf(index)];\r
58                         }\r
59                         set\r
60                         {\r
61                                 base[IndexOf(index)] = value;\r
62                         }\r
63                 }\r
64                 object IDataParameterCollection.this[string index]\r
65                 {\r
66                         get \r
67                         {\r
68                                 return this[IndexOf(index)];\r
69                         }\r
70                         set\r
71                         {\r
72                                 this[IndexOf(index)] = (DB2Parameter)value;\r
73                         }\r
74                 }\r
75                 public bool Contains(string paramName)\r
76                 {\r
77                         return(-1 != IndexOf(paramName));\r
78                 }\r
79 \r
80                 public int IndexOf(string paramName)\r
81                 {\r
82                         int index = 0;\r
83                         for(index = 0; index < Count; index++) \r
84                         {\r
85                                 if (0 == _cultureAwareCompare(((DB2Parameter)this[index]).ParameterName, paramName))\r
86                                 {\r
87                                         return index;\r
88                                 }\r
89                         }\r
90                         return -1;\r
91                 }\r
92 \r
93                 public void RemoveAt(string paramName)\r
94                 {\r
95                         RemoveAt(IndexOf(paramName));\r
96                 }\r
97 \r
98                 public override int Add(object obj)\r
99                 {\r
100                         DB2Parameter value = (DB2Parameter)obj;\r
101                         if(value.ParameterName == null)\r
102                                 throw new ArgumentException("parameter must be named");\r
103                         if(IndexOf(value.ParameterName) >= 0)\r
104                                 throw new ArgumentException("parameter name is already in collection");\r
105                         return base.Add(value);\r
106                 }\r
107 \r
108                 public DB2Parameter Add(DB2Parameter value)\r
109                 {\r
110                         if(value.ParameterName == null)\r
111                                 throw new ArgumentException("parameter must be named");\r
112                         if(IndexOf(value.ParameterName) >= 0)\r
113                                 throw new ArgumentException("parameter name is already in collection");\r
114                         base.Add(value);\r
115                         return value;\r
116                 }\r
117 \r
118                 public DB2Parameter Add(string paramName, DB2Type type)\r
119                 {\r
120                         return Add(new DB2Parameter(paramName, type));\r
121                 }\r
122 \r
123                 public DB2Parameter Add(string paramName, object value)\r
124                 {\r
125                         return Add(new DB2Parameter(paramName, value));\r
126                 }\r
127 \r
128                 public DB2Parameter Add(string paramName, DB2Type dbType, int size)\r
129                 {\r
130                         return Add(new DB2Parameter(paramName, dbType, size));\r
131                 }\r
132 \r
133                 public DB2Parameter Add(string paramName, DB2Type dbType, int size, string sourceColumn)\r
134                 {\r
135                         return Add(new DB2Parameter(paramName, dbType, size, sourceColumn));\r
136                 }\r
137 \r
138                 private int _cultureAwareCompare(string strA, string strB)\r
139                 {\r
140                         return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase);\r
141                 }\r
142                 \r
143                 internal void GetOutValues()\r
144                 {\r
145                         foreach(DB2Parameter param in this)\r
146                         {\r
147                                 if(ParameterDirection.Output == param.Direction || ParameterDirection.InputOutput == param.Direction)\r
148                                 {\r
149                                         param.GetOutValue();\r
150                                         //Console.WriteLine(param.ParameterName);\r
151                                 }\r
152                         }\r
153                 }\r
154         }\r
155 }\r
156 \r