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
.Runtime
.InteropServices
;
26 namespace IBM
.Data
.DB2
29 public sealed class DB2Parameter
: MarshalByRefObject
, IDbDataParameter
, IDataParameter
, ICloneable
31 private DbType dbType
= DbType
.Object
;
32 private DB2Type db2Type
= DB2Type
.Invalid
;
33 private short db2DataType
= DB2Constants
.SQL_UNKNOWN_TYPE
;
34 private short db2LastUsedDataType
= DB2Constants
.SQL_UNKNOWN_TYPE
;
36 private ParameterDirection direction
;
37 private short db2Direction
= DB2Constants
.SQL_PARAM_INPUT
;
38 private bool nullable
= true;
39 private string parameterName
;
40 private string sourceColumn
;
41 private DataRowVersion sourceVersion
;
42 private object dataVal
;
43 private byte scale
, precision
;
45 internal IntPtr internalBuffer
;
46 internal IntPtr internalLengthBuffer
;
47 internal int requiredMemory
;
49 #region Contructors and destructors
52 direction
= ParameterDirection
.Input
;
53 sourceVersion
= DataRowVersion
.Current
;
56 public DB2Parameter(string name
, DB2Type type
)
58 direction
= ParameterDirection
.Input
;
59 sourceVersion
= DataRowVersion
.Current
;
60 this.ParameterName
= name
;
64 public DB2Parameter(string name
, DB2Type type
, int size
)
66 direction
= ParameterDirection
.Input
;
67 sourceVersion
= DataRowVersion
.Current
;
68 this.ParameterName
= name
;
73 public DB2Parameter(string name
, DB2Type type
, int size
, string sourceColumn
)
75 direction
= ParameterDirection
.Input
;
76 sourceVersion
= DataRowVersion
.Current
;
77 this.ParameterName
= name
;
80 this.SourceColumn
= sourceColumn
;
83 public DB2Parameter(string parameterName
, object value)
85 direction
= ParameterDirection
.Input
;
86 sourceVersion
= DataRowVersion
.Current
;
87 this.ParameterName
= parameterName
;
91 public DB2Parameter(string parameterName
, DB2Type db2Type
, int size
, ParameterDirection parameterDirection
, bool isNullable
, byte precision
, byte scale
, string srcColumn
, DataRowVersion srcVersion
, object value)
93 this.ParameterName
= parameterName
;
94 this.DB2Type
= db2Type
;
96 this.Direction
= parameterDirection
;
97 this.IsNullable
= isNullable
;
98 this.Precision
= precision
;
100 this.SourceColumn
= srcColumn
;
101 this.SourceVersion
= srcVersion
;
108 #region DbType Property
109 public DB2Type DB2Type
120 case DB2Type
.Invalid
: dbType
= DbType
.Object
; db2DataType
= DB2Constants
.SQL_UNKNOWN_TYPE
; break;
121 case DB2Type
.SmallInt
: dbType
= DbType
.Int16
; db2DataType
= DB2Constants
.SQL_SMALLINT
; break;
122 case DB2Type
.Integer
: dbType
= DbType
.Int32
; db2DataType
= DB2Constants
.SQL_INTEGER
; break;
123 case DB2Type
.BigInt
: dbType
= DbType
.Int64
; db2DataType
= DB2Constants
.SQL_BIGINT
; break;
124 case DB2Type
.Real
: dbType
= DbType
.Single
; db2DataType
= DB2Constants
.SQL_REAL
; break;
125 case DB2Type
.Double
: dbType
= DbType
.Double
; db2DataType
= DB2Constants
.SQL_DOUBLE
; break;
126 case DB2Type
.Float
: dbType
= DbType
.Single
; db2DataType
= DB2Constants
.SQL_REAL
; break;
127 case DB2Type
.Decimal
: dbType
= DbType
.Decimal
; db2DataType
= DB2Constants
.SQL_DECIMAL
; break;
128 case DB2Type
.Numeric
: dbType
= DbType
.VarNumeric
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
129 case DB2Type
.Date
: dbType
= DbType
.Date
; db2DataType
= DB2Constants
.SQL_TYPE_DATE
; break;
130 case DB2Type
.Time
: dbType
= DbType
.Time
; db2DataType
= DB2Constants
.SQL_TYPE_TIME
; break;
131 case DB2Type
.Timestamp
: dbType
= DbType
.DateTime
; db2DataType
= DB2Constants
.SQL_TYPE_TIMESTAMP
; break;
132 case DB2Type
.Char
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
133 case DB2Type
.VarChar
: dbType
= DbType
.StringFixedLength
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
134 case DB2Type
.LongVarChar
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
135 case DB2Type
.Binary
: dbType
= DbType
.Binary
; db2DataType
= DB2Constants
.SQL_VARBINARY
; break;
136 case DB2Type
.VarBinary
: dbType
= DbType
.Binary
; db2DataType
= DB2Constants
.SQL_VARBINARY
; break;
137 case DB2Type
.LongVarBinary
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
138 case DB2Type
.Graphic
: dbType
= DbType
.StringFixedLength
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
139 case DB2Type
.VarGraphic
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
140 case DB2Type
.LongVarGraphic
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
141 case DB2Type
.Clob
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
142 case DB2Type
.Blob
: dbType
= DbType
.Binary
; db2DataType
= DB2Constants
.SQL_VARBINARY
; break;
143 case DB2Type
.DbClob
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
144 case DB2Type
.Datalink
: dbType
= DbType
.Byte
; db2DataType
= DB2Constants
.SQL_VARBINARY
; break;
145 case DB2Type
.RowId
: dbType
= DbType
.Decimal
; db2DataType
= DB2Constants
.SQL_DECIMAL
; break;
146 case DB2Type
.XmlReader
: dbType
= DbType
.String
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
148 throw new NotSupportedException("Value is of unknown data type");
153 /// Parameter data type
166 case DbType
.AnsiString
: db2Type
= DB2Type
.VarChar
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
167 case DbType
.AnsiStringFixedLength
: db2Type
= DB2Type
.Char
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
168 case DbType
.Binary
: db2Type
= DB2Type
.Binary
; db2DataType
= DB2Constants
.SQL_VARBINARY
; break;
169 case DbType
.Boolean
: db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_BIT
; break;
170 case DbType
.Byte
: db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_UTINYINT
; break;
171 case DbType
.Currency
: db2Type
= DB2Type
.Decimal
; db2DataType
= DB2Constants
.SQL_DECIMAL
; break;
172 case DbType
.Date
: db2Type
= DB2Type
.Date
; db2DataType
= DB2Constants
.SQL_TYPE_DATE
; break;
173 case DbType
.DateTime
: db2Type
= DB2Type
.Timestamp
; db2DataType
= DB2Constants
.SQL_TYPE_TIMESTAMP
; break;
174 case DbType
.Decimal
: db2Type
= DB2Type
.Decimal
; db2DataType
= DB2Constants
.SQL_DECIMAL
; break;
175 case DbType
.Double
: db2Type
= DB2Type
.Double
; db2DataType
= DB2Constants
.SQL_DOUBLE
; break;
176 case DbType
.Guid
: db2Type
= DB2Type
.Binary
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
177 case DbType
.Int16
: db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_SMALLINT
; break;
178 case DbType
.Int32
: db2Type
= DB2Type
.Integer
; db2DataType
= DB2Constants
.SQL_INTEGER
; break;
179 case DbType
.Int64
: db2Type
= DB2Type
.BigInt
; db2DataType
= DB2Constants
.SQL_BIGINT
; break;
180 case DbType
.Object
: db2Type
= DB2Type
.Invalid
; db2DataType
= DB2Constants
.SQL_UNKNOWN_TYPE
; break;
181 case DbType
.SByte
: db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_UTINYINT
; break;
182 case DbType
.Single
: db2Type
= DB2Type
.Float
; db2DataType
= DB2Constants
.SQL_REAL
; break;
183 case DbType
.String
: db2Type
= DB2Type
.VarChar
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
184 case DbType
.StringFixedLength
: db2Type
= DB2Type
.Char
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
185 case DbType
.Time
: db2Type
= DB2Type
.Time
; db2DataType
= DB2Constants
.SQL_TYPE_TIME
; break;
186 case DbType
.UInt16
: db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_SMALLINT
; break;
187 case DbType
.UInt32
: db2Type
= DB2Type
.Integer
; db2DataType
= DB2Constants
.SQL_INTEGER
; break;
188 case DbType
.UInt64
: db2Type
= DB2Type
.BigInt
; db2DataType
= DB2Constants
.SQL_BIGINT
; break;
189 case DbType
.VarNumeric
: db2Type
= DB2Type
.Numeric
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
191 throw new NotSupportedException("Value is of unknown data type");
199 /// In or out parameter, or both
201 public ParameterDirection Direction
213 case ParameterDirection
.Input
: db2Direction
= DB2Constants
.SQL_PARAM_INPUT
; break;
214 case ParameterDirection
.Output
: db2Direction
= DB2Constants
.SQL_PARAM_OUTPUT
; break;
215 case ParameterDirection
.InputOutput
: db2Direction
= DB2Constants
.SQL_PARAM_INPUT_OUTPUT
; break;
216 case ParameterDirection
.ReturnValue
: db2Direction
= DB2Constants
.SQL_RETURN_VALUE
; break;
223 /// Does this parameter support a null value
225 public bool IsNullable
237 #region ParameterName
238 public string ParameterName
242 return parameterName
;
246 parameterName
= value;
252 /// Gets or sets the name of the source column that is mapped to the DataSet
254 public string SourceColumn
262 sourceColumn
= value;
266 #region SourceVersion
268 /// DataRowVersion property
270 public DataRowVersion SourceVersion
274 return sourceVersion
;
278 sourceVersion
= value;
282 #region IDbDataParameter properties
283 public byte Precision
321 /// The actual parameter data
331 this.dataVal
= value;
337 #region inferType Method
339 /// Determine the data type based on the value
341 private void InferType()
344 throw new ArgumentException("No DB2Parameter.Value found");
346 if(Value
is IConvertible
)
348 switch(((IConvertible
)Value
).GetTypeCode())
350 case TypeCode
.Char
: dbType
= DbType
.Byte
; db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
351 case TypeCode
.Boolean
: dbType
= DbType
.Byte
; db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_BIT
; break;
353 case TypeCode
.Byte
: dbType
= DbType
.Byte
; db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_UTINYINT
; break;
354 case TypeCode
.UInt16
:
355 case TypeCode
.Int16
: dbType
= DbType
.Int16
; db2Type
= DB2Type
.SmallInt
; db2DataType
= DB2Constants
.SQL_SMALLINT
; break;
356 case TypeCode
.UInt32
:
357 case TypeCode
.Int32
: dbType
= DbType
.Int32
; db2Type
= DB2Type
.Integer
; db2DataType
= DB2Constants
.SQL_INTEGER
; break;
358 case TypeCode
.UInt64
:
359 case TypeCode
.Int64
: dbType
= DbType
.Int64
; db2Type
= DB2Type
.BigInt
; db2DataType
= DB2Constants
.SQL_BIGINT
; break;
360 case TypeCode
.Single
: dbType
= DbType
.Single
; db2Type
= DB2Type
.Float
; db2DataType
= DB2Constants
.SQL_REAL
; break;
361 case TypeCode
.Double
: dbType
= DbType
.Double
; db2Type
= DB2Type
.Double
; db2DataType
= DB2Constants
.SQL_DOUBLE
; break;
362 case TypeCode
.Decimal
: dbType
= DbType
.Decimal
; db2Type
= DB2Type
.Decimal
; db2DataType
= DB2Constants
.SQL_DECIMAL
; break;
363 case TypeCode
.DateTime
: dbType
= DbType
.DateTime
; db2Type
= DB2Type
.Timestamp
; db2DataType
= DB2Constants
.SQL_TYPE_TIMESTAMP
; break;
364 case TypeCode
.String
: dbType
= DbType
.String
; db2Type
= DB2Type
.VarChar
; db2DataType
= DB2Constants
.SQL_WCHAR
; break;
366 case TypeCode
.Object
:
367 case TypeCode
.DBNull
:
369 throw new SystemException("Unknown data type");
371 throw new SystemException("Value is of unknown data type");
374 else if(Value
is byte[])
376 dbType
= DbType
.Binary
;
377 db2Type
= DB2Type
.VarBinary
;
378 db2DataType
= DB2Constants
.SQL_VARBINARY
;
380 else if(Value
is TimeSpan
)
382 dbType
= DbType
.Time
;
383 db2Type
= DB2Type
.Time
;
384 db2DataType
= DB2Constants
.SQL_TYPE_TIME
;
388 throw new NotSupportedException("Value is of unsupported data type");
393 internal void CalculateRequiredmemory()
395 //if((direction == ParameterDirection.Input) || (direction == ParameterDirection.InputOutput))
398 // throw new ArgumentException("Value missing");
400 if(dbType
== DbType
.Object
)
402 if((direction
== ParameterDirection
.Output
) || (direction
== ParameterDirection
.ReturnValue
))
403 throw new ArgumentException("Unknown type");
405 if((direction
!= ParameterDirection
.Input
) || !Convert
.IsDBNull(Value
))
410 if (db2DataType
== DB2Constants
.SQL_INTEGER
)
414 if((db2DataType
== DB2Constants
.SQL_VARBINARY
) ||
415 (db2DataType
== DB2Constants
.SQL_WCHAR
))
419 if(direction
!= ParameterDirection
.Input
)
420 throw new ArgumentException("Size not specified");
421 if(Value
== DBNull
.Value
)
423 else if(Value
is string)
424 requiredMemory
= ((string)Value
).Length
;
425 else if(Value
is byte[])
426 requiredMemory
= ((byte[])Value
).Length
;
428 throw new ArgumentException("wrong type!?");
432 requiredMemory
= Size
;
434 if(db2DataType
== DB2Constants
.SQL_WCHAR
)
435 requiredMemory
= (requiredMemory
* 2) + 2;
436 requiredMemory
= (requiredMemory
| 0xf) + 1;
438 requiredMemory
= Math
.Max(128, requiredMemory
);
443 /// Bind this parameter
445 internal short Bind(IntPtr hwndStmt
, short paramNum
)
447 int inLength
= requiredMemory
;
448 db2LastUsedDataType
= db2DataType
;
449 short db2CType
= DB2Constants
.SQL_C_DEFAULT
;
450 if((direction
== ParameterDirection
.Input
) || (direction
== ParameterDirection
.InputOutput
))
452 if(Convert
.IsDBNull(Value
))
454 inLength
= DB2Constants
.SQL_NULL_DATA
;
455 if((db2DataType
== DB2Constants
.SQL_UNKNOWN_TYPE
) ||
456 (db2DataType
== DB2Constants
.SQL_DECIMAL
))
458 db2LastUsedDataType
= DB2Constants
.SQL_VARGRAPHIC
;
459 db2CType
= DB2Constants
.SQL_C_WCHAR
;
463 if((direction
== ParameterDirection
.Input
) || (direction
== ParameterDirection
.InputOutput
))
467 case DB2Constants
.SQL_WCHAR
:
468 string tmpString
= Convert
.ToString(Value
);
469 inLength
= tmpString
.Length
;
470 if((Size
> 0) && (inLength
> Size
))
472 Marshal
.Copy(tmpString
.ToCharArray(), 0, internalBuffer
, inLength
);
474 db2LastUsedDataType
= DB2Constants
.SQL_VARGRAPHIC
;
475 db2CType
= DB2Constants
.SQL_C_WCHAR
;
478 db2LastUsedDataType
= DB2Constants
.SQL_TYPE_BLOB
;
481 case DB2Constants
.SQL_VARBINARY
:
482 byte[] tmpBytes
= (byte[])Value
;
483 inLength
= tmpBytes
.Length
;
484 if((Size
> 0) && (inLength
> Size
))
486 Marshal
.Copy(tmpBytes
, 0, internalBuffer
, inLength
);
487 db2CType
= DB2Constants
.SQL_TYPE_BINARY
;
489 case DB2Constants
.SQL_BIT
:
490 case DB2Constants
.SQL_UTINYINT
:
491 case DB2Constants
.SQL_SMALLINT
:
492 Marshal
.WriteInt16(internalBuffer
, Convert
.ToInt16(Value
));
493 db2CType
= DB2Constants
.SQL_C_SSHORT
;
495 case DB2Constants
.SQL_INTEGER
:
496 Marshal
.WriteInt32(internalBuffer
, Convert
.ToInt32(Value
));
497 db2CType
= DB2Constants
.SQL_C_SLONG
;
499 case DB2Constants
.SQL_BIGINT
:
500 Marshal
.WriteInt64(internalBuffer
, Convert
.ToInt64(Value
));
501 db2CType
= DB2Constants
.SQL_C_SBIGINT
;
503 case DB2Constants
.SQL_REAL
:
504 Marshal
.StructureToPtr((float)Convert
.ToDouble(Value
), internalBuffer
, false);
505 db2CType
= DB2Constants
.SQL_C_TYPE_REAL
;
507 case DB2Constants
.SQL_DOUBLE
:
508 Marshal
.StructureToPtr(Convert
.ToDouble(Value
), internalBuffer
, false);
509 db2CType
= DB2Constants
.SQL_C_DOUBLE
;
511 case DB2Constants
.SQL_DECIMAL
:
512 byte[] tmpDecimalData
= System
.Text
.Encoding
.UTF8
.GetBytes(
513 Convert
.ToDecimal(Value
).ToString(System
.Globalization
.CultureInfo
.InvariantCulture
));
514 inLength
= Math
.Min(tmpDecimalData
.Length
, requiredMemory
);
515 Marshal
.Copy(tmpDecimalData
, 0, internalBuffer
, inLength
);
516 db2LastUsedDataType
= DB2Constants
.SQL_VARCHAR
;
517 db2CType
= DB2Constants
.SQL_C_CHAR
;
519 case DB2Constants
.SQL_TYPE_DATE
:
520 DateTime tmpDate
= Convert
.ToDateTime(Value
);
521 Marshal
.WriteInt16(internalBuffer
, 0, (short)tmpDate
.Year
);
522 Marshal
.WriteInt16(internalBuffer
, 2, (short)tmpDate
.Month
);
523 Marshal
.WriteInt16(internalBuffer
, 4, (short)tmpDate
.Day
);
524 db2CType
= DB2Constants
.SQL_C_TYPE_DATE
;
526 case DB2Constants
.SQL_TYPE_TIMESTAMP
:
527 DateTime tmpDateTime
= Convert
.ToDateTime(Value
);
528 Marshal
.WriteInt16(internalBuffer
, 0, (short)tmpDateTime
.Year
);
529 Marshal
.WriteInt16(internalBuffer
, 2, (short)tmpDateTime
.Month
);
530 Marshal
.WriteInt16(internalBuffer
, 4, (short)tmpDateTime
.Day
);
531 Marshal
.WriteInt16(internalBuffer
, 6, (short)tmpDateTime
.Hour
);
532 Marshal
.WriteInt16(internalBuffer
, 8, (short)tmpDateTime
.Minute
);
533 Marshal
.WriteInt16(internalBuffer
, 10, (short)tmpDateTime
.Second
);
534 Marshal
.WriteInt32(internalBuffer
, 12, (int)((tmpDateTime
.Ticks
% 10000000) * 100));
535 db2CType
= DB2Constants
.SQL_C_TYPE_TIMESTAMP
;
537 case DB2Constants
.SQL_TYPE_TIME
:
538 TimeSpan tmpTime
= (TimeSpan
)Value
;
539 Marshal
.WriteInt16(internalBuffer
, 0, (short)tmpTime
.Hours
);
540 Marshal
.WriteInt16(internalBuffer
, 2, (short)tmpTime
.Minutes
);
541 Marshal
.WriteInt16(internalBuffer
, 4, (short)tmpTime
.Seconds
);
542 db2CType
= DB2Constants
.SQL_C_TYPE_TIME
;
550 case DB2Constants
.SQL_WCHAR
:
551 db2LastUsedDataType
= DB2Constants
.SQL_VARGRAPHIC
;
552 db2CType
= DB2Constants
.SQL_C_WCHAR
;
554 case DB2Constants
.SQL_VARBINARY
:
555 db2CType
= DB2Constants
.SQL_TYPE_BINARY
;
557 case DB2Constants
.SQL_BIT
:
558 case DB2Constants
.SQL_UTINYINT
:
559 case DB2Constants
.SQL_SMALLINT
:
560 db2CType
= DB2Constants
.SQL_C_SSHORT
;
562 case DB2Constants
.SQL_INTEGER
:
563 db2CType
= DB2Constants
.SQL_C_SLONG
;
565 case DB2Constants
.SQL_BIGINT
:
566 db2CType
= DB2Constants
.SQL_C_SBIGINT
;
568 case DB2Constants
.SQL_REAL
:
569 db2CType
= DB2Constants
.SQL_C_TYPE_REAL
;
571 case DB2Constants
.SQL_DOUBLE
:
572 db2CType
= DB2Constants
.SQL_C_DOUBLE
;
574 case DB2Constants
.SQL_DECIMAL
:
575 db2LastUsedDataType
= DB2Constants
.SQL_VARCHAR
;
576 db2CType
= DB2Constants
.SQL_C_CHAR
;
578 case DB2Constants
.SQL_TYPE_DATE
:
579 db2CType
= DB2Constants
.SQL_C_TYPE_DATE
;
581 case DB2Constants
.SQL_TYPE_TIMESTAMP
:
582 db2CType
= DB2Constants
.SQL_C_TYPE_TIMESTAMP
;
584 case DB2Constants
.SQL_TYPE_TIME
:
585 db2CType
= DB2Constants
.SQL_C_TYPE_TIME
;
589 Marshal
.WriteInt32(internalLengthBuffer
, inLength
);
590 short sqlRet
= DB2CLIWrapper
.SQLBindParameter(hwndStmt
, paramNum
, db2Direction
,
591 db2CType
, db2LastUsedDataType
, Size
, Scale
,
592 internalBuffer
, requiredMemory
, internalLengthBuffer
);
597 object ICloneable
.Clone ()
599 DB2Parameter clone
= new DB2Parameter();
600 clone
.dbType
= dbType
;
601 clone
.db2Type
= db2Type
;
602 clone
.db2DataType
= db2DataType
;
603 clone
.db2LastUsedDataType
= db2LastUsedDataType
;
604 clone
.direction
= direction
;
605 clone
.db2Direction
= db2Direction
;
606 clone
.nullable
= nullable
;
607 clone
.parameterName
= parameterName
;
608 clone
.sourceColumn
= sourceColumn
;
609 clone
.sourceVersion
= sourceVersion
;
610 clone
.dataVal
= dataVal
;
612 clone
.precision
= precision
;
614 if(dataVal
is ICloneable
)
616 clone
.dataVal
= ((ICloneable
)dataVal
).Clone();
621 internal void GetOutValue()
623 int length
= Marshal
.ReadInt32(internalLengthBuffer
);
624 if(length
== DB2Constants
.SQL_NULL_DATA
)
626 dataVal
= DBNull
.Value
;
631 case DB2Type
.SmallInt
:
632 dataVal
= Marshal
.ReadInt16(internalBuffer
);
634 case DB2Type
.Integer
:
635 dataVal
= Marshal
.ReadInt32(internalBuffer
);
638 dataVal
= Marshal
.ReadInt64(internalBuffer
);
641 dataVal
= Marshal
.PtrToStructure(internalBuffer
, typeof(Double
));
644 dataVal
= Marshal
.PtrToStructure(internalBuffer
, typeof(Single
));
647 case DB2Type
.VarChar
:
648 case DB2Type
.LongVarChar
:
649 case DB2Type
.Graphic
:
650 case DB2Type
.VarGraphic
:
651 case DB2Type
.LongVarGraphic
:
654 dataVal
= Marshal
.PtrToStringUni(internalBuffer
, Math
.Min(Size
, length
/ 2));
657 case DB2Type
.VarBinary
:
658 case DB2Type
.LongVarBinary
:
660 case DB2Type
.Datalink
:
661 length
= Math
.Min(Size
, length
);
662 dataVal
= new byte[length
];
663 Marshal
.Copy(internalBuffer
, (byte[])dataVal
, 0, length
);
665 case DB2Type
.Decimal
:
666 dataVal
= decimal.Parse(Marshal
.PtrToStringAnsi(internalBuffer
, length
),
667 System
.Globalization
.CultureInfo
.InvariantCulture
);
669 case DB2Type
.Timestamp
:
670 DateTime dtTmp
= new DateTime(
671 Marshal
.ReadInt16(internalBuffer
, 0), // year
672 Marshal
.ReadInt16(internalBuffer
, 2), // month
673 Marshal
.ReadInt16(internalBuffer
, 4), // day
674 Marshal
.ReadInt16(internalBuffer
, 6), // hour
675 Marshal
.ReadInt16(internalBuffer
, 8), // minute
676 Marshal
.ReadInt16(internalBuffer
, 10));// second
677 dataVal
= dtTmp
.AddTicks(Marshal
.ReadInt32(internalBuffer
, 12) / 100); // nanoseconds
680 dataVal
= new DateTime(
681 Marshal
.ReadInt16(internalBuffer
, 0),
682 Marshal
.ReadInt16(internalBuffer
, 2),
683 Marshal
.ReadInt16(internalBuffer
, 4));
686 dataVal
= new TimeSpan(
687 Marshal
.ReadInt16(internalBuffer
, 0), // Hour
688 Marshal
.ReadInt16(internalBuffer
, 2), // Minute
689 Marshal
.ReadInt16(internalBuffer
, 4)); // Second
692 case DB2Type
.Invalid
:
694 case DB2Type
.Numeric
:
696 case DB2Type
.XmlReader
:
697 throw new NotImplementedException();
699 throw new NotSupportedException("unknown data type");