vendredi 30 janvier 2015

Scala SQLite Invalid Query for DELETE

I have problem when trying to add a row and then delete one row from a table. What I have now is:



def addItem(item:Item)={
val query = items.filter(_.name === name)
items += (item.name,item.timestamp)
if(query.list.length > 10)
{
query.sortBy(timestamp).take(1).delete
}
}


It is supposed to store 10 latest items in the database by removing the oldest if there is more than 10.


But I get an error saying



SlickException : Invalid query for DELETE statement: A single source table is required, found List((s2,Comprehension))


I do have another table in the database but this should have nothing to do with that, there is not even a relation between the two tables.


Do you have any ideas what might be wrong? Or is there another way of keeping only last 10 values in the DB. The time stamp is java.sql.timestamp and I'm using Slick library for the SQLite for scala. Also the class Item is just holding a string and a timestamp.


Thanks! Any help is appreciated!


Aucun commentaire:

Enregistrer un commentaire