问题描述
我已经设置好Play! (使用Slick)应用程序在运行测试时使用H2,到目前为止,它的运行情况非常好.我现在遇到一个错误,因为使用小写的列和表名的普通SQL查询,H2抱怨找不到TABLE(全部大写).
I've setup my Play! (with Slick) application to use H2 when running tests, and it has worked great so far. I'm getting an error now, because of a plain-SQL query that uses lower-case column and table names, and H2 complains that the TABLE (all uppercase) could not be found.
现在,我需要设置很少的选项,IGNORECASE
,可能还有MODE
.
Now I need to set a few options, IGNORECASE
for sure, and possibly the MODE
.
设置数据库进行测试时,我使用
When I setup my database for tests, I use
def fakeAppWithMemoryDatabase = FakeApplication(additionalConfiguration = inMemoryDatabase())
对于开发,我使用PSQL,因此在我的application.conf
文件中,我有:
For development, I use PSQL, so in my application.conf
file, I have:
slick.db.driver=scala.slick.driver.H2Driver
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/mydb"
从文档中,我看到了我可以将设置传递给db.default.url
字符串,例如
From the documentation, I see I can pass settings to the db.default.url
string, like
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL;"
,但是我的default.url
设置适用于我的Postgres DB.在这种情况下,是否可以将MODE
和IGNORECASE
设置传递给H2?
but my default.url
setting is for my Postgres DB. Is there a way to pass in MODE
and IGNORECASE
settings to H2 in this scenario?
我尝试将SET IGNORECASE TRUE;
附加到我的SQL查询中,但仍然收到相同的错误.
I have tried to append SET IGNORECASE TRUE;
to my SQL query but I still receive the same error.
推荐答案
您需要添加DATABASE_TO_UPPER = false到您的网址.它会让您忽略".有了这个,我将继续使用H2,否则我不会.无法说出为什么默认情况下此选项为true ...
You need to addDATABASE_TO_UPPER=falseto your Url. It will let you leave the "" out.With this I will continue to use H2 otherwise I wouldn't. Can't tell why this option is true by default...
这篇关于在Play中为H2设置IGNORECASE和其他选项!框架测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!