J
J
JackieRyan2021-01-26 13:04:25
Java
JackieRyan, 2021-01-26 13:04:25

Changing the database on program startup?

Hello! I'm trying to make a code that will change the specific text in the database every time it is run. Somehow I wrote what I could. Can you please fix what is wrong? Thanks in advance!

More about the task:
1. There is a path: data/data/com.gameloft.android.ANMP.GloftPOHM/databases/
2. There is a sqlite file: gameloft_sharing
3. There is a text in two places: "time":"1663568928" (this is an example, there are always 10 digits, but they are different for each installation). And yes, I know that this is Unix, but in this case it does not matter, here they are just numbers!

It is necessary to make sure that at each start these 10 digits in both parameters are synchronously changed to random ones (it is very important that these digits in both sections are identical after each change).

Actually my code (so far only the generator of 10 digits works, and even then I'm not sure that the SQLite class will pick it up):

import java.io.File;
import java.util.Random;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class Numbers {
    public static void main(String[] args) {
        Random rand = new Random();
        rand.nextInt((999999999) + 1111111111);
    }
}

public class SQLite extends SQLiteOpenHelper {

    public SQLite(Activity activity) {
        super(activity.getApplicationContext(), "", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        UPDATE table SET field = replace( field, "time":"%", "time":"Numbers");
    }

    public SQLiteDatabase open(String filepath) {
        File fDB = new File(filepath);
        if (!fDB.exists()) {
            return null;
        }
        return SQLiteDatabase.openDatabase(filepath, null, SQLiteDatabase.OPEN_READWRITE);
    }
}[/code]

Помогите пожалуйста привести код в работоспособное состояние. Я дальше просто не знаю что делать...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question