2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Data.DB2Client / Mono.Data.Db2Client / DB2ClientParameterCollection.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 #region Licence\r
23         /// DB2DriverCS - A DB2 driver for .Net\r
24         /// Copyright 2003 By Christopher Bockner\r
25         /// Released under the terms of the MIT/X11 Licence\r
26         /// Please refer to the Licence.txt file that should be distributed with this package\r
27         /// This software requires that DB2 client software be installed correctly on the machine\r
28         /// (or instance) on which the driver is running.  \r
29 #endregion\r
30 using System;\r
31 using System.Data;\r
32 using System.Collections;\r
33 using System.Globalization;\r
34 \r
35 \r
36 namespace DB2ClientCS\r
37 {\r
38         /// <summary>\r
39         /// Summary description for DB2ClientParameterCollection.\r
40         /// </summary>\r
41         public class DB2ClientParameterCollection : ArrayList, IDataParameterCollection\r
42         {\r
43                 public object this[string index]\r
44                 {\r
45                         get \r
46                         {\r
47                                 return this[IndexOf(index)];\r
48                         }\r
49                         set\r
50                         {\r
51                                 this[IndexOf(index)] = value;\r
52                         }\r
53                 }\r
54                 public bool Contains(string paramName)\r
55                 {\r
56                         return(-1 != IndexOf(paramName));\r
57                 }\r
58 \r
59                 public int IndexOf(string paramName)\r
60                 {\r
61                         int index = 0;\r
62                         foreach(DB2ClientParameter item in this) \r
63                         {\r
64                                 if (0 == _cultureAwareCompare(item.ParameterName, paramName))\r
65                                 {\r
66                                         return index;\r
67                                 }\r
68                                 index++;\r
69                         }\r
70                         return -1;\r
71                 }\r
72 \r
73                 public void RemoveAt(string paramName)\r
74                 {\r
75                         RemoveAt(IndexOf(paramName));\r
76                 }\r
77 \r
78                 public override int Add(object value)\r
79                 {\r
80                         return Add((DB2ClientParameter)value);\r
81                 }\r
82 \r
83                 public int Add(DB2ClientParameter value)\r
84                 {\r
85                         if (((DB2ClientParameter)value).ParameterName != null)\r
86                         {\r
87                                 return base.Add(value);\r
88                         }\r
89                         else\r
90                                 throw new ArgumentException("parameter must be named");\r
91                 }\r
92 \r
93                 public int Add(string paramName, DbType type)\r
94                 {\r
95                         return Add(new DB2ClientParameter(paramName, type));\r
96                 }\r
97 \r
98                 public int Add(string paramName, object value)\r
99                 {\r
100                         return Add(new DB2ClientParameter(paramName, value));\r
101                 }\r
102 \r
103                 public int Add(string paramName, DbType dbType, string sourceColumn)\r
104                 {\r
105                         return Add(new DB2ClientParameter(paramName, dbType, sourceColumn));\r
106                 }\r
107 \r
108                 private int _cultureAwareCompare(string strA, string strB)\r
109                 {\r
110                         return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase);\r
111                 }\r
112         }\r
113 }\r
114 \r