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
4 changes: 2 additions & 2 deletions src/main/scala/net/noerd/prequel/Formattables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Nullable( val value: Option[ Formattable ] ) extends Formattable {
value.map( _.escaped( formatter ) ).getOrElse( "null" )
}
override def addTo( statement: ReusableStatement ): Unit = {
statement.addNull
value.map(statement << _).getOrElse(statement.addNull)
}
}
object Nullable {
Expand Down Expand Up @@ -184,4 +184,4 @@ class BinaryFormattable( val value: Array[Byte] ) extends Formattable {
}
object BinaryFormattable{
def apply( value: Array[Byte] ) = new BinaryFormattable( value )
}
}
26 changes: 25 additions & 1 deletion src/test/scala/net/noerd/prequel/TransactionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,31 @@ class TransactionSpec extends FunSpec with ShouldMatchers with BeforeAndAfterEac
difference should be > (1.0)
}
}

it( "should handle nullable columns correctly" ) {
case class Item( v1: Long, v2: Option[String] )

val items = List( Item( 1001, Some( "foo" ) ), Item( 1002, None ) )
val strNullable = (x:Option[String]) => Nullable(x.map(StringFormattable(_)))

database.transaction { tx =>
tx.executeBatch( "insert into transactionspec values(?, ?)" ) { statement =>
items.foreach { item =>
statement << item.v1 << Nullable(item.v2.map(StringFormattable(_))) <<!
}
}
}

database.transaction { tx =>
val rs = tx.select( "select id, name from transactionspec where id > 1000" ) { row =>
Item( row, row )
}

rs should contain (items.head)
rs should contain (items.last)
}
}

}
}
}
}