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