Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Migration_9_10.java « migration « persistence « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b17b8675ce499a57061defae89e58a0897d6f2d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package it.niedermann.owncloud.notes.persistence.migration;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import androidx.annotation.NonNull;

import it.niedermann.owncloud.notes.shared.util.NoteUtil;

public class Migration_9_10 {
    /**
     * Adds a column to store excerpt instead of regenerating it each time
     * https://github.com/stefan-niedermann/nextcloud-notes/issues/528
     */
    public Migration_9_10(@NonNull SQLiteDatabase db) {
        db.execSQL("ALTER TABLE NOTES ADD COLUMN EXCERPT INTEGER NOT NULL DEFAULT ''");
        Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT", "TITLE"}, null, null, null, null, null, null);
        while (cursor.moveToNext()) {
            ContentValues values = new ContentValues();
            values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1), cursor.getString(2)));
            db.update("NOTES", values, "ID" + " = ? ", new String[]{cursor.getString(0)});
        }
        cursor.close();
    }
}