Skip to content

Commit ecaf58d

Browse files
committed
DATACOUCH-532 - Use parameters in queries instead of literals.
This will allow query plans to be reused for different parameters.
1 parent 5cd916b commit ecaf58d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/org/springframework/data/couchbase/core/query/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public String toN1qlString(ReactiveCouchbaseTemplate template, Class domainClass
248248
final StringBuilder statement = new StringBuilder();
249249
appendString(statement, n1ql.selectEntity); // select ...
250250
appendWhereString(statement, n1ql.filter); // typeKey = typeValue
251-
appendWhere(statement, null); // criteria on this Query
251+
appendWhere(statement, new int[] { 0 }); // criteria on this Query
252252
appendSort(statement);
253253
appendSkipAndLimit(statement);
254254
return statement.toString();

src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ void shouldSaveAndFindAll() {
8383
}
8484
}
8585

86+
// "1\" or name=name or name=\"1")
87+
@Test
88+
void findByInjection() {
89+
Airport vie = null;
90+
Airport xxx = null;
91+
try {
92+
vie = new Airport("airports::vie", "vie", "loww");
93+
airportRepository.save(vie);
94+
xxx = new Airport("airports::xxx", "xxx", "xxxx");
95+
airportRepository.save(xxx);
96+
sleep(1000);
97+
List<Airport> airports;
98+
airports = airportRepository.findAllByIata("1\" or iata=iata or iata=\"1");
99+
assertEquals(0, airports.size());
100+
airports = airportRepository.findAllByIata("vie");
101+
assertEquals(1, airports.size());
102+
} finally {
103+
airportRepository.delete(vie);
104+
airportRepository.delete(xxx);
105+
}
106+
107+
}
108+
86109
@Test
87110
void findBySimpleProperty() {
88111
Airport vie = null;

0 commit comments

Comments
 (0)