Author: shawkins
Date: 2010-08-02 22:06:18 -0400 (Mon, 02 Aug 2010)
New Revision: 2399
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ConvertModifier.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseConvertModifier.java
Log:
TEIID-1181 fix for sybase complaining that bit is not nullable
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ConvertModifier.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ConvertModifier.java 2010-08-02
19:12:20 UTC (rev 2398)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ConvertModifier.java 2010-08-03
02:06:18 UTC (rev 2399)
@@ -86,6 +86,7 @@
private Map<List<Integer>, FunctionModifier> specificConverts = new
HashMap<List<Integer>, FunctionModifier>();
private boolean booleanNumeric;
private boolean wideningNumericImplicit;
+ private boolean booleanNullable = true;
public void addTypeConversion(FunctionModifier convert, int ... targetType) {
for (int i : targetType) {
@@ -188,6 +189,9 @@
booleanValue = nested.getParameters().get(0);
}
}
+ if (!booleanNullable) {
+ return Arrays.asList("CASE WHEN ", booleanValue, " = 0 THEN
'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
return Arrays.asList("CASE WHEN ", booleanValue, " = 0 THEN
'false' WHEN ", booleanValue, " IS NOT NULL THEN 'true'
END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
});
@@ -199,5 +203,9 @@
}
});
}
+
+ public void setBooleanNullable(boolean booleanNullable) {
+ this.booleanNullable = booleanNullable;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2010-08-02
19:12:20 UTC (rev 2398)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2010-08-03
02:06:18 UTC (rev 2399)
@@ -193,5 +193,10 @@
public boolean nullPlusNonNullIsNull() {
return true;
}
+
+ @Override
+ public boolean booleanNullable() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2010-08-02
19:12:20 UTC (rev 2398)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2010-08-03
02:06:18 UTC (rev 2399)
@@ -94,6 +94,7 @@
//add in type conversion
ConvertModifier convertModifier = new ConvertModifier();
+ convertModifier.setBooleanNullable(booleanNullable());
//boolean isn't treated as bit, since it doesn't support null
//byte is treated as smallint, since tinyint is unsigned
convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE,
FunctionModifier.SHORT); //$NON-NLS-1$
@@ -327,4 +328,8 @@
public boolean nullPlusNonNullIsNull() {
return false;
}
+
+ public boolean booleanNullable() {
+ return false;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseConvertModifier.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseConvertModifier.java 2010-08-02
19:12:20 UTC (rev 2398)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseConvertModifier.java 2010-08-03
02:06:18 UTC (rev 2399)
@@ -174,7 +174,7 @@
LANG_FACTORY.createLiteral("string", String.class)},
//$NON-NLS-1$
String.class);
- helpGetString1(func, "CASE WHEN 1 = 0 THEN 'false' WHEN 1 IS NOT
NULL THEN 'true' END"); //$NON-NLS-1$
+ helpGetString1(func, "CASE WHEN 1 = 0 THEN 'false' ELSE
'true' END"); //$NON-NLS-1$
}
@Test public void testTimestampToString() throws Exception {
@@ -749,7 +749,7 @@
// Source = BOOLEAN
@Test public void testBooleanToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"string", "CASE WHEN 1 = 0 THEN 'false' WHEN 1 IS NOT NULL THEN
'true' END"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpTest(LANG_FACTORY.createLiteral(Boolean.TRUE, Boolean.class),
"string", "CASE WHEN 1 = 0 THEN 'false' ELSE 'true'
END"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testBooleanToByte() throws Exception {
Show replies by date