|
17 | 17 |
|
18 | 18 | using System;
|
19 | 19 | using System.Collections.Generic;
|
| 20 | +using System.Data; |
20 | 21 | using System.Linq;
|
21 | 22 | using System.Text;
|
22 | 23 | using FirebirdSql.EntityFrameworkCore.Firebird.Storage.Internal;
|
@@ -252,4 +253,68 @@ void AppendSqlLiteral(StringBuilder commandStringBuilder, object value, IPropert
|
252 | 253 | mapping ??= Dependencies.TypeMappingSource.GetMappingForValue(value);
|
253 | 254 | commandStringBuilder.Append(mapping.GenerateProviderValueSqlLiteral(value));
|
254 | 255 | }
|
| 256 | + |
| 257 | + public override ResultSetMapping AppendStoredProcedureCall( |
| 258 | + StringBuilder commandStringBuilder, |
| 259 | + IReadOnlyModificationCommand command, |
| 260 | + int commandPosition, |
| 261 | + out bool requiresTransaction) |
| 262 | + { |
| 263 | + var storedProcedure = command.StoreStoredProcedure; |
| 264 | + var resultSetMapping = ResultSetMapping.NoResults; |
| 265 | + |
| 266 | + foreach (var resultColumn in storedProcedure.ResultColumns) |
| 267 | + { |
| 268 | + resultSetMapping = ResultSetMapping.LastInResultSet; |
| 269 | + if (resultColumn == command.RowsAffectedColumn) |
| 270 | + { |
| 271 | + resultSetMapping |= ResultSetMapping.ResultSetWithRowsAffectedOnly; |
| 272 | + } |
| 273 | + else |
| 274 | + { |
| 275 | + resultSetMapping = ResultSetMapping.LastInResultSet; |
| 276 | + break; |
| 277 | + } |
| 278 | + } |
| 279 | + |
| 280 | + commandStringBuilder.Append("EXECUTE PROCEDURE "); |
| 281 | + SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, storedProcedure.Name); |
| 282 | + |
| 283 | + if (storedProcedure.Parameters.Any()) |
| 284 | + { |
| 285 | + commandStringBuilder.Append(" "); |
| 286 | + var first = true; |
| 287 | + |
| 288 | + for (var i = 0; i < command.ColumnModifications.Count; i++) |
| 289 | + { |
| 290 | + var columnModification = command.ColumnModifications[i]; |
| 291 | + if (columnModification.Column is not IStoreStoredProcedureParameter parameter) |
| 292 | + { |
| 293 | + continue; |
| 294 | + } |
| 295 | + |
| 296 | + if (parameter.Direction.HasFlag(ParameterDirection.Output)) |
| 297 | + { |
| 298 | + continue; |
| 299 | + } |
| 300 | + |
| 301 | + if (first) |
| 302 | + { |
| 303 | + first = false; |
| 304 | + } |
| 305 | + else |
| 306 | + { |
| 307 | + commandStringBuilder.Append(", "); |
| 308 | + } |
| 309 | + SqlGenerationHelper.GenerateParameterNamePlaceholder( |
| 310 | + commandStringBuilder, columnModification.UseOriginalValueParameter |
| 311 | + ? columnModification.OriginalParameterName! |
| 312 | + : columnModification.ParameterName!); |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator); |
| 317 | + requiresTransaction = true; |
| 318 | + return resultSetMapping; |
| 319 | + } |
255 | 320 | }
|
0 commit comments