Slick为MySQL生成错误的SQL(MyISAM)

时间:2015-12-18 11:26:57

标签: mysql scala slick myisam

我想使用最新的Slick(3.1.1)分析遗留的mysql数据库(myisam引擎)。

版本:

  scalaVersion := "2.11.7"
  "com.typesafe.slick" %% "slick" % "3.1.1"
  "com.typesafe.slick" %% "slick-codegen" % "3.1.1"
  "org.slf4j" % "slf4j-nop" % "1.7.13"
  "mysql" % "mysql-connector-java" % "5.1.38"

使用slick.codegen.SourceCodeGenerator从我的数据库生成Tables.scala后,我写了一些简单的查询代码:

  val query = Users map { _.firstname }
  val action = query.result
  val future = db.run(action)
  future onSuccess {  
    case result => println("result: " + result)
  }
  future onFailure {
    case t => 
        println("Got an error: " + t.getMessage)
        println("SQL: " + action.statements.head)   
  }

输出如下:

Got an error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"Users"' at line 1
SQL: select "FirstName" from "Users"

这些引号对我来说不对。它应该是select FirstName from Users,对吧?

出了什么问题?

整顿:这是我的一个简单的复制和粘贴错误。我忘了替换那个

object Tables extends { val profile = slick.driver.H2Driver } with demo.Tables

object Tables extends { val profile = slick.driver.MySQLDriver } with demo.Tables

抱歉!

1 个答案:

答案 0 :(得分:1)

如果MySQL在ANSI_QUOTES SQL模式下运行,则双引号可用于转义表名和列名。

有关SQL模式的详细信息,请参阅http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html