/// <summary> /// Allows this <see cref="HsqlCommandBuilder"/> /// to handle additional parameter properties. /// </summary> /// <param name="parameter"> /// A <see cref="DbParameter"/> to which the additional /// modifications are applied. /// </param> /// <param name="row"> /// The <see cref="DataRow"/> from the schema table /// provided by <see cref="DbDataReader.GetSchemaTable"/>. /// </param> /// <param name="statementType"> /// The type of command being generated; INSERT, UPDATE or DELETE. /// </param> /// <param name="whereClause"> /// <c>true</c> if the parameter is part of the update or delete /// <c>WHERE</c> clause; <c>false</c> if it is part of the insert /// or update values. /// </param> protected override void ApplyParameterInfo( DbParameter parameter, DataRow row, StatementType statementType, bool whereClause) { HsqlParameter parm = (HsqlParameter)parameter; int?providerType = row[SchemaTableColumn.ProviderType] as int?; if (providerType != null) { parm.ProviderType = (HsqlProviderType)providerType; } }
internal void DeriveParametersInternal() { if (CommandType != CommandType.StoredProcedure) { throw new InvalidOperationException(string.Format( "Operation not supported for CommandType: " + CommandType.ToString())); } Prepare(); HsqlStatement statement = m_statement; ParameterMetaData pmd = statement.ParameterDescriptor.metaData; string[] parameterNames = pmd.colNames; int count = parameterNames.Length; HsqlParameter[] parameters = new HsqlParameter[count]; for (int i = 0; i < count; i++) { string name = parameterNames[i]; ParameterMode mode = (ParameterMode)pmd.paramMode[i]; int type = pmd.colTypes[i]; int precision = pmd.colSizes[i]; int scale = pmd.colScales[i]; int nullability = pmd.colNullable[i]; HsqlProviderType providerType = (HsqlProviderType)type; DbType dbType = HsqlConvert.ToDbType(providerType); ParameterDirection? direction = HsqlConvert.ToParameterDirection(mode); bool? isNullable = IsNullable(nullability); bool isCharacter = IsCharacterType(type); bool isNumber = (!isCharacter) && IsNumberType(type); bool isTemporal = !(isCharacter || isNumber) && IsTemporalType(type); int size = ToBufferSize(type, precision); if (isCharacter) { precision = 0; scale = 0; } else if (isNumber || isTemporal) { if (precision == 0) { precision = ToDefaultPrecision(type); } } HsqlParameter parameter = new HsqlParameter(); parameter.DbType = dbType; if (direction != null) { parameter.Direction = direction.Value; } if (isNullable != null) { parameter.IsNullable = isNullable.Value; } parameter.ParameterName = name; parameter.Precision = (byte)Math.Min(byte.MaxValue, precision); parameter.ProviderType = providerType; parameter.Scale = (byte)Math.Min(byte.MaxValue, scale); parameter.Size = size; parameter.SourceVersion = DataRowVersion.Default; parameters[i] = parameter; } HsqlParameterCollection pc = Parameters; pc.Clear(); foreach (HsqlParameter parameter in parameters) { pc.Add(parameter); } }
/// <summary> /// Returns a new cloned instance of this parameter. /// </summary> /// <remarks> /// <para> /// Special handling is provided when <c>Value</c> is /// of type <c>byte[]</c>, <c>char[]</c> or <c>ICloneable</c>. /// </para> /// <para> /// Case 1: /// </para> /// <para> /// When the source <c>Value</c> is of type <c>byte[]</c> or /// <c>char[]</c>, then the source <c>Offset</c> and <c>Size</c> /// properties are taken into consideration. Specifically, the /// destination <c>Offset</c> is assigned zero (0) and the destination /// <c>Value</c> is assigned a copy of the source <c>Value</c> that /// starts from the source <c>Offset</c>. When the source <c>Size</c> /// is zero (0), then <c>Value.Length - Offset</c> elements are /// copied; otherwise, the lower of <c>Size</c> or <c>Value.Length /// - Offset</c> elements are copied. /// </para> /// <para> /// Case 2: /// </para> /// <para> /// When the source <c>Value</c> is <c>ICloneable</c> then the target /// <c>Value</c> is assigned a clone of the source <c>Value</c>. /// </para> /// <para> /// Case 3: /// </para> /// <para> /// The target <c>Value</c> is assigned directly from the source /// <c>Value</c>. /// </para> /// </remarks> /// <returns> /// The cloned <see cref="HsqlParameter"/> instance. /// </returns> public HsqlParameter Clone() { HsqlParameter parameter = new HsqlParameter(); parameter.m_assigned = m_assigned; parameter.m_dataRowVersion = m_dataRowVersion; parameter.m_dbType = m_dbType; parameter.m_direction = m_direction; parameter.m_forceSize = m_forceSize; parameter.m_hsqlDbType = m_hsqlDbType; parameter.m_inferProviderType = m_inferProviderType; parameter.m_name = m_name; parameter.m_nullable = m_nullable; parameter.m_precision = m_precision; parameter.m_scale = m_scale; parameter.m_size = m_size; parameter.m_sourceColumn = m_sourceColumn; parameter.m_sourceColumnNullMapping = m_sourceColumnNullMapping; parameter.m_suppressed = m_suppressed; byte[] bytes; char[] chars; if (null != (bytes = m_value as byte[])) { int targetLength = bytes.Length - m_offset; if ((m_size != 0) && (m_size < targetLength)) { targetLength = m_size; } byte[] targetValue = new byte[Math.Max(targetLength, 0)]; Buffer.BlockCopy( bytes, m_offset, targetValue, 0, targetValue.Length); parameter.m_offset = 0; parameter.m_value = targetValue; } else if (null != (chars = m_value as char[])) { int targetLength = chars.Length - m_offset; if ((m_size != 0) && (m_size < targetLength)) { targetLength = m_size; } char[] targetValue = new char[Math.Max(targetLength, 0)]; Buffer.BlockCopy( chars, m_offset, targetValue, 0, targetValue.Length * 2); parameter.m_offset = 0; parameter.m_value = targetValue; } else { parameter.m_offset = m_offset; ICloneable cloneable = m_value as ICloneable; parameter.m_value = (cloneable == null) ? m_value : cloneable.Clone(); } return parameter; }
internal void DeriveParametersInternal() { if (CommandType != CommandType.StoredProcedure) { throw new InvalidOperationException(string.Format( "Operation not supported for CommandType: " + CommandType.ToString())); } Prepare(); HsqlStatement statement = m_statement; ParameterMetaData pmd = statement.ParameterDescriptor.metaData; string[] parameterNames = pmd.colNames; int count = parameterNames.Length; HsqlParameter[] parameters = new HsqlParameter[count]; for (int i = 0; i < count; i++) { string name = parameterNames[i]; ParameterMode mode = (ParameterMode)pmd.paramMode[i]; int type = pmd.colTypes[i]; int precision = pmd.colSizes[i]; int scale = pmd.colScales[i]; int nullability = pmd.colNullable[i]; HsqlProviderType providerType = (HsqlProviderType)type; DbType dbType = HsqlConvert.ToDbType(providerType); ParameterDirection?direction = HsqlConvert.ToParameterDirection(mode); bool?isNullable = IsNullable(nullability); bool isCharacter = IsCharacterType(type); bool isNumber = (!isCharacter) && IsNumberType(type); bool isTemporal = !(isCharacter || isNumber) && IsTemporalType(type); int size = ToBufferSize(type, precision); if (isCharacter) { precision = 0; scale = 0; } else if (isNumber || isTemporal) { if (precision == 0) { precision = ToDefaultPrecision(type); } } HsqlParameter parameter = new HsqlParameter(); parameter.DbType = dbType; if (direction != null) { parameter.Direction = direction.Value; } if (isNullable != null) { parameter.IsNullable = isNullable.Value; } parameter.ParameterName = name; parameter.Precision = (byte)Math.Min(byte.MaxValue, precision); parameter.ProviderType = providerType; parameter.Scale = (byte)Math.Min(byte.MaxValue, scale); parameter.Size = size; parameter.SourceVersion = DataRowVersion.Default; parameters[i] = parameter; } HsqlParameterCollection pc = Parameters; pc.Clear(); foreach (HsqlParameter parameter in parameters) { pc.Add(parameter); } }
/// <summary> /// Returns a new cloned instance of this parameter. /// </summary> /// <remarks> /// <para> /// Special handling is provided when <c>Value</c> is /// of type <c>byte[]</c>, <c>char[]</c> or <c>ICloneable</c>. /// </para> /// <para> /// Case 1: /// </para> /// <para> /// When the source <c>Value</c> is of type <c>byte[]</c> or /// <c>char[]</c>, then the source <c>Offset</c> and <c>Size</c> /// properties are taken into consideration. Specifically, the /// destination <c>Offset</c> is assigned zero (0) and the destination /// <c>Value</c> is assigned a copy of the source <c>Value</c> that /// starts from the source <c>Offset</c>. When the source <c>Size</c> /// is zero (0), then <c>Value.Length - Offset</c> elements are /// copied; otherwise, the lower of <c>Size</c> or <c>Value.Length /// - Offset</c> elements are copied. /// </para> /// <para> /// Case 2: /// </para> /// <para> /// When the source <c>Value</c> is <c>ICloneable</c> then the target /// <c>Value</c> is assigned a clone of the source <c>Value</c>. /// </para> /// <para> /// Case 3: /// </para> /// <para> /// The target <c>Value</c> is assigned directly from the source /// <c>Value</c>. /// </para> /// </remarks> /// <returns> /// The cloned <see cref="HsqlParameter"/> instance. /// </returns> public HsqlParameter Clone() { HsqlParameter parameter = new HsqlParameter(); parameter.m_assigned = m_assigned; parameter.m_dataRowVersion = m_dataRowVersion; parameter.m_dbType = m_dbType; parameter.m_direction = m_direction; parameter.m_forceSize = m_forceSize; parameter.m_hsqlDbType = m_hsqlDbType; parameter.m_inferProviderType = m_inferProviderType; parameter.m_name = m_name; parameter.m_nullable = m_nullable; parameter.m_precision = m_precision; parameter.m_scale = m_scale; parameter.m_size = m_size; parameter.m_sourceColumn = m_sourceColumn; parameter.m_sourceColumnNullMapping = m_sourceColumnNullMapping; parameter.m_suppressed = m_suppressed; byte[] bytes; char[] chars; if (null != (bytes = m_value as byte[])) { int targetLength = bytes.Length - m_offset; if ((m_size != 0) && (m_size < targetLength)) { targetLength = m_size; } byte[] targetValue = new byte[Math.Max(targetLength, 0)]; Buffer.BlockCopy( bytes, m_offset, targetValue, 0, targetValue.Length); parameter.m_offset = 0; parameter.m_value = targetValue; } else if (null != (chars = m_value as char[])) { int targetLength = chars.Length - m_offset; if ((m_size != 0) && (m_size < targetLength)) { targetLength = m_size; } char[] targetValue = new char[Math.Max(targetLength, 0)]; Buffer.BlockCopy( chars, m_offset, targetValue, 0, targetValue.Length * 2); parameter.m_offset = 0; parameter.m_value = targetValue; } else { parameter.m_offset = m_offset; ICloneable cloneable = m_value as ICloneable; parameter.m_value = (cloneable == null) ? m_value : cloneable.Clone(); } return(parameter); }