diff --git a/src/main/scala/net/noerd/prequel/ColumnTypes.scala b/src/main/scala/net/noerd/prequel/ColumnTypes.scala index adbee4b..c83ffb8 100644 --- a/src/main/scala/net/noerd/prequel/ColumnTypes.scala +++ b/src/main/scala/net/noerd/prequel/ColumnTypes.scala @@ -102,4 +102,15 @@ class BinaryColumnType( row: ResultSetRow ) extends ColumnType[ Array[Byte] ] { } object BinaryColumnType extends ColumnTypeFactory[ Array[Byte] ] { def apply( row: ResultSetRow ) = new BinaryColumnType( row ) -} \ No newline at end of file +} + +// +// BigDecimal +// + +class BigDecimalColumnType( row: ResultSetRow ) extends ColumnType[ BigDecimal ] { + override def nextValueOption: Option[ BigDecimal ] = row.nextBigDecimal +} +object BigDecimalColumnType extends ColumnTypeFactory[ BigDecimal ] { + def apply( row: ResultSetRow ) = new BigDecimalColumnType( row ) +} diff --git a/src/main/scala/net/noerd/prequel/Formattables.scala b/src/main/scala/net/noerd/prequel/Formattables.scala index 16968f2..5375398 100644 --- a/src/main/scala/net/noerd/prequel/Formattables.scala +++ b/src/main/scala/net/noerd/prequel/Formattables.scala @@ -184,4 +184,22 @@ class BinaryFormattable( val value: Array[Byte] ) extends Formattable { } object BinaryFormattable{ def apply( value: Array[Byte] ) = new BinaryFormattable( value ) -} \ No newline at end of file +} + +// +// BigDecimal +// +class BigDecimalFormattable( val value: BigDecimal ) + extends Formattable { + override def escaped( formatter: SQLFormatter ): String = { + formatter.toSQLString( value.toString() ) + } + override def addTo( statement: ReusableStatement ): Unit = { + statement.addBigDecimal( value ) + } +} +object BigDecimalFormattable{ + def apply( value: BigDecimal ) = { + new BigDecimalFormattable( value ) + } +} diff --git a/src/main/scala/net/noerd/prequel/ResultSetRow.scala b/src/main/scala/net/noerd/prequel/ResultSetRow.scala index 7d34e70..06ce6aa 100644 --- a/src/main/scala/net/noerd/prequel/ResultSetRow.scala +++ b/src/main/scala/net/noerd/prequel/ResultSetRow.scala @@ -29,7 +29,8 @@ class ResultSetRow( val rs: ResultSet ) { def nextDate: Option[ Date ] = nextValueOption( rs.getTimestamp ) def nextObject: Option[ AnyRef ] = nextValueOption( rs.getObject ) def nextBinary: Option[ Array[Byte] ] = nextValueOption( rs.getBytes ) - + def nextBigDecimal: Option[ BigDecimal ] = nextValueOption( i => BigDecimal(rs.getBigDecimal(i)) ) + def columnNames: Seq[ String ]= { val columnNames = ArrayBuffer.empty[ String ] val metaData = rs.getMetaData @@ -86,6 +87,7 @@ object ResultSetRowImplicits { implicit def row2DateTime( row: ResultSetRow ) = DateTimeColumnType( row ).nextValue implicit def row2Duration( row: ResultSetRow ) = DurationColumnType( row ).nextValue implicit def row2Binary( row: ResultSetRow ) = BinaryColumnType( row ).nextValue + implicit def row2BigDecimal( row: ResultSetRow ) = BigDecimalColumnType( row ).nextValue implicit def row2BooleanOption( row: ResultSetRow ) = BooleanColumnType( row ).nextValueOption implicit def row2IntOption( row: ResultSetRow ) = IntColumnType( row ).nextValueOption @@ -97,4 +99,5 @@ object ResultSetRowImplicits { implicit def row2DateTimeOption( row: ResultSetRow ) = DateTimeColumnType( row ).nextValueOption implicit def row2DurationOption( row: ResultSetRow ) = DurationColumnType( row ).nextValueOption implicit def row2BinaryOption( row: ResultSetRow ) = BinaryColumnType( row ).nextValueOption + implicit def row2BigDecimalOption( row: ResultSetRow ) = BigDecimalColumnType( row ).nextValueOption } \ No newline at end of file diff --git a/src/main/scala/net/noerd/prequel/ReusableStatement.scala b/src/main/scala/net/noerd/prequel/ReusableStatement.scala index f6a669b..b4623d3 100644 --- a/src/main/scala/net/noerd/prequel/ReusableStatement.scala +++ b/src/main/scala/net/noerd/prequel/ReusableStatement.scala @@ -18,7 +18,7 @@ import org.joda.time.DateTime * ## Set parameters and execute in on shot * statement.executeWith( param1, param2, param3 ) */ -private class ReusableStatement( val wrapped: PreparedStatement, formatter: SQLFormatter ) { +class ReusableStatement( val wrapped: PreparedStatement, formatter: SQLFormatter ) { private val StartIndex = 1 private var parameterIndex = StartIndex @@ -99,7 +99,12 @@ private class ReusableStatement( val wrapped: PreparedStatement, formatter: SQLF /** * Add a Double to the current parameter index */ - def addDouble( value: Double ): Unit = addValue( wrapped.setDouble( parameterIndex, value ) ) + def addDouble( value: Double ): Unit = addValue( wrapped.setDouble( parameterIndex, value ) ) + + /** + * Add a BigDecimal to the current parameter index + */ + def addBigDecimal( value: BigDecimal ): Unit = addValue( wrapped.setBigDecimal( parameterIndex, value.bigDecimal ) ) /** * Add Null to the current parameter index diff --git a/src/main/scala/net/noerd/prequel/SQLFormatter.scala b/src/main/scala/net/noerd/prequel/SQLFormatter.scala index e86a5d2..a5e865b 100644 --- a/src/main/scala/net/noerd/prequel/SQLFormatter.scala +++ b/src/main/scala/net/noerd/prequel/SQLFormatter.scala @@ -87,4 +87,5 @@ object SQLFormatterImplicits { implicit def date2Formattable( wrapped: Date ) = DateTimeFormattable( wrapped ) implicit def duration2Formattable( wrapped: Duration ) = new DurationFormattable( wrapped ) implicit def binary2Formattable( wrapped: Array[Byte] ) = new BinaryFormattable( wrapped ) + implicit def bigDecimalFormattable( wrapped: BigDecimal ) = new BigDecimalFormattable( wrapped ) } \ No newline at end of file