imported everything from my branch (which is slightly harmless).
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlParameter.cs
1 //
2 // System.Data.SqlClient.SqlParameter.cs
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Daniel Morgan (danmorg@sc.rr.com)
7 //   Tim Coleman (tim@timcoleman.com)
8 //   Diego Caravana (diego@toth.it)
9 //   Umadevi S (sumadevi@novell.com)
10 //
11 // (C) Ximian, Inc. 2002
12 // Copyright (C) Tim Coleman, 2002
13 //
14
15 //
16 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining
19 // a copy of this software and associated documentation files (the
20 // "Software"), to deal in the Software without restriction, including
21 // without limitation the rights to use, copy, modify, merge, publish,
22 // distribute, sublicense, and/or sell copies of the Software, and to
23 // permit persons to whom the Software is furnished to do so, subject to
24 // the following conditions:
25 // 
26 // The above copyright notice and this permission notice shall be
27 // included in all copies or substantial portions of the Software.
28 // 
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 //
37
38 using Mono.Data.Tds;
39 using Mono.Data.Tds.Protocol;
40 using System;
41 using System.ComponentModel;
42 using System.Data;
43 using System.Data.Common;
44 #if NET_2_0
45 using System.Data.ProviderBase;
46 #endif // NET_2_0
47 using System.Data.SqlTypes;
48 using System.Runtime.InteropServices;
49 using System.Text;
50
51 namespace System.Data.SqlClient {
52         [TypeConverterAttribute (typeof (SqlParameterConverter))]
53 #if NET_2_0
54         public sealed class SqlParameter : DbParameterBase, IDbDataParameter, IDataParameter, ICloneable
55 #else
56         public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
57 #endif // NET_2_0
58         {
59                 #region Fields
60
61                 TdsMetaParameter metaParameter;
62
63                 SqlParameterCollection container = null;
64                 DbType dbType;
65                 ParameterDirection direction = ParameterDirection.Input;
66                 bool isNullable;
67                 bool isSizeSet = false;
68                 bool isTypeSet = false;
69                 int offset;
70                 SqlDbType sqlDbType;
71                 string sourceColumn;
72                 DataRowVersion sourceVersion;
73
74                 #endregion // Fields
75
76                 #region Constructors
77
78                 public SqlParameter () 
79                         : this (String.Empty, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
80                 {
81                 }
82
83                 public SqlParameter (string parameterName, object value) 
84                 {
85                         metaParameter = new TdsMetaParameter (parameterName, SqlTypeToFrameworkType (value));
86                         this.sourceVersion = DataRowVersion.Current;
87                         InferSqlType (value);
88                 }
89                 
90                 public SqlParameter (string parameterName, SqlDbType dbType) 
91                         : this (parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
92                 {
93                 }
94
95                 public SqlParameter (string parameterName, SqlDbType dbType, int size) 
96                         : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
97                 {
98                 }
99                 
100                 public SqlParameter (string parameterName, SqlDbType dbType, int size, string sourceColumn) 
101                         : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null)
102                 {
103                 }
104                 
105                 [EditorBrowsable (EditorBrowsableState.Advanced)]        
106                 public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value) 
107                 {
108                         metaParameter = new TdsMetaParameter (parameterName, size, 
109                                                               isNullable, precision, 
110                                                               scale, 
111                                                               SqlTypeToFrameworkType (value));
112                         SqlDbType = dbType;
113                         Direction = direction;
114                         SourceColumn = sourceColumn;
115                         SourceVersion = sourceVersion;
116                 }
117
118                 // This constructor is used internally to construct a
119                 // SqlParameter.  The value array comes from sp_procedure_params_rowset.
120                 // This is in SqlCommand.DeriveParameters.
121                 internal SqlParameter (object[] dbValues) 
122                         : this (dbValues [3].ToString (), String.Empty)
123                 {
124                         Precision = 0;
125                         Scale = 0;
126                         Direction = ParameterDirection.Input;
127
128                         ParameterName = (string) dbValues[3];
129
130                         switch ((short) dbValues[5]) {
131                         case 1:
132                                 Direction = ParameterDirection.Input;
133                                 break;
134                         case 2:
135                                 Direction = ParameterDirection.Output;
136                                 break;
137                         case 3:
138                                 Direction = ParameterDirection.InputOutput;
139                                 break;
140                         case 4:
141                                 Direction = ParameterDirection.ReturnValue;
142                                 break;
143                         default:
144                                 Direction = ParameterDirection.Input;
145                                 break;
146                         }
147                         IsNullable = (dbValues [8] != null && 
148                                       dbValues [8] != DBNull.Value) ? (bool) dbValues [8] : false;
149
150                         if (dbValues [12] != null && dbValues [12] != DBNull.Value)
151                                 Precision = (byte) ((short) dbValues [12]);
152
153                         if (dbValues [13] != null && dbValues [13] != DBNull.Value)
154                                 Scale = (byte) ( (short) dbValues [13]);
155
156                         SetDbTypeName ((string) dbValues [16]);
157                 }
158
159                 #endregion // Constructors
160
161                 #region Properties
162
163                 // Used to ensure that only one collection can contain this
164                 // parameter
165                 internal SqlParameterCollection Container {
166                         get { return container; }
167                         set { container = value; }
168                 }
169
170 #if ONLY_1_0 || ONLY_1_1        
171                 [Browsable (false)]
172                 [DataSysDescription ("The parameter generic type.")]
173                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
174                 [RefreshProperties (RefreshProperties.All)]
175 #endif                                                   
176                 [DataCategory ("Data")]
177                 public 
178 #if NET_2_0
179                 override
180 #endif // NET_2_0
181          DbType DbType {
182                         get { return dbType; }
183                         set { 
184                                 SetDbType (value); 
185                                 isTypeSet = true;
186                         }
187                 }
188
189                 [DataCategory ("Data")]
190 #if ONLY_1_0 || ONLY_1_1
191                 [DataSysDescription ("Input, output, or bidirectional parameter.")]
192                 [DefaultValue (ParameterDirection.Input)]
193 #endif
194 #if NET_2_0
195                 [RefreshProperties (RefreshProperties.All)]
196 #endif
197                 public 
198 #if NET_2_0
199                 override
200 #endif // NET_2_0
201          ParameterDirection Direction {
202                         get { return direction; }
203                         set { 
204                                 direction = value; 
205                                 switch( direction ) {
206                                         case ParameterDirection.Output:
207                                         MetaParameter.Direction = TdsParameterDirection.Output;
208                                                 break;
209                                         case ParameterDirection.InputOutput:
210                                                 MetaParameter.Direction = TdsParameterDirection.InputOutput;
211                                                 break;
212                                         case ParameterDirection.ReturnValue:
213                                                 MetaParameter.Direction = TdsParameterDirection.ReturnValue;
214                                                 break;
215                                 }
216                         }
217                 }
218
219                 internal TdsMetaParameter MetaParameter {
220                         get { return metaParameter; }
221                 }
222
223                 string IDataParameter.ParameterName {
224                         get { return metaParameter.ParameterName; }
225                         set { metaParameter.ParameterName = value; }
226                 }
227
228 #if ONLY_1_0 || ONLY_1_1
229                 [Browsable (false)]
230                 [DataSysDescription ("a design-time property used for strongly typed code-generation.")]
231                 [DefaultValue (false)]
232                 [DesignOnly (true)]
233                 [EditorBrowsable (EditorBrowsableState.Advanced)]        
234 #endif
235                 public 
236 #if NET_2_0
237                 override
238 #endif // NET_2_0
239          bool IsNullable        {
240                         get { return metaParameter.IsNullable; }
241                         set { metaParameter.IsNullable = value; }
242                 }
243
244                 [Browsable (false)]
245                 [DataCategory ("Data")]
246 #if ONLY_1_0 || ONLY_1_1
247                 [DataSysDescription ("Offset in variable length data types.")]
248                 [DefaultValue (0)]
249 #endif
250 #if NET_2_0
251                 [EditorBrowsable (EditorBrowsableState.Advanced)]
252 #endif
253                 public 
254 #if NET_2_0
255                 override
256 #endif // NET_2_0
257          int Offset {
258                         get { return offset; }
259                         set { offset = value; }
260                 }
261         
262 #if ONLY_1_0 || ONLY_1_1        
263                 [DataSysDescription ("Name of the parameter, like '@p1'")]
264                 [DefaultValue ("")]
265 #endif
266                 public 
267 #if NET_2_0
268                 override
269 #endif // NET_2_0
270          string ParameterName {
271                         get { return metaParameter.ParameterName; }
272                         set { metaParameter.ParameterName = value; }
273                 }
274
275                 [DataCategory ("Data")]
276 #if ONLY_1_0 || ONLY_1_1
277                 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
278                 [DefaultValue (0)]
279 #endif
280 #if NET_2_0
281                 [Browsable (false)]
282                 [EditorBrowsable (EditorBrowsableState.Never)]
283 #endif          
284                 public 
285 #if NET_2_0
286                 override
287 #endif // NET_2_0
288          byte Precision {
289                         get { return metaParameter.Precision; }
290                         set { metaParameter.Precision = value; }
291                 }
292
293                 [DataCategory ("Data")]
294 #if ONLY_1_0 || ONLY_1_1
295                 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
296                 [DefaultValue (0)]
297 #endif
298 #if NET_2_0
299                 [Browsable (false)]
300                 [EditorBrowsable (EditorBrowsableState.Never)]
301 #endif
302                 public 
303 #if NET_2_0
304                 override
305 #endif // NET_2_0
306          byte Scale {
307                         get { return metaParameter.Scale; }
308                         set { metaParameter.Scale = value; }
309                 }
310
311                 [DataCategory ("Data")]
312 #if ONLY_1_0 || ONLY_1_1
313                 [DataSysDescription ("Size of variable length data types (strings & arrays).")]
314                 [DefaultValue (0)]
315 #endif
316                 public 
317 #if NET_2_0
318                 override
319 #endif // NET_2_0
320          int Size {
321                         get { return metaParameter.Size; }
322                         set { metaParameter.Size = value; }
323                 }
324
325                 [DataCategory ("Data")]
326 #if ONLY_1_0 || ONLY_1_1
327                 [DataSysDescription ("When used by a DataAdapter.Update, the source column name that is used to find the DataSetColumn name in the ColumnMappings. This is to copy a value between the parameter and a datarow.")]
328                 [DefaultValue ("")]
329 #endif
330                 public 
331 #if NET_2_0
332                 override
333 #endif // NET_2_0
334          string SourceColumn {
335                         get { return sourceColumn; }
336                         set { sourceColumn = value; }
337                 }
338
339                 [DataCategory ("Data")]
340 #if ONLY_1_0 || ONLY_1_1
341                 [DataSysDescription ("When used by a DataAdapter.Update (UpdateCommand only), the version of the DataRow value that is used to update the data source.")]
342                 [DefaultValue (DataRowVersion.Current)]
343 #endif
344                 public 
345 #if NET_2_0
346                 override
347 #endif // NET_2_0
348          DataRowVersion SourceVersion {
349                         get { return sourceVersion; }
350                         set { sourceVersion = value; }
351                 }
352                 
353                 [DataCategory ("Data")]
354 #if ONLY_1_0 || ONLY_1_1
355                 [DataSysDescription ("The parameter native type.")]
356                 [DefaultValue (SqlDbType.NVarChar)]
357 #endif
358                 [RefreshProperties (RefreshProperties.All)]
359 #if NET_2_0
360                 [DbProviderSpecificTypeProperty(true)]
361 #endif
362                 public SqlDbType SqlDbType {
363                         get { return sqlDbType; }
364                         set { 
365                                 SetSqlDbType (value); 
366                                 isTypeSet = true;
367                         }
368                 }
369
370                 [DataCategory ("Data")]
371 #if ONLY_1_0 || ONLY_1_1
372                 [DataSysDescription ("Value of the parameter.")]
373                 [DefaultValue (null)]
374 #endif
375                 [TypeConverterAttribute (typeof (StringConverter))]
376 #if NET_2_0
377                 [RefreshProperties (RefreshProperties.All)]             
378 #endif
379                 public 
380 #if NET_2_0
381                 override
382 #endif // NET_2_0
383          object Value {
384                         get { return metaParameter.Value; }
385                         set { 
386                                 if (!isTypeSet)
387                                         InferSqlType (value);
388                                 metaParameter.Value = SqlTypeToFrameworkType (value);
389                         }
390                 }
391
392 //#if NET_2_0
393 //              public SqlCompareOptions CompareInfo{
394
395 //#endif
396
397                 #endregion // Properties
398
399                 #region Methods
400
401                 object ICloneable.Clone ()
402                 {
403                         return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value);
404                 }
405
406                 // If the value is set without the DbType/SqlDbType being set, then we
407                 // infer type information.
408                 private void InferSqlType (object value)
409                 {
410                         Type type = value.GetType ();
411
412                         string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
413
414                         switch (type.FullName) {
415                         case "System.Int64":
416                         case "System.Data.SqlTypes.SqlInt64":
417                                 SetSqlDbType (SqlDbType.BigInt);
418                                 break;
419                         case "System.Boolean":
420                         case "System.Data.SqlTypes.SqlBoolean":
421                                 SetSqlDbType (SqlDbType.Bit);
422                                 break;
423                         case "System.String":
424                         case "System.Data.SqlTypes.SqlString":
425                                 SetSqlDbType (SqlDbType.NVarChar);
426                                 break;
427                         case "System.DateTime":
428                         case "System.Data.SqlTypes.SqlDateTime":
429                                 SetSqlDbType (SqlDbType.DateTime);
430                                 break;
431                         case "System.Decimal":
432                         case "System.Data.SqlTypes.SqlDecimal":
433                                 SetSqlDbType (SqlDbType.Decimal);
434                                 break;
435                         case "System.Double":
436                         case "System.Data.SqlTypes.SqlDouble":
437                                 SetSqlDbType (SqlDbType.Float);
438                                 break;
439                         case "System.Byte[]":
440                         case "System.Data.SqlTypes.SqlBinary":
441                                 SetSqlDbType (SqlDbType.VarBinary);
442                                 break;
443                         case "System.Byte":
444                         case "System.Data.SqlTypes.SqlByte":
445                                 SetSqlDbType (SqlDbType.TinyInt);
446                                 break;
447                         case "System.Int32":
448                         case "System.Data.SqlTypes.SqlInt32":
449                                 SetSqlDbType (SqlDbType.Int);
450                                 break;
451                         case "System.Single":
452                         case "System.Data.SqlTypes.Single":
453                                 SetSqlDbType (SqlDbType.Real);
454                                 break;
455                         case "System.Int16":
456                         case "System.Data.SqlTypes.SqlInt16":
457                                 SetSqlDbType (SqlDbType.SmallInt);
458                                 break;
459                         case "System.Guid":
460                         case "System.Data.SqlTypes.SqlGuid":
461                                 SetSqlDbType (SqlDbType.UniqueIdentifier);
462                                 break;
463                         case "System.Money":
464                         case "System.SmallMoney":
465                         case "System.Data.SqlTypes.SqlMoney":
466                                 SetSqlDbType (SqlDbType.Money);
467                                 break;
468                         case "System.Object":
469                         case "System.DBNull":
470                                 SetSqlDbType (SqlDbType.Variant); // variant can contain numeric,
471                                                                 //string,binary or data and also nul                                                                //values, so we can later resolve                                                                   // it to correct type.  
472                                 break;  
473                         default:
474                                 throw new ArgumentException (exception);                                
475                         }
476                 }
477
478                 // When the DbType is set, we also set the SqlDbType, as well as the SQL Server
479                 // string representation of the type name.  If the DbType is not convertible
480                 // to an SqlDbType, throw an exception.
481                 private void SetDbType (DbType type)
482                 {
483                         string exception = String.Format ("No mapping exists from DbType {0} to a known SqlDbType.", type);
484
485                         switch (type) {
486                         case DbType.AnsiString:
487                                 MetaParameter.TypeName = "varchar";
488                                 sqlDbType = SqlDbType.VarChar;
489                                 break;
490                         case DbType.AnsiStringFixedLength:
491                                 MetaParameter.TypeName = "char";
492                                 sqlDbType = SqlDbType.Char;
493                                 break;
494                         case DbType.Binary:
495                                 MetaParameter.TypeName = "varbinary";
496                                 sqlDbType = SqlDbType.VarBinary;
497                                 break;
498                         case DbType.Boolean:
499                                 MetaParameter.TypeName = "bit";
500                                 sqlDbType = SqlDbType.Bit;
501                                 break;
502                         case DbType.Byte:
503                                 MetaParameter.TypeName = "tinyint";
504                                 sqlDbType = SqlDbType.TinyInt;
505                                 break;
506                         case DbType.Currency:
507                                 sqlDbType = SqlDbType.Money;
508                                 MetaParameter.TypeName = "money";
509                                 break;
510                         case DbType.Date:
511                         case DbType.DateTime:
512                                 MetaParameter.TypeName = "datetime";
513                                 sqlDbType = SqlDbType.DateTime;
514                                 break;
515                         case DbType.Decimal:
516                                 MetaParameter.TypeName = "decimal";
517                                 sqlDbType = SqlDbType.Decimal;
518                                 break;
519                         case DbType.Double:
520                                 MetaParameter.TypeName = "float";
521                                 sqlDbType = SqlDbType.Float;
522                                 break;
523                         case DbType.Guid:
524                                 MetaParameter.TypeName = "uniqueidentifier";
525                                 sqlDbType = SqlDbType.UniqueIdentifier;
526                                 break;
527                         case DbType.Int16:
528                                 MetaParameter.TypeName = "smallint";
529                                 sqlDbType = SqlDbType.SmallInt;
530                                 break;
531                         case DbType.Int32:
532                                 MetaParameter.TypeName = "int";
533                                 sqlDbType = SqlDbType.Int;
534                                 break;
535                         case DbType.Int64:
536                                 MetaParameter.TypeName = "bigint";
537                                 sqlDbType = SqlDbType.BigInt;
538                                 break;
539                         case DbType.Object:
540                                 MetaParameter.TypeName = "sql_variant";
541                                 sqlDbType = SqlDbType.Variant;
542                                 break;
543                         case DbType.Single:
544                                 MetaParameter.TypeName = "real";
545                                 sqlDbType = SqlDbType.Real;
546                                 break;
547                         case DbType.String:
548                                 MetaParameter.TypeName = "nvarchar";
549                                 sqlDbType = SqlDbType.NVarChar;
550                                 break;
551                         case DbType.StringFixedLength:
552                                 MetaParameter.TypeName = "nchar";
553                                 sqlDbType = SqlDbType.NChar;
554                                 break;
555                         case DbType.Time:
556                                 MetaParameter.TypeName = "datetime";
557                                 sqlDbType = SqlDbType.DateTime;
558                                 break;
559                         default:
560                                 throw new ArgumentException (exception);
561                         }
562                         dbType = type;
563                 }
564
565                 // Used by internal constructor which has a SQL Server typename
566                 private void SetDbTypeName (string dbTypeName)
567                 {
568                         switch (dbTypeName.ToLower ()) {        
569                         case "bigint":
570                                 SqlDbType = SqlDbType.BigInt;
571                                 break;
572                         case "binary":
573                                 SqlDbType = SqlDbType.Binary;
574                                 break;
575                         case "bit":
576                                 SqlDbType = SqlDbType.Bit;
577                                 break;
578                         case "char":
579                                 SqlDbType = SqlDbType.Char;
580                                 break;
581                         case "datetime":
582                                 SqlDbType = SqlDbType.DateTime;
583                                 break;
584                         case "decimal":
585                                 SqlDbType = SqlDbType.Decimal;
586                                 break;
587                         case "float":
588                                 SqlDbType = SqlDbType.Float;
589                                 break;
590                         case "image":
591                                 SqlDbType = SqlDbType.Image;
592                                 break;
593                         case "int":
594                                 SqlDbType = SqlDbType.Int;
595                                 break;
596                         case "money":
597                                 SqlDbType = SqlDbType.Money;
598                                 break;
599                         case "nchar":
600                                 SqlDbType = SqlDbType.NChar;
601                                 break;
602                         case "ntext":
603                                 SqlDbType = SqlDbType.NText;
604                                 break;
605                         case "nvarchar":
606                                 SqlDbType = SqlDbType.NVarChar;
607                                 break;
608                         case "real":
609                                 SqlDbType = SqlDbType.Real;
610                                 break;
611                         case "smalldatetime":
612                                 SqlDbType = SqlDbType.SmallDateTime;
613                                 break;
614                         case "smallint":
615                                 SqlDbType = SqlDbType.SmallInt;
616                                 break;
617                         case "smallmoney":
618                                 SqlDbType = SqlDbType.SmallMoney;
619                                 break;
620                         case "text":
621                                 SqlDbType = SqlDbType.Text;
622                                 break;
623                         case "timestamp":
624                                 SqlDbType = SqlDbType.Timestamp;
625                                 break;
626                         case "tinyint":
627                                 SqlDbType = SqlDbType.TinyInt;
628                                 break;
629                         case "uniqueidentifier":
630                                 SqlDbType = SqlDbType.UniqueIdentifier;
631                                 break;
632                         case "varbinary":
633                                 SqlDbType = SqlDbType.VarBinary;
634                                 break;
635                         case "varchar":
636                                 SqlDbType = SqlDbType.VarChar;
637                                 break;
638                         default:
639                                 SqlDbType = SqlDbType.Variant;
640                                 break;
641                         }
642                 }
643
644                 // When the SqlDbType is set, we also set the DbType, as well as the SQL Server
645                 // string representation of the type name.  If the SqlDbType is not convertible
646                 // to a DbType, throw an exception.
647                 private void SetSqlDbType (SqlDbType type)
648                 {
649                         string exception = String.Format ("No mapping exists from SqlDbType {0} to a known DbType.", type);
650
651                         switch (type) {
652                         case SqlDbType.BigInt:
653                                 MetaParameter.TypeName = "bigint";
654                                 dbType = DbType.Int64;
655                                 break;
656                         case SqlDbType.Binary:
657                                 MetaParameter.TypeName = "binary";
658                                 dbType = DbType.Binary;
659                                 break;
660                         case SqlDbType.Timestamp:
661                                 MetaParameter.TypeName = "timestamp";
662                                 dbType = DbType.Binary;
663                                 break;
664                         case SqlDbType.VarBinary:
665                                 MetaParameter.TypeName = "varbinary";
666                                 dbType = DbType.Binary;
667                                 break;
668                         case SqlDbType.Bit:
669                                 MetaParameter.TypeName = "bit";
670                                 dbType = DbType.Boolean;
671                                 break;
672                         case SqlDbType.Char:
673                                 MetaParameter.TypeName = "char";
674                                 dbType = DbType.AnsiStringFixedLength;
675                                 break;
676                         case SqlDbType.DateTime:
677                                 MetaParameter.TypeName = "datetime";
678                                 dbType = DbType.DateTime;
679                                 break;
680                         case SqlDbType.SmallDateTime:
681                                 MetaParameter.TypeName = "smalldatetime";
682                                 dbType = DbType.DateTime;
683                                 break;
684                         case SqlDbType.Decimal:
685                                 MetaParameter.TypeName = "decimal";
686                                 dbType = DbType.Decimal;
687                                 break;
688                         case SqlDbType.Float:
689                                 MetaParameter.TypeName = "float";
690                                 dbType = DbType.Double;
691                                 break;
692                         case SqlDbType.Image:
693                                 MetaParameter.TypeName = "image";
694                                 dbType = DbType.Binary;
695                                 break;
696                         case SqlDbType.Int:
697                                 MetaParameter.TypeName = "int";
698                                 dbType = DbType.Int32;
699                                 break;
700                         case SqlDbType.Money:
701                                 MetaParameter.TypeName = "money";
702                                 dbType = DbType.Currency;
703                                 break;
704                         case SqlDbType.SmallMoney:
705                                 MetaParameter.TypeName = "smallmoney";
706                                 dbType = DbType.Currency;
707                                 break;
708                         case SqlDbType.NChar:
709                                 MetaParameter.TypeName = "nchar";
710                                 dbType = DbType.StringFixedLength;
711                                 break;
712                         case SqlDbType.NText:
713                                 MetaParameter.TypeName = "ntext";
714                                 dbType = DbType.String;
715                                 break;
716                         case SqlDbType.NVarChar:
717                                 MetaParameter.TypeName = "nvarchar";
718                                 dbType = DbType.String;
719                                 break;
720                         case SqlDbType.Real:
721                                 MetaParameter.TypeName = "real";
722                                 dbType = DbType.Single;
723                                 break;
724                         case SqlDbType.SmallInt:
725                                 MetaParameter.TypeName = "smallint";
726                                 dbType = DbType.Int16;
727                                 break;
728                         case SqlDbType.Text:
729                                 MetaParameter.TypeName = "text";
730                                 dbType = DbType.AnsiString;
731                                 break;
732                         case SqlDbType.VarChar:
733                                 MetaParameter.TypeName = "varchar";
734                                 dbType = DbType.AnsiString;
735                                 break;
736                         case SqlDbType.TinyInt:
737                                 MetaParameter.TypeName = "tinyint";
738                                 dbType = DbType.Byte;
739                                 break;
740                         case SqlDbType.UniqueIdentifier:
741                                 MetaParameter.TypeName = "uniqueidentifier";
742                                 dbType = DbType.Guid;
743                                 break;
744                         case SqlDbType.Variant:
745                                 MetaParameter.TypeName = "sql_variant";
746                                 dbType = DbType.Object;
747                                 break;
748                         default:
749                                 throw new ArgumentException (exception);
750                         }
751                         sqlDbType = type;
752                 }
753
754                 public override string ToString() 
755                 {
756                         return ParameterName;
757                 }
758
759                 private object SqlTypeToFrameworkType (object value)
760                 {
761                         if (! (value is INullable)) // if the value is not SqlType
762                                 return value;
763
764                         // Map to .net type, as Mono TDS respects only types from .net
765                         switch (value.GetType ().FullName) {
766                         case "System.Data.SqlTypes.SqlBinary":
767                                 return ( (SqlBinary) value).Value;
768                         case "System.Data.SqlTypes.SqlBoolean":
769                                 return ( (SqlBoolean) value).Value;
770                         case "System.Data.SqlTypes.SqlByte":
771                                 return ( (SqlByte) value).Value;
772                         case "System.Data.SqlTypes.SqlDateTime":
773                                 return ( (SqlDateTime) value).Value;
774                         case "System.Data.SqlTypes.SqlDecimal":
775                                 return ( (SqlDecimal) value).Value;
776                         case "System.Data.SqlTypes.SqlDouble":
777                                 return ( (SqlDouble) value).Value;
778                         case "System.Data.SqlTypes.SqlGuid":
779                                 return ( (SqlGuid) value).Value;
780                         case "System.Data.SqlTypes.SqlInt16":
781                                 return ( (SqlInt16) value).Value;
782                         case "System.Data.SqlTypes.SqlInt32 ":
783                                 return ( (SqlInt32 ) value).Value;
784                         case "System.Data.SqlTypes.SqlInt64":
785                                 return ( (SqlInt64) value).Value;
786                         case "System.Data.SqlTypes.SqlMoney":
787                                 return ( (SqlMoney) value).Value;
788                         case "System.Data.SqlTypes.SqlSingle":
789                                 return ( (SqlSingle) value).Value;
790                         case "System.Data.SqlTypes.SqlString":
791                                 return ( (SqlString) value).Value;
792                         }
793                         return value;
794                 }
795
796 #if NET_2_0
797                 [MonoTODO]
798                 public override void CopyTo (DbParameter param)
799                 {
800                         throw new NotImplementedException ();
801                 }
802                 
803                 [MonoTODO]
804                 public override void ResetDbType ()
805                 {
806                         throw new NotImplementedException ();
807                 }
808 #endif // NET_2_0
809
810                 #endregion // Methods
811         }
812 }