Why does this ScalaQuery statement delete only odd lines?

When you try to delete a batch of records, only odd lines are deleted!

val byUser = Orders.createFinderBy(_.userID) byUser(id).mutate(_.delete) 

If I print a record instead, I get the correct number of lines.

 byUser(id).mutate{x => x.echo} 

I worked on a problem like this that generates the desired SQL.

 (for{o <- Orders if o.userID is id.bind } yield o).delete 

But why and how does the mutate version only affect odd lines?

+6
source share
1 answer

I have a dig in the source code, and it looks like @RexKerr says the iterator is used to process the elements, applying deletes as they iterate (while loop in mutate method here):

https://github.com/rjmac/scala-query/blob/master/src/main/scala/org/scalaquery/MutatingInvoker.scala

Interestingly, there is a flag beforeAfterDelete, which can be used to force the iterator to return after each deletion. Access databases seem to be set to true (see AccessQueryInvoker Class), but not others:

https://github.com/rjmac/scala-query/blob/master/src/main/scala/org/scalaquery/ql/extended/AccessDriver.scala

I would recommend downloading the sources and debugging the code. Perhaps this flag should be set for the database provider that you are using. I will also consider sending a bug report:

http://scalaquery.org/community.html

PS. I know this is an old question, but answered it just in case someone had this problem.

+1
source

Source: https://habr.com/ru/post/919146/


All Articles