Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 在ScalikeJDBC中更新返回的查询_Scala_Scalikejdbc - Fatal编程技术网

Scala 在ScalikeJDBC中更新返回的查询

Scala 在ScalikeJDBC中更新返回的查询,scala,scalikejdbc,Scala,Scalikejdbc,使用隐式val会话:范围内的DBSession,具体为scalikejdbc.AutoSession: 更新工作 sql""" update payments set status=${status.name} where id in ($ids) """.update().apply() 并选择工作 sql""" select id from payments where status='valid' """.map(_.long).list().apply()

使用
隐式val会话:范围内的DBSession
,具体为
scalikejdbc.AutoSession

更新工作

sql"""
    update payments set status=${status.name} where id in ($ids)
""".update().apply()
并选择工作

sql"""
   select id
   from payments
   where status='valid'
""".map(_.long).list().apply()
但是更新返回列失败,因为事务设置为只读

sql"""
  update payments
  set status='submitted'
  where status='pending'
  and scheduled <= ${ZonedDateTime.now.toInstant}
  returning id
""".map(_.long).iterable().apply().toIterator
我尝试创建自己的
DBSession
,以避免与此模式匹配,但放弃了这种方法。我最接近让它工作的方法是:

val writeableSession: DBSession = DBSession(session.connection, isReadOnly = false)

def inner()(implicit session: DBSession): Iterator[Payment] = {
  sql"""
  update payments
  set status='submitted'
  where status='pending'
  returning id
""".map(_.long).iterable().apply().toIterator
}

inner()(writeableSession)
此操作失败,因为
会话。连接
null


如何将其强制为localTx而不是只读?

通常,
自动会话
充当DDL和insert/update/delete ops的自动提交会话,而它充当select查询的只读会话

它似乎是这样做的,以下是直截了当的方法

DB.localTx { implicit session =>
  // Have both the update operation and select query inside this block
}

通常,
AutoSession
充当DDL和insert/update/delete ops的自动提交会话,而它充当select查询的只读会话

它似乎是这样做的,以下是直截了当的方法

DB.localTx { implicit session =>
  // Have both the update operation and select query inside this block
}

谢谢是的,我更愿意这样做,但我在playframework中除了一个热切绑定的Autosession之外什么都没有。我明白了
scalikejdbc.TxBoundary.Future
可能对您的用例有用。我很抱歉。当然,我可以调用
DB.localTx
。我不知道为什么我认为我不能谢谢是的,我更愿意这样做,但我在playframework中除了一个热切绑定的Autosession之外什么都没有。我明白了
scalikejdbc.TxBoundary.Future
可能对您的用例有用。我很抱歉。当然,我可以调用
DB.localTx
。我不知道为什么我认为我不能