Permalink
Browse files

issue #1769

Added unsigned integer mapping to Long, following the MySQL connector reference. Added code for unsigned bigint aswell, but scala.math.BigInt isn't support as a default datatype, I left these parts in for completeness, but commented out. Updated the tests for the MySQLProfile to cover the new conversion.

Additionally fixed two typos, I spotted randomly.
  • Loading branch information...
Asamsig committed Sep 2, 2017
1 parent c1520fb commit f732b6c251b51e6a9d26dbbe64ee4f0300414719
@@ -1,4 +1,4 @@
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, si SMALLINT NOT NULL, mi MEDIUMINT NOT NULL, bi BIGINT NOT NULL );
CREATE TABLE `table_name`( id INT NOT NULL, si SMALLINT NOT NULL, mi MEDIUMINT NOT NULL, ui INT UNSIGNED NOT NULL, bi BIGINT NOT NULL/*, ubi BIGINT UNSIGNED NOT NULL*/ );
CREATE TABLE `bit_test`(b1 BIT NOT NULL, b2 BIT NOT NULL DEFAULT b'0', b3 BIT NOT NULL DEFAULT b'1');
@@ -178,13 +178,16 @@ val SimpleA = CustomTyping.SimpleA
| 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.id, "Int")
| assertType(TableName.baseTableRow.si, "Int")
| assertType(TableName.baseTableRow.mi, "Int")
| assertType(TableName.baseTableRow.ui, "Long")
| assertType(TableName.baseTableRow.bi, "Long")
| //assertType(TableName.baseTableRow.ubi, "BigInt")
| val bitEntries = Seq(BitTestRow(true), BitTestRow(false, true, true))
| DBIO.seq(
| schema.create,
| TableName += TableNameRow(0, 0, 0, 0),
| TableName += TableNameRow(0, 0, 0, 0, 0/*, BigInt(0)*/),
| BitTest ++= bitEntries,
| BitTest.result.map{assertEquals(_, bitEntries)},
| TableName.result.map{ case rows: Seq[TableNameRow] => assert(rows.length == 1) },
@@ -8,7 +8,7 @@ object JdbcCapabilities {
val createModel = Capability("jdbc.createModel")
/** Can insert into AutoInc columns. */
val forceInsert = Capability("jdbc.forceInsert")
/** Supports a native insertOrUpdate command. Ootherwise the functionality
/** Supports a native insertOrUpdate command. Otherwise the functionality
* is emulated on the client side. The emulation uses transactions for
* consistency but does not guarantee atomicity, so it may fail if another
* insert for the same key happens concurrently. */
@@ -195,7 +195,7 @@ class JdbcModelBuilder(mTables: Seq[MTable], ignoreInvalidDefaults: Boolean)(imp
def dbType: Option[String] = Some(meta.typeName)
/** Column length of string types */
def length: Option[Int] = if(tpe == "String") meta.size else None // Only valid for strings!
/** Indicates wether this should be a varchar in case of a string column.
/** Indicates whether this should be a varchar in case of a string column.
* Currently defaults to true. Should be based on the value of dbType in the future. */
def varying: Boolean =
Seq(java.sql.Types.NVARCHAR, java.sql.Types.VARCHAR, java.sql.Types.LONGVARCHAR, java.sql.Types.LONGNVARCHAR) contains meta.sqlType
@@ -107,7 +107,12 @@ trait MySQLProfile extends JdbcProfile { profile =>
override def jdbcTypeToScala(jdbcType: Int, typeName: String = ""): ClassTag[_] = {
import java.sql.Types._
jdbcType match{
case SMALLINT => classTag[Int]
case SMALLINT => classTag[Int]
case INTEGER if typeName.contains("UNSIGNED") => classTag[Long]
/**
* Currently java.math.BigInteger/scala.math.BigInt isn't supported as a default datatype, so this is currently out of scope.
*/
// case BIGINT if typeName.contains("UNSIGNED") => classTag[BigInt]
case _ => super.jdbcTypeToScala(jdbcType, typeName)
}
}

0 comments on commit f732b6c

Please sign in to comment.