|
|
|
|
@@ -16,7 +16,7 @@ Mono<Void> completion = client.execute("CREATE TABLE person (id VARCHAR(255) PRI
|
|
|
|
|
It exposes intermediate, continuation, and terminal methods at each stage of the execution specification.
|
|
|
|
|
The preceding example above uses `then()` to return a completion `Publisher` that completes as soon as the query (or queries, if the SQL query contains multiple statements) completes.
|
|
|
|
|
|
|
|
|
|
NOTE: `execute(…)` accepts either the SQL query string or a query `Supplier<String>` to defer the actual query creation until execution.
|
|
|
|
|
NOTE: `execute(…)` accepts either the SQL query string or a query `Supplier<String>` to defer the actual query creation until the query is sent to the database.
|
|
|
|
|
|
|
|
|
|
[[r2dbc.datbaseclient.queries]]
|
|
|
|
|
== Running Queries
|
|
|
|
|
@@ -104,7 +104,7 @@ These are typically `SELECT` statements constrained by a `WHERE` clause or `INSE
|
|
|
|
|
Parameterized statements bear the risk of SQL injection if parameters are not escaped properly.
|
|
|
|
|
`DatabaseClient` leverages R2DBC's `bind` API to eliminate the risk of SQL injection for query parameters.
|
|
|
|
|
You can provide a parameterized SQL statement with the `execute(…)` operator and bind parameters to the actual `Statement`.
|
|
|
|
|
Your R2DBC driver then executes the statement by using prepared statements and parameter substitution.
|
|
|
|
|
Your R2DBC driver then runs the statement by using prepared statements and parameter substitution.
|
|
|
|
|
|
|
|
|
|
Parameter binding supports two binding strategies:
|
|
|
|
|
|
|
|
|
|
@@ -130,11 +130,11 @@ As an example, Postgres uses indexed markers, such as `$1`, `$2`, `$n`.
|
|
|
|
|
Another example is SQL Server, which uses named bind markers prefixed with `@`.
|
|
|
|
|
|
|
|
|
|
This is different from JDBC, which requires `?` as bind markers.
|
|
|
|
|
In JDBC, the actual drivers translate `?` bind markers to database-native markers as part of their statement execution.
|
|
|
|
|
In JDBC, the actual drivers translate `?` bind markers to database-native markers as part of processing the statement.
|
|
|
|
|
|
|
|
|
|
Spring Data R2DBC lets you use native bind markers or named bind markers with the `:name` syntax.
|
|
|
|
|
|
|
|
|
|
Named parameter support leverages a `R2dbcDialect` instance to expand named parameters to native bind markers at the time of query execution, which gives you a certain degree of query portability across various database vendors.
|
|
|
|
|
Named parameter support uses a `R2dbcDialect` instance to expand named parameters to native bind markers at the time of running the query, which gives you a certain degree of query portability across various database vendors.
|
|
|
|
|
****
|
|
|
|
|
|
|
|
|
|
The query-preprocessor unrolls named `Collection` parameters into a series of bind markers to remove the need of dynamic query creation based on the number of arguments.
|
|
|
|
|
@@ -149,7 +149,7 @@ SELECT id, name, state FROM table WHERE (name, age) IN (('John', 35), ('Ann', 50
|
|
|
|
|
----
|
|
|
|
|
====
|
|
|
|
|
|
|
|
|
|
The preceding query can be parametrized and executed as follows:
|
|
|
|
|
The preceding query can be parametrized and run as follows:
|
|
|
|
|
|
|
|
|
|
====
|
|
|
|
|
[source,java]
|
|
|
|
|
@@ -178,7 +178,7 @@ db.execute("SELECT id, name, state FROM table WHERE age IN (:ages)")
|
|
|
|
|
[[r2dbc.datbaseclient.filter]]
|
|
|
|
|
== Statement Filters
|
|
|
|
|
|
|
|
|
|
You can register a `Statement` filter (`StatementFilterFunction`) through `DatabaseClient` to intercept and modify statements in their execution, as the following example shows:
|
|
|
|
|
You can register a `Statement` filter (`StatementFilterFunction`) through `DatabaseClient` to intercept and modify statements when they run, as the following example shows:
|
|
|
|
|
|
|
|
|
|
====
|
|
|
|
|
[source,java]
|
|
|
|
|
@@ -205,4 +205,4 @@ db.execute("SELECT id, name, state FROM table")
|
|
|
|
|
----
|
|
|
|
|
====
|
|
|
|
|
|
|
|
|
|
`StatementFilterFunction` allow filtering of the executed `Statement` and filtering of `Result` objects.
|
|
|
|
|
`StatementFilterFunction` allows filtering of the `Statement` and filtering of the `Result` objects.
|
|
|
|
|
|