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

Parameter binding in Batch #99

Open
dmitry-s opened this issue Jun 5, 2019 · 7 comments
Open

Parameter binding in Batch #99

dmitry-s opened this issue Jun 5, 2019 · 7 comments
Labels
status: need-more-implementations An enhancement that requires more implementations to be included type: enhancement A general enhancement

Comments

@dmitry-s
Copy link

dmitry-s commented Jun 5, 2019

In the current implementation Batch.add(...) method only accepts String sql parameter. Is there a way to bind parameters?
It probably would make sense to make add(...) method accept Statement instead of String.

@mp911de
Copy link
Member

mp911de commented Jun 5, 2019

Batch is intended for unparametrized statements. Statement.add() is intended for parametrized statement batching.

@dmitry-s
Copy link
Author

dmitry-s commented Jun 5, 2019

Statement.add() is only useful if there is one statement and multiple sets of parameters. But if we have multiple statements and each of them has multiple parameter sets - I think that would be good use case for Batch.
Also, even if you have only one set of parameters wouldn't it make sense to bind them instead of having to embed them into the actual sql statement string (and doing all type conversions and escaping manually)?

@mp911de
Copy link
Member

mp911de commented Jun 5, 2019

That’s not how databases work. Database protocols (At least Postgres and SQL Server) provide typically a method to run a batch or a single parametrized statement. Running different parameterized statements needs to happen in multiple roundtrips.

IIRC, Postgres also allows sending the SQL and a table of parameters in a single roundtrip. Combining multiple statements basically would just shortcut multiple Statement executions. So we would create an expectation of running multiple statements in a single go without having implementations that are capable of such a feature.

@dmitry-s
Copy link
Author

dmitry-s commented Jun 5, 2019

That's actually how Spanner works, so I assumed it would make sense for other databases as well.

@ChengyuanZhao
Copy link

Mark, I see what you're saying about Postgres and SQL Server and indeed we're seeing a lot of specialization in the SPI around those traditional servers. We are just trying to see if there is flexibility to support these newer SQL servers like Spanner.

@mp911de
Copy link
Member

mp911de commented Jun 6, 2019

lot of specialization in the SPI around those traditional servers

R2DBC was built with traditional SQL databases in mind. R2DBC SPI isn't frozen. It stands for a standard SPI that should be backed by a sufficient number of implementations that find a particular feature useful. If we get 3 or more implementations that natively support that feature, we can include it into SPI. It does not make sense to call a feature standard when it's only implemented by a single database.

We are just trying to see if there is flexibility to support these newer SQL servers like Spanner.

R2DBC SPI is intended to expose standard functionality through a standard SPI where functionality can be broadly consumed by clients. If you want to provide additional functionality in addition to what R2DBC exposes, then adding these features in your classes is the best way how to expose these.

When working with JDBC, it's quite common to obtain a specific interface (see Postgres, Oracle, MySQL) of the driver and then working with that interface directly.

TL;DR: Just because a feature isn't exposed in R2DBC SPI, this does not mean that it's discouraged or should not be implemented.

That being said, let's keep this ticket open and revisit it at a later time when more implementations pick up R2DCBC.

@mp911de mp911de added status: need-more-implementations An enhancement that requires more implementations to be included type: enhancement A general enhancement labels Jun 6, 2019
@mirromutth
Copy link
Contributor

... (At least Postgres and SQL Server) ... Running different parameterized statements needs to happen in multiple roundtrips.

MySQL is also needs to happen in multiple roundtrips when running different prepared statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: need-more-implementations An enhancement that requires more implementations to be included type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants