Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is InsertUsingStoredProcedure, UpdateUsingStoredProcedure, DeleteUsingStoredProcedure in model builder supported? #1158

Open
Camel-RD opened this issue Feb 12, 2024 · 2 comments · May be fixed by #1185

Comments

@Camel-RD
Copy link

When i configure model with InsertUsingStoredProcedure and try to save changes, i get an error:
SQL error code = -104
Token unknown - line 1, column 1
CALL

@Camel-RD
Copy link
Author

Can we fix this issue with this code in FbUpdateSqlGenerator.cs?

	public override ResultSetMapping AppendStoredProcedureCall(
		StringBuilder commandStringBuilder,
		IReadOnlyModificationCommand command,
		int commandPosition,
		out bool requiresTransaction)
	{
		var storedProcedure = command.StoreStoredProcedure;
		var resultSetMapping = ResultSetMapping.NoResults;

		foreach (var resultColumn in storedProcedure.ResultColumns)
		{
			resultSetMapping = ResultSetMapping.LastInResultSet;
			if (resultColumn == command.RowsAffectedColumn)
			{
				resultSetMapping |= ResultSetMapping.ResultSetWithRowsAffectedOnly;
			}
			else
			{
				resultSetMapping = ResultSetMapping.LastInResultSet;
				break;
			}
		}

		commandStringBuilder.Append("EXECUTE PROCEDURE ");
		SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, storedProcedure.Name);

		if (storedProcedure.Parameters.Any())
		{
			commandStringBuilder.AppendLine();
			var first = true;

			for (var i = 0; i < command.ColumnModifications.Count; i++)
			{
				var columnModification = command.ColumnModifications[i];
				if (columnModification.Column is not IStoreStoredProcedureParameter parameter)
				{
					continue;
				}

				if (parameter.Direction.HasFlag(ParameterDirection.Output))
				{
					continue;
				}

				if (first)
				{
					first = false;
				}
				else
				{
					commandStringBuilder.Append(", ");
				}
				SqlGenerationHelper.GenerateParameterNamePlaceholder(
					commandStringBuilder, columnModification.UseOriginalValueParameter
						? columnModification.OriginalParameterName!
						: columnModification.ParameterName!);
			}
		}

		commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator);
		requiresTransaction = true;
		return resultSetMapping;
	}

@cincuranet
Copy link
Member

Can you create PR?

@cincuranet cincuranet linked a pull request Nov 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants