Hello,
How can I delete all rows from my AO table ?
I am trying something like :
@Override
public void removeAll() {
ao.deleteWithSQL(MyTableName.class);
}
it is getting converted to : DELETE FROM PUBLIC.AO_7F4041_JECHLOGS WHERE [*] and giving me SQL exception.
I also tried achieving something similar to
delete from tablename where 1==1;
but unable to add it properly in deleteWithSQL() function.
Once I achieve deleting all rows, I also have to find out deleting with some condition, Eg: where date_column is < today - X days
Try
ao.deleteWithSQL(MyTableName.class, "ID > ?", 0);
Another way is to select all rows with ao.find(MyTableName.class) and then delete them in forEach loop with ao.delete(row).
@AlexeyDorofeyev
nice meeting you again !!
Meanwhile I had found a little ugly workaround using known column.
ao.deleteWithSQL(JECHLogs.class, "EVENT_DATE IS NOT NULL OR EVENT_DATE IS NULL");
I shall definitely try yours as its seems more neat.
One more question :
Will we have the ‘ID’ column auto created in all the AO tables ??
Yes. Note that your AO entities interfaces always extend net.java.ao.Entity, which has getID() method.
Thank you for the confirmation @AlexeyDorofeyev
Also your code below works quite fine…
ao.deleteWithSQL(MyTableName.class, “ID > ?”, 0);