Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/scala/net/noerd/prequel/ColumnTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
}
}

//
// 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 )
}
20 changes: 19 additions & 1 deletion src/main/scala/net/noerd/prequel/Formattables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,22 @@ class BinaryFormattable( val value: Array[Byte] ) extends Formattable {
}
object BinaryFormattable{
def apply( value: Array[Byte] ) = new BinaryFormattable( value )
}
}

//
// 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 )
}
}
5 changes: 4 additions & 1 deletion src/main/scala/net/noerd/prequel/ResultSetRow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
9 changes: 7 additions & 2 deletions src/main/scala/net/noerd/prequel/ReusableStatement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/net/noerd/prequel/SQLFormatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
}