Skip to content
Permalink
Browse files

Proper treatment of CHAR(1) columns in JdbcModelBuilder:

- Use Scala type Char instead of String

- Strip quotes off from default values

Fixes #1004. Test in h2.sql (via GeneratedCodeTest).
  • Loading branch information
szeiger committed Feb 20, 2015
1 parent 7f0f62f commit 58a1db9a9301e68ac8f9732f992d9897f404e376
@@ -20,3 +20,8 @@ create table "E" (
);

create table "SIMPLE_AS" ("A1" INTEGER NOT NULL,"A2" VARCHAR NOT NULL);

CREATE TABLE "PERSON"(
"ID" NUMBER(11,0) NOT NULL,
"PERSON_TYPE" CHAR(1) DEFAULT 'Y' NOT NULL
);
@@ -178,7 +178,7 @@ class JdbcModelBuilder(mTables: Seq[MTable], ignoreInvalidDefaults: Boolean)(imp
final val StringPattern = """^'(.*)'$""".r
/** Scala type this column is mapped to */
def tpe = jdbcTypeToScala(meta.sqlType).toString match {
case "java.lang.String" => "String"
case "java.lang.String" => if(meta.size == Some(1)) "Char" else "String"
case t => t
}
def name = meta.name
@@ -221,8 +221,11 @@ class JdbcModelBuilder(mTables: Seq[MTable], ignoreInvalidDefaults: Boolean)(imp
case (v,"Double") => v.toDouble
case (v,"Float") => v.toFloat
case (v,"Char") =>
assert(v.size == 1, "char has unexpected size: "+v)
v.head
v.length match {
case 1 => v(0)
case 3 => v(1) // quoted character
case n => throw new SlickException(s"""Default value "$v" for Char column "$name" has wrong size""")
}
case (v,"String") if meta.typeName == "CHAR" => v.head // FIXME: check length
case (v,"scala.math.BigDecimal") => v // FIXME: probably we shouldn't use a string here
case (StringPattern(str),"String") => str

0 comments on commit 58a1db9

Please sign in to comment.
You can’t perform that action at this time.