Permalink
Browse files

MySQL smallint type should map to scala Int

  • Loading branch information...
trevorsibanda committed May 27, 2017
1 parent 3e7b771 commit e04e93f4b5a5e583c7752642e16a604b03eca877
@@ -1,3 +1,3 @@
CREATE TABLE `LongTextTest`( entry1 LONGTEXT NOT NULL , entry2 MEDIUMTEXT NOT NULL , entry3 TEXT NOT NULL , entry4 VARCHAR(255) NOT NULL );
CREATE TABLE DEFAULT_NUMERIC( d0 decimal(13,2) NOT NULL DEFAULT '0.00',d1 decimal(13) NOT NULL DEFAULT 0.00, d3 INT NOT NULL DEFAULT '0.00' );
CREATE TABLE `table_name`( id INT NOT NULL );
CREATE TABLE `table_name`( id INT NOT NULL, si SMALLINT NOT NULL, mi MEDIUMINT NOT NULL, bi BIGINT NOT NULL );
@@ -170,14 +170,19 @@ val SimpleA = CustomTyping.SimpleA
"""
| val entry = DefaultNumericRow(d0 = scala.math.BigDecimal(123.45), d1 = scala.math.BigDecimal(90), d3 = 0)
| val createStmt = schema.create.statements.mkString
| assertTrue("Schema name should be `slick_test`" , TableName.baseTableRow.schemaName.getOrElse("") == "slick_test" )
| assertTrue(createStmt contains "`entry1` LONGTEXT")
| assertTrue(createStmt contains "`entry2` MEDIUMTEXT")
| assertTrue(createStmt contains "`entry3` TEXT")
| assertTrue(createStmt contains "`entry4` VARCHAR(255)")
| def assertType(r: Rep[_], t: String) = assert(r.toNode.nodeType.toString == s"$t'")
| assertType(TableName.baseTableRow.si, "Int")
| assertType(TableName.baseTableRow.mi, "Int")
| assertType(TableName.baseTableRow.bi, "Long")
| DBIO.seq(
| schema.create,
| TableName += TableNameRow(0),
| TableName.result.map{ case Seq(TableNameRow(id) ) => assertTrue("Schema name should be `slick_test`" , TableName.baseTableRow.schemaName.get eq "slick_test" ) },
| TableName += TableNameRow(0, 0, 0, 0),
| TableName.result.map{ case rows: Seq[TableNameRow] => assert(rows.length == 1) },
| DefaultNumeric += entry,
| DefaultNumeric.result.head.map{ r => assertEquals(r , entry) }
| )
@@ -65,6 +65,7 @@ trait MySQLProfile extends JdbcProfile { profile =>
- SqlCapabilities.sequenceLimited
- RelationalCapabilities.joinFull
- JdbcCapabilities.nullableNoDefault
- JdbcCapabilities.distinguishesIntTypes //https://github.com/slick/slick/pull/1735
)
override protected[this] def loadProfileConfig: Config = {
@@ -102,6 +103,16 @@ trait MySQLProfile extends JdbcProfile { profile =>
override def schema = meta.name.catalog
override def catalog = meta.name.schema
}
//https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-type-conversions.html
import scala.reflect.{ClassTag, classTag}
override def jdbcTypeToScala(jdbcType: Int, typeName: String = ""): ClassTag[_] = {
import java.sql.Types._
jdbcType match{
case SMALLINT => classTag[Int]
case _ => super.jdbcTypeToScala(jdbcType, typeName)
}
}
}
override def createModelBuilder(tables: Seq[MTable], ignoreInvalidDefaults: Boolean)(implicit ec: ExecutionContext): JdbcModelBuilder =

0 comments on commit e04e93f

Please sign in to comment.