mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Fix query bugs w/ in-list, empty; format booleans as Yes/No
This commit is contained in:
@ -183,12 +183,32 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
||||
}
|
||||
case IN:
|
||||
{
|
||||
clause += " IN (" + values.stream().map(x -> "?").collect(Collectors.joining(",")) + ") ";
|
||||
if(values.isEmpty())
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// if there are no values, then we want a false here - so say column != column. //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
clause += " != " + column;
|
||||
}
|
||||
else
|
||||
{
|
||||
clause += " IN (" + values.stream().map(x -> "?").collect(Collectors.joining(",")) + ") ";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NOT_IN:
|
||||
{
|
||||
clause += " NOT IN (" + values.stream().map(x -> "?").collect(Collectors.joining(",")) + ") ";
|
||||
if(values.isEmpty())
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// if there are no values, then we want a true here - so say column == column. //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
clause += " = " + column;
|
||||
}
|
||||
else
|
||||
{
|
||||
clause += " NOT IN (" + values.stream().map(x -> "?").collect(Collectors.joining(",")) + ") ";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STARTS_WITH:
|
||||
@ -272,7 +292,7 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
||||
clause += " IS NOT NULL ";
|
||||
if(isString(field.getType()))
|
||||
{
|
||||
clause += " AND " + column + " !+ '' ";
|
||||
clause += " AND " + column + " != '' ";
|
||||
}
|
||||
expectedNoOfParams = 0;
|
||||
break;
|
||||
|
@ -121,7 +121,6 @@ public class RDBMSQueryAction extends AbstractRDBMSAction implements QueryInterf
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
while(resultSet.next())
|
||||
{
|
||||
// todo - Add display values (String labels for possibleValues, formatted #'s, etc)
|
||||
QRecord record = new QRecord();
|
||||
record.setTableName(table.getName());
|
||||
LinkedHashMap<String, Serializable> values = new LinkedHashMap<>();
|
||||
|
@ -375,6 +375,25 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void testIsNotBlankQuery() throws QException
|
||||
{
|
||||
QueryInput queryInput = initQueryRequest();
|
||||
queryInput.setFilter(new QQueryFilter()
|
||||
.withCriteria(new QFilterCriteria()
|
||||
.withFieldName("firstName")
|
||||
.withOperator(QCriteriaOperator.IS_NOT_BLANK)
|
||||
));
|
||||
QueryOutput queryOutput = new RDBMSQueryAction().execute(queryInput);
|
||||
Assertions.assertEquals(5, queryOutput.getRecords().size(), "Expected # of rows");
|
||||
Assertions.assertTrue(queryOutput.getRecords().stream().allMatch(r -> r.getValue("firstName") != null), "Should find expected rows");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -484,4 +503,23 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
transaction.rollback();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testEmptyInList() throws QException
|
||||
{
|
||||
QueryInput queryInput = initQueryRequest();
|
||||
queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria("firstName", QCriteriaOperator.IN, List.of())));
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
Assertions.assertEquals(0, queryOutput.getRecords().size(), "IN empty list should find nothing.");
|
||||
|
||||
queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria("firstName", QCriteriaOperator.NOT_IN, List.of())));
|
||||
queryOutput = new QueryAction().execute(queryInput);
|
||||
Assertions.assertEquals(5, queryOutput.getRecords().size(), "NOT_IN empty list should find everything.");
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user