1
我需要使用我的舊代碼與油滑3,但它不工作,我不知道該怎麼做。油滑3截斷表測試
我的舊代碼:
database.withSession { implicit s: Session =>
StaticQuery.updateNA("SET foreign_key_checks = 0").execute()
val q = StaticQuery.query[String, String](
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?"
).apply(dbname)
for (table <- q) {
StaticQuery.updateNA("TRUNCATE " + dbname + "." + table).execute()
}
StaticQuery.updateNA("SET foreign_key_checks = 1").execute()
}
新的代碼,包括漂亮的3:
val a = for {
_ <- sqlu"SET foreign_key_checks = 0"
s <- sql"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ${ dbname }".as[String]
_ <- DBIO.sequence(s.map(table => sqlu"TRUNCATE #${MySQLDriver.quoteIdentifier(dbname)}.#${MySQLDriver.quoteIdentifier(table)}").map(x => DBIO.successful(x)))
_ <- DBIO.successful(sql"SET foreign_key_checks = 1")
} yield()
Await.result(db.run(a), scala.concurrent.duration.Duration(1000, SECONDS))
錯誤:
com.googlecode.flyway.core.api.FlywayException: Unable to lock table `myLocalDB_test`.`schema_version
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'myLocalDB_test.schema_version' doesn't exist