Skip to content

Commit

Permalink
MySQL driver 6.x and later doesn't support null in name pattern or sc…
Browse files Browse the repository at this point in the history
…heme pattern, the correct way in later versions is passing '%'. MySQL driver 8.x now defaults nullCatalogMeansCurrent to false, therefore the current catalog has to be passed in.

Added "%" as tableNamePattern on SQLServer, Postgres, Oracle. Oracle has started not accepting null in newer versions, and "%" should be semantically the same.
  • Loading branch information
Asamsig committed Jun 16, 2018
1 parent 42d787b commit 27ed3f5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions slick/src/main/scala/slick/jdbc/MySQLProfile.scala
Expand Up @@ -14,6 +14,7 @@ import slick.ast.TypeUtil._
import slick.basic.Capability
import slick.compiler.{Phase, ResolveZipJoins, CompilerState}
import slick.jdbc.meta.{MPrimaryKey, MColumn, MTable}
import slick.dbio.DBIO
import slick.lifted._
import slick.relational.{RelationalProfile, RelationalCapabilities}
import slick.sql.SqlCapabilities
Expand Down Expand Up @@ -124,6 +125,12 @@ trait MySQLProfile extends JdbcProfile { profile =>

override def createModelBuilder(tables: Seq[MTable], ignoreInvalidDefaults: Boolean)(implicit ec: ExecutionContext): JdbcModelBuilder =
new ModelBuilder(tables, ignoreInvalidDefaults)
override def defaultTables(implicit ec: ExecutionContext): DBIO[Seq[MTable]] ={
for {
catalog <- SimpleJdbcAction(_.session.conn.getCatalog)
mtables <- MTable.getTables(Some(catalog), None, Some("%"), Some(Seq("TABLE")))
} yield mtables
}

override val columnTypes = new JdbcTypes
override protected def computeQueryCompiler = super.computeQueryCompiler.replace(new MySQLResolveZipJoins) - Phase.fixRowNumberOrdering
Expand Down
2 changes: 1 addition & 1 deletion slick/src/main/scala/slick/jdbc/OracleProfile.scala
Expand Up @@ -99,7 +99,7 @@ trait OracleProfile extends JdbcProfile {
override def defaultTables(implicit ec: ExecutionContext): DBIO[Seq[MTable]] = {
for {
user <- SimpleJdbcAction(_.session.metaData.getUserName)
mtables <- MTable.getTables(None, Some(user), None, Some(Seq("TABLE")))
mtables <- MTable.getTables(None, Some(user), Some("%"), Some(Seq("TABLE")))
} yield mtables
}

Expand Down
2 changes: 1 addition & 1 deletion slick/src/main/scala/slick/jdbc/PostgresProfile.scala
Expand Up @@ -140,7 +140,7 @@ trait PostgresProfile extends JdbcProfile {
new ModelBuilder(tables, ignoreInvalidDefaults)

override def defaultTables(implicit ec: ExecutionContext): DBIO[Seq[MTable]] =
MTable.getTables(None, None, None, Some(Seq("TABLE")))
MTable.getTables(None, None, Some("%"), Some(Seq("TABLE")))

override val columnTypes = new JdbcTypes
override protected def computeQueryCompiler = super.computeQueryCompiler - Phase.rewriteDistinct
Expand Down
2 changes: 1 addition & 1 deletion slick/src/main/scala/slick/jdbc/SQLServerProfile.scala
Expand Up @@ -118,7 +118,7 @@ trait SQLServerProfile extends JdbcProfile {
new ModelBuilder(tables, ignoreInvalidDefaults)

override def defaultTables(implicit ec: ExecutionContext): DBIO[Seq[MTable]] = {
MTable.getTables(None, None, None, Some(Seq("TABLE"))).map(_.filter(!_.name.schema.contains("sys")))
MTable.getTables(None, None, Some("%"), Some(Seq("TABLE"))).map(_.filter(!_.name.schema.contains("sys")))
}

override def defaultSqlTypeName(tmd: JdbcType[_], sym: Option[FieldSymbol]): String = tmd.sqlType match {
Expand Down
6 changes: 6 additions & 0 deletions slick/src/main/scala/slick/jdbc/meta/MTable.scala
Expand Up @@ -23,6 +23,12 @@ case class MTable(
}

object MTable {
/**
* Some DatabaseMetaData methods take arguments that are String patterns. These arguments all have names such as fooPattern.
* Within a pattern String, "%" means match any substring of 0 or more characters, and "_" means match any one character.
* Only metadata entries matching the search pattern are returned.
* If a search pattern argument is set to null, that argument's criterion will be dropped from the search.
*/
def getTables(cat: Option[String], schemaPattern: Option[String], namePattern: Option[String],
types: Option[Seq[String]]) = ResultSetAction[MTable](
_.metaData.getTables(cat.orNull, schemaPattern.orNull, namePattern.orNull, types.map(_.toArray).orNull) ) { r =>
Expand Down

0 comments on commit 27ed3f5

Please sign in to comment.