Permalink
Browse files

[jdbc-driver] Fix parameter definition for null decimal/numeric (1.0.…

…16-2)
  • Loading branch information...
cchantep
cchantep committed Mar 15, 2014
1 parent f6c3145 commit a0122044eb1125fe66899582c1eb1df617cf8351
@@ -212,39 +212,29 @@ public static ParameterDef Null(final int sqlType) {
} // end of Null
/**
- * Boolean constructor.
+ * Boolean definition
*/
- public static ParameterDef Bool() {
- return Default(Types.BOOLEAN);
- } // end of Bool
+ public static final ParameterDef Bool = Default(Types.BOOLEAN);
/**
- * Byte constructor.
+ * Byte definition
*/
- public static ParameterDef Byte() {
- return Default(Types.TINYINT);
- } // end of Byte
+ public static final ParameterDef Byte = Default(Types.TINYINT);
/**
- * Short constructor.
+ * Short definition
*/
- public static ParameterDef Short() {
- return Default(Types.SMALLINT);
- } // end of Short
+ public static final ParameterDef Short = Default(Types.SMALLINT);
/**
- * Integer constructor.
+ * Integer definition
*/
- public static ParameterDef Int() {
- return Default(Types.INTEGER);
- } // end of Int
+ public static final ParameterDef Int = Default(Types.INTEGER);
/**
- * Long constructor.
+ * Long definition
*/
- public static ParameterDef Long() {
- return Default(Types.BIGINT);
- } // end of Long
+ public static final ParameterDef Long = Default(Types.BIGINT);
/**
* Float constructor.
@@ -274,12 +264,22 @@ public static ParameterDef Double(final double d) {
return Scaled(Types.DOUBLE, bd.scale());
} // end of Double
+ /**
+ * Numeric with default scale.
+ */
+ public static final ParameterDef Numeric = Default(Types.NUMERIC);
+
/**
* BigDecimal constructor.
*/
public static ParameterDef Numeric(final BigDecimal bd) {
return Scaled(Types.NUMERIC, bd.scale());
- } // end of BigDecimal
+ } // end of Numeric
+
+ /**
+ * Decimal with default scale.
+ */
+ public static final ParameterDef Decimal = Default(Types.DECIMAL);
/**
* BigDecimal constructor (as DECIMAL).
@@ -289,32 +289,24 @@ public static ParameterDef Decimal(final BigDecimal bd) {
} // end of Decimal
/**
- * String constructor.
+ * String definition
*/
- public static ParameterDef Str() {
- return Default(Types.VARCHAR);
- } // end of Str
+ public static final ParameterDef Str = Default(Types.VARCHAR);
/**
- * Date constructor.
+ * Date definition
*/
- public static ParameterDef Date() {
- return Default(Types.DATE);
- } // end of Date
+ public static final ParameterDef Date = Default(Types.DATE);
/**
- * Time constructor.
+ * Time definition
*/
- public static ParameterDef Time() {
- return Default(Types.TIME);
- } // end of Time
+ public static final ParameterDef Time = Default(Types.TIME);
/**
- * Timestamp constructor.
+ * Timestamp definition
*/
- public static ParameterDef Timestamp() {
- return Default(Types.TIMESTAMP);
- } // end of Timestamp
+ public static final ParameterDef Timestamp = Default(Types.TIMESTAMP);
// --- Inner classes ---
@@ -251,7 +251,7 @@ public void setNull(final int parameterIndex,
public void setBoolean(final int parameterIndex,
final boolean x) throws SQLException {
- setParam(parameterIndex, Bool(), (Object)x);
+ setParam(parameterIndex, Bool, x);
} // end of setBoolean
/**
@@ -260,7 +260,7 @@ public void setBoolean(final int parameterIndex,
public void setByte(final int parameterIndex,
final byte x) throws SQLException {
- setParam(parameterIndex, Byte(), (Object)x);
+ setParam(parameterIndex, Byte, x);
} // end of setByte
/**
@@ -269,7 +269,7 @@ public void setByte(final int parameterIndex,
public void setShort(final int parameterIndex,
final short x) throws SQLException {
- setParam(parameterIndex, Short(), (Object)x);
+ setParam(parameterIndex, Short, x);
} // end of setShort
/**
@@ -278,7 +278,7 @@ public void setShort(final int parameterIndex,
public void setInt(final int parameterIndex,
final int x) throws SQLException {
- setParam(parameterIndex, Int(), (Object)x);
+ setParam(parameterIndex, Int, x);
} // end of setInt
/**
@@ -287,7 +287,7 @@ public void setInt(final int parameterIndex,
public void setLong(final int parameterIndex,
final long x) throws SQLException {
- setParam(parameterIndex, Long(), (Object)x);
+ setParam(parameterIndex, Long, x);
} // end of setLong
/**
@@ -296,7 +296,7 @@ public void setLong(final int parameterIndex,
public void setFloat(final int parameterIndex,
final float x) throws SQLException {
- setParam(parameterIndex, Float(x), (Object)x);
+ setParam(parameterIndex, Float(x), x);
} // end of setFloat
/**
@@ -305,7 +305,7 @@ public void setFloat(final int parameterIndex,
public void setDouble(final int parameterIndex,
final double x) throws SQLException {
- setParam(parameterIndex, Double(x), (Object)x);
+ setParam(parameterIndex, Double(x), x);
} // end of setDouble
/**
@@ -314,7 +314,9 @@ public void setDouble(final int parameterIndex,
public void setBigDecimal(final int parameterIndex,
final BigDecimal x) throws SQLException {
- setParam(parameterIndex, Numeric(x), (Object)x);
+ final ParameterDef def = (x == null) ? Numeric : Numeric(x);
+
+ setParam(parameterIndex, def, x);
} // end of setBigDecimal
/**
@@ -323,7 +325,7 @@ public void setBigDecimal(final int parameterIndex,
public void setString(final int parameterIndex,
final String x) throws SQLException {
- setParam(parameterIndex, Str(), (Object)x);
+ setParam(parameterIndex, Str, x);
} // end of setString
/**
@@ -587,7 +589,7 @@ public ResultSetMetaData getMetaData() throws SQLException {
public void setDate(final int parameterIndex,
final Date x) throws SQLException {
- setParam(parameterIndex, Date(), (Object)x);
+ setParam(parameterIndex, Date, x);
} // end of setDate
/**
@@ -597,7 +599,7 @@ public void setDate(final int parameterIndex,
final Date x,
final Calendar cal) throws SQLException {
- setParam(parameterIndex, Date(),
+ setParam(parameterIndex, Date,
(Object)ImmutablePair.of(x, cal.getTimeZone()));
} // end of setDate
@@ -608,7 +610,7 @@ public void setDate(final int parameterIndex,
public void setTime(final int parameterIndex,
final Time x) throws SQLException {
- setParam(parameterIndex, Time(), (Object)x);
+ setParam(parameterIndex, Time, x);
} // end of setTime
/**
@@ -618,7 +620,7 @@ public void setTime(final int parameterIndex,
final Time x,
final Calendar cal) throws SQLException {
- setParam(parameterIndex, Time(),
+ setParam(parameterIndex, Time,
(Object)ImmutablePair.of(x, cal.getTimeZone()));
} // end of setTime
@@ -629,7 +631,7 @@ public void setTime(final int parameterIndex,
public void setTimestamp(final int parameterIndex, final Timestamp x)
throws SQLException {
- setParam(parameterIndex, Timestamp(), (Object)x);
+ setParam(parameterIndex, Timestamp, x);
} // end of setTimestamp
/**
@@ -640,7 +642,7 @@ public void setTimestamp(final int parameterIndex,
final Calendar cal)
throws SQLException {
- setParam(parameterIndex, Timestamp(),
+ setParam(parameterIndex, Timestamp,
(Object)ImmutablePair.of(x, cal.getTimeZone()));
} // end of setTimestamp
@@ -925,7 +927,9 @@ public void setNClob(final int parameterIndex, final Reader x)
void setDecimal(final int parameterIndex,
final BigDecimal x) throws SQLException {
- setParam(parameterIndex, Decimal(x), (Object)x);
+ final ParameterDef def = (x == null) ? Decimal : Decimal(x);
+
+ setParam(parameterIndex, def, x);
} // end of setBigDecimal
/**
@@ -934,7 +938,7 @@ void setDecimal(final int parameterIndex,
public void setReal(final int parameterIndex,
final float x) throws SQLException {
- setParam(parameterIndex, Real(x), (Object)x);
+ setParam(parameterIndex, Real(x), x);
} // end of setReal
// ---
@@ -841,6 +841,26 @@ trait StatementSpecification[S <: PreparedStatement] extends Setters {
aka("SQL query") mustEqual ("SELECT ? WHERE false" -> d2))
}
+
+ "be null NUMERIC" in {
+ lazy val s = statement()
+ s.setBigDecimal(1, null.asInstanceOf[java.math.BigDecimal])
+
+ lazy val m = s.getParameterMetaData
+
+ (m.getParameterCount aka "count" mustEqual 1).
+ and(m.getParameterType(1) aka "SQL type" mustEqual Types.NUMERIC)
+ }
+
+ "be null DECIMAL" in {
+ lazy val s = statement()
+ s.setDecimal(1, null.asInstanceOf[java.math.BigDecimal])
+
+ lazy val m = s.getParameterMetaData
+
+ (m.getParameterCount aka "count" mustEqual 1).
+ and(m.getParameterType(1) aka "SQL type" mustEqual Types.DECIMAL)
+ }
}
"String" should {
View
@@ -9,7 +9,7 @@ object Acolyte extends Build with Dependencies
aggregate(jdbcDriver, scalacPlugin, jdbcScala, studio).
settings(
organization in ThisBuild := "org.eu.acolyte",
- version in ThisBuild := "1.0.16-1",
+ version in ThisBuild := "1.0.16-2",
javaOptions in ThisBuild ++= Seq("-source", "1.6", "-target", "1.6"),
scalaVersion in ThisBuild := "2.10.3",
publishTo in ThisBuild := Some(Resolver.file("file",

0 comments on commit a012204

Please sign in to comment.