-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLiteDriver silently ignores unmatched database schemas since 3.1.0 #1402
Comments
My original description was inaccurate so I have updated it. Please read the latest version on GitHub in case you are reading this issue from mails, etc. |
Any updates on this issue? It seems the problem remains in Slick 3.2.0-M1. |
@lastland I am wondering what do do about this. Without table prefix, SQL's return type of a column using a quoted string seems to depend on the fact if this string matches the name of a column (in which case it is the value of the column) or not (in which case it is the string). That's pretty weird behavior on it's own. How does this surface as a problem in a real world use case with slick? |
@cvogt Say you have the following object: class Users(_tableTag: Tag) extends Table[UsersRow](_tableTag, "users") {
val id: Rep[Int] = column[Int]("id", O.PrimaryKey)
val firstname: Rep[String] = column[String]("firstname")
...
} while what you have in your SQLite database is: CREATE TABLE "users" ("id" integer not null primary key, "first" varchar not null); Invoking a query to fetch the I guess guaranteeing that a type of Scala objects matches the "type" in the database (i.e. the database schema) is also part of type-safety? In that way, silently ignoring such a type mismatch compromises Slick's type safety. Of course, using Slick code generator and migration tools like Scala-Forklift could avoid the inconsistency between Scala code and database schemas in the first place, but Slick should not rely on them to be type-safe. PS: If you are using any other database profile (e.g. |
@lastland I see. I remember the change, but couldn't find the PR where this happened right now. I agree that an exception would be preferable. FYI, the SQLite docs say
https://www.sqlite.org/lang_keywords.html If there is an easy way to put a hack into Slick that prevents this, I'd be in favor. As it seems always fully qualifying column names would work, but also make the generate SQL code less readable. |
Any ideas for other hacks? |
@cvogt Isn't using fully qualified column names the better option ? The generated sql might be less readable but I think its better than a hack |
Since Slick 3.1.0 the generated SQL statements for a selection query on a single table becomes:
comparing with Slick 3.0.0:
While this works well with other db drivers, this will cause
SQLiteDriver
to silently ignore unmatched database schema, and return unexpected results. To understand the problem, see the following examples in SQLite:PS: invoking queries on case classes with different column names with their corresponding tables in other drivers, including the older versions of
SQLiteDriver
, will cause aSQLException
.The text was updated successfully, but these errors were encountered: