private void UpdateParameterValues(Descriptor descriptor, int batchIndex) { if (!HasParameters) { return; } for (var i = 0; i < descriptor.Count; i++) { var parameter = descriptor[i]; var index = i; if (_namedParameters.Count > 0) { index = _batchParameters[batchIndex].IndexOf(_namedParameters[i], i); if (index == -1) { throw FbException.Create($"Must declare the variable '{_namedParameters[i]}'."); } } if (index != -1) { var commandParameter = _batchParameters[batchIndex][index]; if (commandParameter.InternalValue == DBNull.Value || commandParameter.InternalValue == null) { parameter.NullFlag = -1; parameter.DbValue.SetValue(DBNull.Value); if (!parameter.AllowDBNull()) { parameter.DataType++; } } else { parameter.NullFlag = 0; switch (parameter.DbDataType) { case DbDataType.Binary: { var blob = _statement.CreateBlob(); blob.Write((byte[])commandParameter.InternalValue); parameter.DbValue.SetValue(blob.Id); } break; case DbDataType.Text: { var blob = _statement.CreateBlob(); if (commandParameter.InternalValue is byte[]) { blob.Write((byte[])commandParameter.InternalValue); } else { blob.Write((string)commandParameter.InternalValue); } parameter.DbValue.SetValue(blob.Id); } break; case DbDataType.Array: { if (parameter.ArrayHandle == null) { parameter.ArrayHandle = _statement.CreateArray(parameter.Relation, parameter.Name); } else { parameter.ArrayHandle.Database = _statement.Database; parameter.ArrayHandle.Transaction = _statement.Transaction; } parameter.ArrayHandle.Handle = 0; parameter.ArrayHandle.Write((Array)commandParameter.InternalValue); parameter.DbValue.SetValue(parameter.ArrayHandle.Handle); } break; case DbDataType.Guid: if (!(commandParameter.InternalValue is Guid) && !(commandParameter.InternalValue is byte[])) { throw new InvalidOperationException("Incorrect Guid value."); } parameter.DbValue.SetValue(commandParameter.InternalValue); break; default: parameter.DbValue.SetValue(commandParameter.InternalValue); break; } } } } }
private void UpdateParameterValues() { var index = -1; for (var i = 0; i < _statement.Parameters.Count; i++) { var statementParameter = _statement.Parameters[i]; index = i; if (_namedParameters.Count > 0) { index = Parameters.IndexOf(_namedParameters[i], i); if (index == -1) { throw new FbException(string.Format("Must declare the variable '{0}'", _namedParameters[i])); } } if (index != -1) { var commandParameter = Parameters[index]; if (commandParameter.InternalValue == DBNull.Value || commandParameter.InternalValue == null) { statementParameter.NullFlag = -1; statementParameter.Value = DBNull.Value; if (!statementParameter.AllowDBNull()) { statementParameter.DataType++; } } else { statementParameter.NullFlag = 0; switch (statementParameter.DbDataType) { case DbDataType.Binary: { var blob = _statement.CreateBlob(); blob.Write((byte[])commandParameter.InternalValue); statementParameter.Value = blob.Id; } break; case DbDataType.Text: { var blob = _statement.CreateBlob(); if (commandParameter.InternalValue is byte[]) { blob.Write((byte[])commandParameter.InternalValue); } else { blob.Write((string)commandParameter.InternalValue); } statementParameter.Value = blob.Id; } break; case DbDataType.Array: { if (statementParameter.ArrayHandle == null) { statementParameter.ArrayHandle = _statement.CreateArray( statementParameter.Relation, statementParameter.Name); } else { statementParameter.ArrayHandle.Database = _statement.Database; statementParameter.ArrayHandle.Transaction = _statement.Transaction; } statementParameter.ArrayHandle.Handle = 0; statementParameter.ArrayHandle.Write((System.Array)commandParameter.InternalValue); statementParameter.Value = statementParameter.ArrayHandle.Handle; } break; case DbDataType.Guid: if (!(commandParameter.InternalValue is Guid) && !(commandParameter.InternalValue is byte[])) { throw new InvalidOperationException("Incorrect Guid value."); } statementParameter.Value = commandParameter.InternalValue; break; default: statementParameter.Value = commandParameter.InternalValue; break; } } } } }