Skip to content

Commit f732b6c

Browse files
author
Alexander Samsig
committed
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.
1 parent c1520fb commit f732b6c

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CREATE TABLE `LongTextTest`( entry1 LONGTEXT NOT NULL , entry2 MEDIUMTEXT NOT NULL , entry3 TEXT NOT NULL , entry4 VARCHAR(255) NOT NULL );
22
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' );
3-
CREATE TABLE `table_name`( id INT NOT NULL, si SMALLINT NOT NULL, mi MEDIUMINT NOT NULL, bi BIGINT NOT NULL );
3+
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*/ );
44
CREATE TABLE `bit_test`(b1 BIT NOT NULL, b2 BIT NOT NULL DEFAULT b'0', b3 BIT NOT NULL DEFAULT b'1');

slick-testkit/src/codegen/scala/slick/test/codegen/GenerateMainSources.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,16 @@ val SimpleA = CustomTyping.SimpleA
178178
| assertTrue(createStmt contains "`entry3` TEXT")
179179
| assertTrue(createStmt contains "`entry4` VARCHAR(255)")
180180
| def assertType(r: Rep[_], t: String) = assert(r.toNode.nodeType.toString == s"$t'")
181+
| assertType(TableName.baseTableRow.id, "Int")
181182
| assertType(TableName.baseTableRow.si, "Int")
182183
| assertType(TableName.baseTableRow.mi, "Int")
184+
| assertType(TableName.baseTableRow.ui, "Long")
183185
| assertType(TableName.baseTableRow.bi, "Long")
186+
| //assertType(TableName.baseTableRow.ubi, "BigInt")
184187
| val bitEntries = Seq(BitTestRow(true), BitTestRow(false, true, true))
185188
| DBIO.seq(
186189
| schema.create,
187-
| TableName += TableNameRow(0, 0, 0, 0),
190+
| TableName += TableNameRow(0, 0, 0, 0, 0/*, BigInt(0)*/),
188191
| BitTest ++= bitEntries,
189192
| BitTest.result.map{assertEquals(_, bitEntries)},
190193
| TableName.result.map{ case rows: Seq[TableNameRow] => assert(rows.length == 1) },

slick/src/main/scala/slick/jdbc/JdbcCapabilities.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object JdbcCapabilities {
88
val createModel = Capability("jdbc.createModel")
99
/** Can insert into AutoInc columns. */
1010
val forceInsert = Capability("jdbc.forceInsert")
11-
/** Supports a native insertOrUpdate command. Ootherwise the functionality
11+
/** Supports a native insertOrUpdate command. Otherwise the functionality
1212
* is emulated on the client side. The emulation uses transactions for
1313
* consistency but does not guarantee atomicity, so it may fail if another
1414
* insert for the same key happens concurrently. */

slick/src/main/scala/slick/jdbc/JdbcModelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class JdbcModelBuilder(mTables: Seq[MTable], ignoreInvalidDefaults: Boolean)(imp
195195
def dbType: Option[String] = Some(meta.typeName)
196196
/** Column length of string types */
197197
def length: Option[Int] = if(tpe == "String") meta.size else None // Only valid for strings!
198-
/** Indicates wether this should be a varchar in case of a string column.
198+
/** Indicates whether this should be a varchar in case of a string column.
199199
* Currently defaults to true. Should be based on the value of dbType in the future. */
200200
def varying: Boolean =
201201
Seq(java.sql.Types.NVARCHAR, java.sql.Types.VARCHAR, java.sql.Types.LONGVARCHAR, java.sql.Types.LONGNVARCHAR) contains meta.sqlType

slick/src/main/scala/slick/jdbc/MySQLProfile.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ trait MySQLProfile extends JdbcProfile { profile =>
107107
override def jdbcTypeToScala(jdbcType: Int, typeName: String = ""): ClassTag[_] = {
108108
import java.sql.Types._
109109
jdbcType match{
110-
case SMALLINT => classTag[Int]
110+
case SMALLINT => classTag[Int]
111+
case INTEGER if typeName.contains("UNSIGNED") => classTag[Long]
112+
/**
113+
* Currently java.math.BigInteger/scala.math.BigInt isn't supported as a default datatype, so this is currently out of scope.
114+
*/
115+
// case BIGINT if typeName.contains("UNSIGNED") => classTag[BigInt]
111116
case _ => super.jdbcTypeToScala(jdbcType, typeName)
112117
}
113118
}

0 commit comments

Comments
 (0)