Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0006637 Added support for the BOOLEAN column data type in Derby (Apache DB) #225

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DerbyTriggerTemplate(ISymmetricDialect symmetricDialect) {
clobColumnTemplate = "sym_clob_to_string('\"$(columnName)\"', '$(schemaName)$(tableName)', $(primaryKeyWhereString) )" ;
blobColumnTemplate = "sym_blob_to_string('\"$(columnName)\"', '$(schemaName)$(tableName)', $(primaryKeyWhereString) )" ;
wrappedBlobColumnTemplate = null;
booleanColumnTemplate = null;
booleanColumnTemplate = "case when $(columnName) is null then '' when $(columnName) then '1' else '0' end" ;
triggerConcatCharacter = "||" ;
newTriggerValue = "new" ;
oldTriggerValue = "old" ;
Expand Down Expand Up @@ -150,4 +150,4 @@ protected String getPrimaryKeyWhereString(String alias, Column[] columns) {
b.append("'");
return b.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ protected ColumnString fillOutColumnTemplate(String origTableAlias, String table
templateToUse = adjustColumnTemplate(templateToUse, column.getMappedTypeCode());
templateToUse = templateToUse.trim();
} else {
throw new NotImplementedException("Table " + table + " column " + column);
throw new NotImplementedException(table.toString() + " " + column.toString());
}
String formattedColumnText = FormatUtils.replace("columnSizeOrMax",
trigger.isUseCaptureLobs() ? "max" : "$(columnSize)", templateToUse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected Object getObjectValue(String value, Column column, BinaryEncoding enco
} else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.DOUBLE || type == Types.REAL) {
objectValue = parseBigDecimal(value);
} else if (type == Types.BOOLEAN) {
objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
objectValue = parseBoolean(value);
} else if (!(column.getJdbcTypeName() != null && FormatUtils.upper(column.getJdbcTypeName()).contains(TypeMap.GEOMETRY))
&& !(column.getJdbcTypeName() != null && FormatUtils.upper(column.getJdbcTypeName()).contains(TypeMap.GEOGRAPHY))
&& (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY ||
Expand Down Expand Up @@ -578,6 +578,11 @@ protected Object parseInteger(String value) {
}
}

protected Object parseBoolean(String value) {
value = cleanNumber(value);
return value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
}

protected String cleanNumber(String value) {
value = value.trim();
if (value.equalsIgnoreCase("true")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.SqlTemplateSettings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

public class AbstractDatabasePlatformTest {
@Test
Expand Down Expand Up @@ -80,6 +82,14 @@ public void testParseQualifiedTableName() {
assertEquals(3, testDatabasePlatform.parseQualifiedTableName("\"CATALOG\".\"SCHEMA\".\"TABLE\"").size());
}

@ParameterizedTest
@CsvSource({ "1,true", "true,true", "0,false" })
void testParseBoolean(String textValue, String expectedValue) {
Boolean expectedResult = Boolean.valueOf(expectedValue);
Object result = testDatabasePlatform.parseBoolean(textValue); // null value is not applicable because of check in getObjectValue
assertEquals(expectedResult, result);
}

private AbstractDatabasePlatform testDatabasePlatform = new AbstractDatabasePlatform(new SqlTemplateSettings()) {
@Override
public String getName() {
Expand Down