From 86bd663460b5863ca725cdb471b68a1979224660 Mon Sep 17 00:00:00 2001 From: Luca Rota Date: Wed, 27 Nov 2024 16:57:40 +0100 Subject: [PATCH] Fix query with boolean value (needs JSQLParser 5.1-SNAPSHOT until the release of version 5.1) --- pom.xml | 23 +++++++++++++++---- .../processor/utils/ValueToStringVisitor.java | 15 ++++++++---- .../jdbc/salesforce/utils/Constants.java | 2 +- .../processor/UpdateQueryAnalyzerTest.java | 21 +++++++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 459e04a..9530069 100644 --- a/pom.xml +++ b/pom.xml @@ -33,14 +33,14 @@ 17 17 UTF-8 - 1.6.12-release + 1.6.13-release 61.1.0 1.18.30 2.0.7 3.12.0 - 5.0 + 5.1-SNAPSHOT 3.10.8 5.9.3 5.7.0 @@ -54,8 +54,17 @@ 3.3.0 3.6.0 3.1.1 + 1.9.3 - + + + jsqlparser-snapshots + + true + + https://oss.sonatype.org/content/groups/public/ + + org.projectlombok @@ -133,6 +142,12 @@ ${slf4j.version} test + + org.junit.platform + junit-platform-launcher + ${unit-platform-launcher.version} + test + @@ -194,7 +209,7 @@ single-jar - 1.6.12-fatjar-release + 1.6.13-fatjar-release diff --git a/src/main/java/com/ascendix/jdbc/salesforce/statement/processor/utils/ValueToStringVisitor.java b/src/main/java/com/ascendix/jdbc/salesforce/statement/processor/utils/ValueToStringVisitor.java index 76d9cb0..06aa3e0 100644 --- a/src/main/java/com/ascendix/jdbc/salesforce/statement/processor/utils/ValueToStringVisitor.java +++ b/src/main/java/com/ascendix/jdbc/salesforce/statement/processor/utils/ValueToStringVisitor.java @@ -39,23 +39,30 @@ public Expression visit(NullValue nullValue, S context) { return null; } + @Override + public Expression visit(BooleanValue booleanValue, S context) { + log.trace("[VtoSVisitor] DoubleValue {}={}", columnName, booleanValue.getValue()); + fieldValues.put(columnName, booleanValue.getValue()); + return null; + } + @Override public Expression visit(DoubleValue doubleValue, S context) { - log.warn("[VtoSVisitor] DoubleValue {}={}", columnName, doubleValue.getValue()); + log.trace("[VtoSVisitor] DoubleValue {}={}", columnName, doubleValue.getValue()); fieldValues.put(columnName, doubleValue.getValue()); return null; } @Override public Expression visit(LongValue longValue, S context) { - log.warn("[VtoSVisitor] LongValue {}={}", columnName, longValue.getValue()); + log.trace("[VtoSVisitor] LongValue {}={}", columnName, longValue.getValue()); fieldValues.put(columnName, longValue.getValue()); return null; } @Override public Expression visit(HexValue hexValue, S context) { - log.warn("[VtoSVisitor] HexValue {}={}", columnName, hexValue.getValue()); + log.trace("[VtoSVisitor] HexValue {}={}", columnName, hexValue.getValue()); fieldValues.put(columnName, hexValue.getValue()); return null; } @@ -72,7 +79,7 @@ public Expression visit(Select subSelect, S context) { Object value = null; PlainSelect plainSelect = subSelect.getPlainSelect(); if (plainSelect != null) { - log.trace("[VtoxSVisitor] SubSelect {}={}", columnName, plainSelect); + log.trace("[VtoSVisitor] SubSelect {}={}", columnName, plainSelect); if (subSelectResolver != null) { List> records = subSelectResolver.apply(plainSelect.toString(), parameters); if (records.size() == 1 && records.get(0).size() == 1) { diff --git a/src/main/java/com/ascendix/jdbc/salesforce/utils/Constants.java b/src/main/java/com/ascendix/jdbc/salesforce/utils/Constants.java index 8731b7e..bbf291a 100644 --- a/src/main/java/com/ascendix/jdbc/salesforce/utils/Constants.java +++ b/src/main/java/com/ascendix/jdbc/salesforce/utils/Constants.java @@ -7,7 +7,7 @@ private Constants() { public static final int DRIVER_MAJOR_VER = 1; public static final int DRIVER_MINOR_VER = 6; - public static final int DRIVER_REVISION_VER = 12; + public static final int DRIVER_REVISION_VER = 13; public static final String DRIVER_VERSION = DRIVER_MAJOR_VER + "." + DRIVER_MINOR_VER + "." + DRIVER_REVISION_VER; diff --git a/src/test/java/com/ascendix/jdbc/salesforce/statement/processor/UpdateQueryAnalyzerTest.java b/src/test/java/com/ascendix/jdbc/salesforce/statement/processor/UpdateQueryAnalyzerTest.java index 17d20df..41ac9a7 100644 --- a/src/test/java/com/ascendix/jdbc/salesforce/statement/processor/UpdateQueryAnalyzerTest.java +++ b/src/test/java/com/ascendix/jdbc/salesforce/statement/processor/UpdateQueryAnalyzerTest.java @@ -1,6 +1,7 @@ package com.ascendix.jdbc.salesforce.statement.processor; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -261,4 +262,24 @@ void testProcessUpdate_One_All() { assertEquals("FirstAccount_new", rec.get("Name")); assertEquals("005xx1111111111111", rec.get("Id")); } + + @Test + void testProcessUpdate_Boolean_ById() { + String soql = "Update Account set Name ='FirstAccount_new', IsDeleted=true where Id='001xx000003GeY0AAK'"; + final QueryAnalyzer queryAnalyzer = new QueryAnalyzer(soql, null, null); + UpdateQueryAnalyzer analyzer = new UpdateQueryAnalyzer(queryAnalyzer); + + assertEquals("Account", analyzer.getFromObjectName()); + + // Verify we have exactly one rec to save + assertEquals(1, analyzer.getRecords(List.of()).size()); + Map rec = analyzer.getRecords(List.of()).get(0); + // Verify the fields count for the first rec + assertEquals(3, rec.size()); + // Verify the fields' names for the first rec + assertEquals(Set.of("IsDeleted", "Name", "Id"), rec.keySet()); + assertEquals("FirstAccount_new", rec.get("Name")); + assertTrue((Boolean) rec.get("IsDeleted")); + assertEquals("001xx000003GeY0AAK", rec.get("Id")); + } }