DATACOUCH-532 - Use parameters in queries instead of literals.

This will allow query plans to be reused for different parameters.
This commit is contained in:
mikereiche
2020-06-25 16:58:12 -07:00
parent 5cd916bea4
commit ecaf58db75
2 changed files with 24 additions and 1 deletions

View File

@@ -248,7 +248,7 @@ public class Query {
final StringBuilder statement = new StringBuilder();
appendString(statement, n1ql.selectEntity); // select ...
appendWhereString(statement, n1ql.filter); // typeKey = typeValue
appendWhere(statement, null); // criteria on this Query
appendWhere(statement, new int[] { 0 }); // criteria on this Query
appendSort(statement);
appendSkipAndLimit(statement);
return statement.toString();

View File

@@ -83,6 +83,29 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
}
}
// "1\" or name=name or name=\"1")
@Test
void findByInjection() {
Airport vie = null;
Airport xxx = null;
try {
vie = new Airport("airports::vie", "vie", "loww");
airportRepository.save(vie);
xxx = new Airport("airports::xxx", "xxx", "xxxx");
airportRepository.save(xxx);
sleep(1000);
List<Airport> airports;
airports = airportRepository.findAllByIata("1\" or iata=iata or iata=\"1");
assertEquals(0, airports.size());
airports = airportRepository.findAllByIata("vie");
assertEquals(1, airports.size());
} finally {
airportRepository.delete(vie);
airportRepository.delete(xxx);
}
}
@Test
void findBySimpleProperty() {
Airport vie = null;