delete using join?

234 views
Skip to first unread message

larham

unread,
Nov 25, 2010, 1:57:53 PM11/25/10
to ORMLite Users
In attempting to delete rows that require a join, I ran into a problem
that sqlite requires syntax for delete that has no arg between
"delete" and "from":

delete from <table> where id in (<inner join sql>)

(compare syntax: "delete * from ..." )

I don't see how such custom sql can be run through any ormlite
function. using queryForAllRaw() will fail because it asks for the
arg between "delete" and "from".

A workaround is to break up the join into separate queries, getting
the <inner join sql> results and feeding those into Dao.deleteIds().

For the android side, I can use Helper access to the sqlitedatabase to
call its exec(sql) for my sql. I don't see a way to do this on the
jdbc side.

Does it seem reasonable to provide access to a raw execute(sql) from
any ConnectionSource or perhaps any Dao?

thanks,

larry

Diederik

unread,
Feb 14, 2013, 12:53:34 AM2/14/13
to ormlit...@googlegroups.com
Have you noticed that the new QueryBuilder class  (as of version 4.43) now supports joins with other query builders?
I have used this to get a list of objects, and then just deleting them with the DaoImpl.delete() method. 
(would have been better to add join() on DeleteBuilder but that is all we have for now.)
Reply all
Reply to author
Forward
0 new messages