It must be
StaticQuery.updateNA(createStatement).execute
instead of
StaticQuery.updateNA(createStatement)
Frage
I'm using slick 2.0.0 in my application and in dev/prod, it is working fine.
In test mode, I want to autogenerate a H2 database (out of the slick table definitions) and use this for my test cases. I use scalatest 2.0.
The database definition (application.conf) for test is the following
db{
...
test {
driver=org.h2.Driver
url="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"
}
}
At the beginning of a test case, I call
Slick.db.withTransaction { implicit s =>
StaticQuery.updateNA("DROP ALL OBJECTS;")
val createStatement = models.slick.Tables.ddl.createStatements.mkString("",";",";")
println("CREATE: "+createStatement)
StaticQuery.updateNA(createStatement)
}
(in test mode, Slick.db points to DB("test") from the play-slick plugin, so it simply takes the DataSource defined in application.conf in db.test)
When running the test case, I get the following output:
CREATE: [...]; create table `mytable` (`field1` VARCHAR(254) NOT NULL,`field2` VARCHAR(254) NOT NULL,`field3` VARCHAR(254) NOT NULL,`ID` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY); [...]
[info] - should [...] *** FAILED ***
[info] org.h2.jdbc.JdbcSQLException: Tabelle "MYTABLE" nicht gefunden
[info] Table "MYTABLE" not found; SQL statement:
[info] INSERT INTO `mytable` (`field1`,`field2`,`field3`) VALUES (?,?,?) [42102-172]
[info] at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
[info] at org.h2.message.DbException.get(DbException.java:169)
[info] at org.h2.message.DbException.get(DbException.java:146)
[info] at org.h2.command.Parser.readTableOrView(Parser.java:4824)
[info] at org.h2.command.Parser.readTableOrView(Parser.java:4802)
[info] at org.h2.command.Parser.parseInsert(Parser.java:966)
[info] at org.h2.command.Parser.parsePrepared(Parser.java:375)
[info] at org.h2.command.Parser.parse(Parser.java:279)
[info] at org.h2.command.Parser.parse(Parser.java:251)
[info] at org.h2.command.Parser.prepareCommand(Parser.java:218)
[info] ...
[info] ScalaTest
So it definitely creates the table and accesses the same table (though in upper case). Is case a problem? Don't think so. How can I make this work?
If case is a problem, is there a way to tell slick to either generate or use the tables with the same case?
Lösung
It must be
StaticQuery.updateNA(createStatement).execute
instead of
StaticQuery.updateNA(createStatement)