[#1028] Syntax errors when using untyped param() in HSQLDB (and other strongly typed dialects)
This commit is contained in:
parent
220ac8c399
commit
9687809b8a
@ -24,6 +24,6 @@
|
||||
<classpathentry exported="true" kind="lib" path="lib/jconn3.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/jtds-1.2.5.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/iijdbc.jar"/>
|
||||
<classpathentry kind="lib" path="lib/h2-1.3.162.jar"/>
|
||||
<classpathentry kind="lib" path="lib/h2-1.3.163.jar" sourcepath="/jOOQ-sources/h2-1.3.163-sources.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -26,7 +26,7 @@
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbynet.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbytools.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/derbyrun.jar" path="3" sourceAttachmentPath="/jOOQ-sources/db-derby-10.8.1.2-src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/h2-1.3.162.jar" path="3" sourceAttachmentPath="/jOOQ-sources/h2-2011-07-17.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/h2-1.3.163.jar" path="3" sourceAttachmentPath="/jOOQ-sources/h2-2011-07-17.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/postgresql-9.0-801.jdbc4.jar" path="3" sourceAttachmentPath="/jOOQ-sources/postgresql-jdbc-9.0-801.src.zip" sourceRootPath="" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/jOOQ-test/lib/log4j-1.2.16.jar" path="3" type="2"/> "/>
|
||||
</listAttribute>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<stringAttribute key="bad_container_name" value="/jOOQ-test/lua"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/jOOQ-test/lib/h2-1.3.162.jar"/>
|
||||
<listEntry value="/jOOQ-test/lib/h2-1.3.163.jar"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
|
||||
Binary file not shown.
@ -9,7 +9,7 @@
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<priority value="debug" />
|
||||
<priority value="trace" />
|
||||
<appender-ref ref="stdout" />
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
@ -6880,7 +6880,6 @@ public abstract class jOOQAbstractTest<
|
||||
assertEquals("ON STOCK", ((EnumType) value).getLiteral());
|
||||
}
|
||||
|
||||
@Test
|
||||
public <R extends TableRecord<R>> void testCustomEnums() throws Exception {
|
||||
reset = false;
|
||||
|
||||
@ -9048,12 +9047,15 @@ public abstract class jOOQAbstractTest<
|
||||
assertEquals("asdf", result2.getValue(1, 1));
|
||||
|
||||
// [#1028] Named params without any associated type information
|
||||
select = create().select(param("p"));
|
||||
// [#1029] TODO Fix this for Postgres!
|
||||
select = create().select(param("p1"), param("p2"));
|
||||
select.bind(1, "10");
|
||||
select.bind(2, null);
|
||||
Result<?> result3 = select.fetch();
|
||||
|
||||
assertEquals(1, result3.size());
|
||||
assertEquals("10", result3.getValue(0, 0));
|
||||
assertEquals(null, result3.getValue(0, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -311,11 +311,13 @@ public abstract class AbstractDataType<T> implements DataType<T> {
|
||||
|
||||
@Override
|
||||
public final String getCastTypeName(Configuration configuration, int precision, int scale) {
|
||||
|
||||
// Remove existing precision / scale information, first
|
||||
String result = getCastTypeName(configuration).replaceAll("\\([^\\)]*\\)", "");
|
||||
String result = getCastTypeName(configuration);
|
||||
|
||||
if (precision != 0) {
|
||||
|
||||
// Remove existing precision / scale information, first
|
||||
result = result.replaceAll("\\([^\\)]*\\)", "");
|
||||
|
||||
if (scale != 0) {
|
||||
result += "(" + precision + ", " + scale + ")";
|
||||
}
|
||||
@ -417,14 +419,7 @@ public abstract class AbstractDataType<T> implements DataType<T> {
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
|
||||
// Object has a default fallback, if it is not registered explicitly
|
||||
if (type == Object.class) {
|
||||
return new DefaultDataType<T>(dialect, (Class<? extends T>) Object.class, "", "");
|
||||
}
|
||||
|
||||
// Default fallback types
|
||||
else if (sqlDataTypesByType.get(type) != null) {
|
||||
if (sqlDataTypesByType.get(type) != null) {
|
||||
return (DataType<T>) sqlDataTypesByType.get(type);
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,10 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Blob;
|
||||
@ -120,12 +124,12 @@ class DefaultBindContext extends AbstractBindContext {
|
||||
|
||||
// [#725] For SQL Server, unknown types should be set to null
|
||||
// explicitly, too
|
||||
else if (configuration.getDialect() == SQLDialect.SQLSERVER) {
|
||||
else if (configuration.getDialect() == SQLSERVER) {
|
||||
stmt.setNull(nextIndex(), sqlType);
|
||||
}
|
||||
|
||||
// [#730] For Sybase, unknown types can be set to null using varchar
|
||||
else if (configuration.getDialect() == SQLDialect.SYBASE) {
|
||||
else if (configuration.getDialect() == SYBASE) {
|
||||
stmt.setNull(nextIndex(), Types.VARCHAR);
|
||||
}
|
||||
|
||||
@ -141,7 +145,7 @@ class DefaultBindContext extends AbstractBindContext {
|
||||
stmt.setBoolean(nextIndex(), (Boolean) value);
|
||||
}
|
||||
else if (type == BigDecimal.class) {
|
||||
if (dialect == SQLDialect.SQLITE) {
|
||||
if (dialect == SQLITE) {
|
||||
stmt.setString(nextIndex(), value.toString());
|
||||
}
|
||||
else {
|
||||
@ -149,7 +153,7 @@ class DefaultBindContext extends AbstractBindContext {
|
||||
}
|
||||
}
|
||||
else if (type == BigInteger.class) {
|
||||
if (dialect == SQLDialect.SQLITE) {
|
||||
if (dialect == SQLITE) {
|
||||
stmt.setString(nextIndex(), value.toString());
|
||||
}
|
||||
else {
|
||||
|
||||
@ -50,7 +50,7 @@ class DefaultDataType<T> extends AbstractDataType<T> {
|
||||
*/
|
||||
private static final long serialVersionUID = -2612295936942892367L;
|
||||
|
||||
protected DefaultDataType(SQLDialect dialect, Class<? extends T> type, String typeName, String castTypeName) {
|
||||
DefaultDataType(SQLDialect dialect, Class<? extends T> type, String typeName, String castTypeName) {
|
||||
super(dialect, null, type, typeName, castTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,13 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
import static org.jooq.SQLDialect.INGRES;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -124,42 +131,49 @@ class Val<T> extends AbstractField<T> implements Param<T> {
|
||||
* Render the bind variable including a cast, if necessary
|
||||
*/
|
||||
private void toSQLCast(RenderContext context) {
|
||||
switch (context.getDialect()) {
|
||||
|
||||
// [#822] Some RDBMS need precision / scale information on BigDecimals
|
||||
case DB2:
|
||||
case DERBY:
|
||||
case HSQLDB: {
|
||||
// [#822] Some RDBMS need precision / scale information on BigDecimals
|
||||
if (getType() == BigDecimal.class && asList(DB2, DERBY, HSQLDB).contains(context.getDialect())) {
|
||||
|
||||
// Add precision / scale on BigDecimals
|
||||
if (getType() == BigDecimal.class) {
|
||||
int scale = ((BigDecimal) getValue()).scale();
|
||||
int precision = scale + ((BigDecimal) getValue()).precision();
|
||||
// Add precision / scale on BigDecimals
|
||||
int scale = ((BigDecimal) getValue()).scale();
|
||||
int precision = scale + ((BigDecimal) getValue()).precision();
|
||||
|
||||
context.sql("cast(")
|
||||
.sql(getBindVariable(context))
|
||||
.sql(" as ")
|
||||
.sql(getDataType(context).getCastTypeName(context, precision, scale))
|
||||
.sql(")");
|
||||
break;
|
||||
}
|
||||
toSQLCast(context, getDataType(context), precision, scale);
|
||||
}
|
||||
|
||||
// No break, fall through
|
||||
else {
|
||||
}
|
||||
// [#1028] Most databases don't know an OTHER type (except H2, HSQLDB).
|
||||
else if (SQLDataType.OTHER == getDataType(context)) {
|
||||
|
||||
// If the bind value is set, it can be used to derive the cast type
|
||||
if (value != null) {
|
||||
toSQLCast(context, FieldTypeHelper.getDataType(context.getDialect(), value.getClass()), 0, 0);
|
||||
}
|
||||
|
||||
// These dialects don't need precision / scale info on BigDecimals
|
||||
case H2:
|
||||
case INGRES:
|
||||
case SYBASE: {
|
||||
context.sql("cast(")
|
||||
.sql(getBindVariable(context))
|
||||
.sql(" as ")
|
||||
.sql(getDataType(context).getCastTypeName(context))
|
||||
.sql(")");
|
||||
// [#632] [#722] Current integration tests show that Ingres and
|
||||
// Sybase can do without casting in most cases.
|
||||
else if (asList(INGRES, SYBASE).contains(context.getDialect())) {
|
||||
context.sql(getBindVariable(context));
|
||||
}
|
||||
|
||||
// Derby and DB2 must have a type associated with NULL. Use VARCHAR
|
||||
// as a workaround. That's probably not correct in all cases, though
|
||||
else {
|
||||
toSQLCast(context, FieldTypeHelper.getDataType(context.getDialect(), String.class), 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
toSQLCast(context, getDataType(context), 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void toSQLCast(RenderContext context, DataType<?> type, int precision, int scale) {
|
||||
context.sql("cast(")
|
||||
.sql(getBindVariable(context))
|
||||
.sql(" as ")
|
||||
.sql(type.getCastTypeName(context, precision, scale))
|
||||
.sql(")");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user