Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Remove check for unnamed parameters as it falsely triggers on JSON op…
Browse files Browse the repository at this point in the history
…erators such as "?|" or "?".
  • Loading branch information
splitfeed authored and jepp3 committed Sep 23, 2024
1 parent 9d882b9 commit 3e78297
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ private List<QueryPart> createQueryParts(String sqlInput, Method method) throws

sqlInput = sqlPreProcess(sqlInput);

if (sqlInput.indexOf('?') != -1) {
throw new RuntimeException("Unnamed parameters are not supported: " + sqlInput);
}

int pos = 0;
Matcher matcher = NAMED_PARAMETER_PATTERN.matcher(sqlInput);
if (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import java.util.Map;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class ParameterizedQueryTest {

MockDb db = new MockDb();
DbProxy dbProxy = new DbProxy(new DatabaseConfig(), db.getConnectionProvider());
TestDao dao = dbProxy.create(TestDao.class);
Expand Down Expand Up @@ -65,25 +64,21 @@ void shouldResolveParametersWithoutAnnotationFromQuery() throws SQLException {
}

@Test
void shouldThrowExceptionIfUnnamedParamsUsedInQuery() {
try {
dao.unnamedParameters("myid", "myname").blockLast();
fail("Exptected exception");
} catch (Exception e) {
assertThat(e.getMessage())
.isEqualTo("Unnamed parameters are not supported: SELECT * FROM foo WHERE id=? AND name=?");
}
void shouldNotThrowExceptionIfUnnamedParamsUsedInQuery() {
assertThatNoException()
.isThrownBy(() -> dao.unnamedParameters("myid", "myname").blockLast());
}

@Test
void shouldAllowJsonOperators() {
assertThatNoException().isThrownBy(() -> dao.jsonOperators().blockLast());
}

@Test
void shouldThrowExceptionIfNotAllParametersAreFound() {
try {
dao.missingParamName("myid", "myname").blockLast();
fail("Exptected exception");
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo(
"Query contains placeholder \"name\" but method noes not have such argument");
}
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> dao.missingParamName("myid", "myname").blockLast())
.withMessage("Query contains placeholder \"name\" but method noes not have such argument");
}

@Test
Expand Down Expand Up @@ -323,10 +318,11 @@ interface TestDao {
@Query("SELECT x FROM y WHERE z IN (:param)")
Flux<String> inClauseUuid(List<UUID> param);

@Query("SELECT x FROM y WHERE z IN (:param)")
Flux<String> unsupportedArrayType(List<Boolean> param);
@Query("SELECT * FROM message_projections WHERE message_json->'categories' ?| array['newsletter', 'spam']")
Flux<String> jsonOperators();
}

@SuppressWarnings("unused")
public class TestObject {
TestEnum myEnum;
boolean finished;
Expand Down

0 comments on commit 3e78297

Please sign in to comment.