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

Question: calling stored procedure which returns values #426

Open
Radamonas opened this issue Mar 22, 2023 · 5 comments
Open

Question: calling stored procedure which returns values #426

Radamonas opened this issue Mar 22, 2023 · 5 comments
Assignees
Labels
documentation Documentation may be added or completed on the portal

Comments

@Radamonas
Copy link

Radamonas commented Mar 22, 2023

Reviewed documentation on calling stored procedures and SQL commands, and I would like to know:

  1. is it possible to retrieve and pass further stored procedure output into the pipeline? Based on the documentation: ToSqlCommand always returns the input events as is.;
  2. if script used in ToSqlCommand has variable declarations like:
DECLARE @typeVar Char(1) = 'A';
SELECT * FROM dbo.myTable WHERE type = @typeVar;

How we could use @ within, isn't it reserved for parameter injection from upper stream? Checked the code, and its a bit strange to use @ for params, as @ is used in MS SQL for variable definitions and @@ for system variables as well.

@paillave
Copy link
Owner

paillave commented Mar 22, 2023

This code works for SqlConnection and such. With SqlConnection, Sql Drivers are directly used, so it supports native SQL Server queries, by using variables (they start with a @). Drivers transmit a command providing the value of these variables to Sql Server. SqlServer extensions for ETL.NET observe all the variables that exist in the given query, and set the value from the corresponding property of the payload.

At the moment, this works only for SqlConnection. I am working on OleDb, ODBC and Oracle Connection here: #423. At the end of the day, SQL server extensions will work for nearly anything. The only exception will be for the save operator that won't work for anything else than Sql Server (at least for now)

@paillave paillave self-assigned this Mar 22, 2023
@paillave paillave added the question Further information is requested label Mar 22, 2023
@Radamonas
Copy link
Author

@paillave, thank you.

What about the first part of the question. Is there a way to get output of the stored procedure into output stream if that stored procedure returns anything?

@paillave
Copy link
Owner

@paillave, thank you.

What about the first part of the question. Is there a way to get output of the stored procedure into output stream if that stored procedure returns anything?

Normaly, using SQL server connection, an exec statement should do it from a CrossApplySqlServerQuery operator. It is not the case?

[...]
contextStream
    .CrossApplySqlServerQuery("get people", o => o
        .FromQuery("exec sp_getPeople @value1, @value2")
        .WithMapping(i => new
            {
                Name = i.ToColumn("FirstName"),
                Birthday = i.ToDateColumn("DateOfBirth")
            }));
[...]

@Radamonas
Copy link
Author

Radamonas commented Mar 23, 2023

@paillave thanks for explaining this, I assume this could be as a part of documentation as based on example provided there, it looks like ToSqlCommand is the only way to use it.

I will close this.

@paillave paillave added the documentation Documentation may be added or completed on the portal label Mar 23, 2023
@paillave
Copy link
Owner

I will reopen it as a documentation ticket. Like most of opened ticket here, I will close them once their content is in the documentation.

@paillave paillave reopened this Mar 23, 2023
@paillave paillave removed the question Further information is requested label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation may be added or completed on the portal
Projects
None yet
Development

No branches or pull requests

2 participants