agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.87k stars 598 forks source link

Increase/Decrease Method support #1121

Closed liorzam closed 7 years ago

liorzam commented 7 years ago

DBFlow Version:4.0.0-beta2 Issue Kind : Feature Description: Adding new SQLCondition for increase/decrease INTEGER column

like: SQLite.update(User.class).set(User_Table.friendsCount.increase())

agrosner commented 7 years ago

not sure if such a method exists. Can you point me to the SQLite documentation for this method?

liorzam commented 7 years ago

you right this method doesnt support in sqlite. but DBFlow is ORM for sql and methods like increase/decrease for int property will be useful.

    private void increaseIntColumn(final DatabaseWrapper databaseWrapper, final String whereClause, Property<Integer> column) {
        final String columnName = column.toString();
        final String sqlCommand = String.format("UPDATE %s SET %s = %s + 1 WHERE %s", User.TABLE_NAME, columnName, columnName, whereClause);
        databaseWrapper.execSQL(sqlCommand);
    }
agrosner commented 7 years ago

you can use the concatenate(1) method on a Property. Also that query you want to use should be used this way:

SQLite.update(User.class)
  .set(User_Table.someColumn.concatenate(1))
  .where(...)
  .executeUpdateDelete();