2 // Mono.Data.Tds.TdsMetaParameter.cs
5 // Tim Coleman (tim@timcoleman.com)
7 // Copyright (C) Tim Coleman, 2002
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Mono
.Data
.Tds
.Protocol
;
35 namespace Mono
.Data
.Tds
{
36 public class TdsMetaParameter
40 TdsParameterDirection direction
= TdsParameterDirection
.Input
;
46 bool isSizeSet
= false;
52 public TdsMetaParameter (string name
, object value)
53 : this (name
, String
.Empty
, value)
57 public TdsMetaParameter (string name
, string typeName
, object value)
65 public TdsMetaParameter (string name
, int size
, bool isNullable
, byte precision
, byte scale
, object value)
69 IsNullable
= isNullable
;
70 Precision
= precision
;
77 public TdsParameterDirection Direction
{
78 get { return direction; }
79 set { direction = value; }
82 public string TypeName
{
83 get { return typeName; }
84 set { typeName = value; }
87 public string ParameterName
{
92 public bool IsNullable
{
93 get { return isNullable; }
94 set { isNullable = value; }
99 set { this.value = value; }
102 public byte Precision
{
103 get { return precision; }
104 set { precision = value; }
108 get { return scale; }
109 set { scale = value; }
113 get { return GetSize (); }
120 #endregion // Properties
124 internal string Prepare ()
126 StringBuilder result
= new StringBuilder (String
.Format ("{0} {1}", ParameterName
, TypeName
));
130 result
.Append (String
.Format ("({0},{1})", Precision
, Scale
));
134 result
.Append (String
.Format ("({0})", Size
> 0 ? Size
: GetActualSize ()));
137 result
.Append (String
.Format ("({0})", Size
> 0 ? Size
: 4000));
142 if (isSizeSet
&& Size
> 0)
143 result
.Append (String
.Format ("({0})", Size
));
146 return result
.ToString ();
149 internal int GetActualSize ()
151 if (Value
== DBNull
.Value
|| Value
== null)
154 switch (Value
.GetType ().ToString ()) {
155 case "System.String":
156 return ((string) value).Length
;
157 case "System.Byte[]":
158 return ((byte[]) value).Length
;
163 private int GetSize ()
177 case "smalldatetime":
188 internal TdsColumnType
GetMetaType ()
192 return TdsColumnType
.Binary
;
194 return TdsColumnType
.Bit
;
196 return TdsColumnType
.Char
;
198 return TdsColumnType
.Decimal
;
201 return TdsColumnType
.DateTimeN
;
202 return TdsColumnType
.DateTime
;
204 return TdsColumnType
.Float8
;
206 return TdsColumnType
.Image
;
209 return TdsColumnType
.IntN
;
210 return TdsColumnType
.Int4
;
212 return TdsColumnType
.Numeric
;
214 return TdsColumnType
.NChar
;
216 return TdsColumnType
.NText
;
218 return TdsColumnType
.NVarChar
;
220 return TdsColumnType
.Real
;
223 return TdsColumnType
.IntN
;
224 return TdsColumnType
.Int2
;
226 return TdsColumnType
.Text
;
229 return TdsColumnType
.IntN
;
230 return TdsColumnType
.Int1
;
231 case "uniqueidentifier":
232 return TdsColumnType
.UniqueIdentifier
;
234 return TdsColumnType
.VarBinary
;
236 return TdsColumnType
.VarChar
;
238 throw new NotSupportedException ();
242 #endregion // Methods