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:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
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.
24 using System
.Collections
;
25 using System
.Globalization
;
28 namespace IBM
.Data
.DB2
31 public class DB2ParameterCollection
: ArrayList
, IDataParameterCollection
33 IntPtr hwndStmt
= IntPtr
.Zero
;
35 internal IntPtr HwndStmt
42 public new DB2Parameter
this[int index
]
46 return (DB2Parameter
)base[index
];
53 public DB2Parameter
this[string index
]
57 return (DB2Parameter
)base[IndexOf(index
)];
61 base[IndexOf(index
)] = value;
64 object IDataParameterCollection
.this[string index
]
68 return this[IndexOf(index
)];
72 this[IndexOf(index
)] = (DB2Parameter
)value;
75 public bool Contains(string paramName
)
77 return(-1 != IndexOf(paramName
));
80 public int IndexOf(string paramName
)
83 for(index
= 0; index
< Count
; index
++)
85 if (0 == _cultureAwareCompare(((DB2Parameter
)this[index
]).ParameterName
, paramName
))
93 public void RemoveAt(string paramName
)
95 RemoveAt(IndexOf(paramName
));
98 public override int Add(object obj
)
100 DB2Parameter
value = (DB2Parameter
)obj
;
101 if(value.ParameterName
== null)
102 throw new ArgumentException("parameter must be named");
103 if(IndexOf(value.ParameterName
) >= 0)
104 throw new ArgumentException("parameter name is already in collection");
105 return base.Add(value);
108 public DB2Parameter
Add(DB2Parameter
value)
110 if(value.ParameterName
== null)
111 throw new ArgumentException("parameter must be named");
112 if(IndexOf(value.ParameterName
) >= 0)
113 throw new ArgumentException("parameter name is already in collection");
118 public DB2Parameter
Add(string paramName
, DB2Type type
)
120 return Add(new DB2Parameter(paramName
, type
));
123 public DB2Parameter
Add(string paramName
, object value)
125 return Add(new DB2Parameter(paramName
, value));
128 public DB2Parameter
Add(string paramName
, DB2Type dbType
, int size
)
130 return Add(new DB2Parameter(paramName
, dbType
, size
));
133 public DB2Parameter
Add(string paramName
, DB2Type dbType
, int size
, string sourceColumn
)
135 return Add(new DB2Parameter(paramName
, dbType
, size
, sourceColumn
));
138 private int _cultureAwareCompare(string strA
, string strB
)
140 return CultureInfo
.CurrentCulture
.CompareInfo
.Compare(strA
, strB
, CompareOptions
.IgnoreKanaType
| CompareOptions
.IgnoreWidth
| CompareOptions
.IgnoreCase
);
143 internal void GetOutValues()
145 foreach(DB2Parameter param
in this)
147 if(ParameterDirection
.Output
== param
.Direction
|| ParameterDirection
.InputOutput
== param
.Direction
)
150 //Console.WriteLine(param.ParameterName);