mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Fix behaviour on Boolean value
This commit is contained in:
parent
33512b4c2b
commit
53daa02e8b
@ -31,8 +31,16 @@ public abstract class AbstractNumberType<T extends Number & Comparable<T>> exten
|
||||
|
||||
@Override
|
||||
public T getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Number num = (Number) rs.getObject(startIndex);
|
||||
return num != null ? MathUtils.cast(num, getReturnedClass()) : null;
|
||||
Object obj = rs.getObject(startIndex);
|
||||
if (obj instanceof Number) {
|
||||
return MathUtils.cast((Number) obj, getReturnedClass());
|
||||
} else if (obj instanceof Boolean) {
|
||||
return MathUtils.cast(Boolean.TRUE.equals(obj) ? 1 : 0, getReturnedClass());
|
||||
} else if (obj != null) {
|
||||
throw new IllegalArgumentException(obj.toString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -669,6 +669,10 @@ public final class Connections {
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// numbers
|
||||
stmt.execute("drop table if exists NUMBER_TEST");
|
||||
stmt.execute("create table NUMBER_TEST(col1 tinyint(1))");
|
||||
|
||||
// xml
|
||||
stmt.execute("drop table if exists XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Target.MYSQL;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.sql.domain.QNumberTest;
|
||||
import com.mysema.query.sql.mysql.MySQLQuery;
|
||||
import com.mysema.testutil.IncludeIn;
|
||||
import org.junit.Test;
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Target.MYSQL;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class SelectMySQLBase extends AbstractBaseTest {
|
||||
@ -30,4 +30,15 @@ public class SelectMySQLBase extends AbstractBaseTest {
|
||||
mysqlQuery().from(survey).straightJoin().list(survey.id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IncludeIn(MYSQL)
|
||||
public void Tinyint() {
|
||||
QNumberTest numberTest = QNumberTest.numberTest;
|
||||
delete(numberTest).execute();
|
||||
insert(numberTest).set(numberTest.col1Boolean, true).execute();
|
||||
insert(numberTest).set(numberTest.col1Number, 1).execute();
|
||||
assertEquals(2, query().from(numberTest).list(numberTest.col1Boolean).size());
|
||||
assertEquals(2, query().from(numberTest).list(numberTest.col1Number).size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
package com.mysema.query.sql.domain;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.mysema.query.sql.ColumnMetadata;
|
||||
import com.mysema.query.sql.spatial.RelationalPathSpatial;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.path.BooleanPath;
|
||||
import com.mysema.query.types.path.NumberPath;
|
||||
import static com.mysema.query.types.PathMetadataFactory.forVariable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* QNumberTest is a Querydsl query type for QNumberTest
|
||||
*/
|
||||
@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
|
||||
public class QNumberTest extends RelationalPathSpatial<QNumberTest> {
|
||||
|
||||
private static final long serialVersionUID = 291758928;
|
||||
|
||||
public static final QNumberTest numberTest = new QNumberTest("NUMBER_TEST");
|
||||
|
||||
public final BooleanPath col1Boolean = createBoolean("col1");
|
||||
|
||||
public final NumberPath col1Number = createNumber("col2", Byte.class);
|
||||
|
||||
public QNumberTest(String variable) {
|
||||
super(QNumberTest.class, forVariable(variable), "null", "NUMBER_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QNumberTest(String variable, String schema, String table) {
|
||||
super(QNumberTest.class, forVariable(variable), schema, table);
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QNumberTest(Path<? extends QNumberTest> path) {
|
||||
super(path.getType(), path.getMetadata(), "null", "NUMBER_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public QNumberTest(PathMetadata<?> metadata) {
|
||||
super(QNumberTest.class, metadata, "null", "NUMBER_TEST");
|
||||
addMetadata();
|
||||
}
|
||||
|
||||
public void addMetadata() {
|
||||
addMetadata(col1Boolean, ColumnMetadata.named("col1").withIndex(1).ofType(Types.BIT));
|
||||
addMetadata(col1Number, ColumnMetadata.named("col1").withIndex(1).ofType(Types.BIT));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user