Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When storage path is specified, queries come back empty. #8

Closed
whatmattersmost opened this issue Feb 22, 2018 · 4 comments
Closed

When storage path is specified, queries come back empty. #8

whatmattersmost opened this issue Feb 22, 2018 · 4 comments

Comments

@whatmattersmost
Copy link

whatmattersmost commented Feb 22, 2018

Repro steps:
+) cloned your repo, builded successfully and verified the employers and customers are queried
+) added a storage path (apps data directory) to the instantiation : /storage/emulated/0/Android/data/com.huma.roomforasset/files/db/ (both in java and kt)
+) added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission
+) after uninstall and reinstall i can see the db in the expected folder. employees and customers table are not empty as expected
+) clicking on the buttons "employees" and "customers" now results in empty tables.

Any ideas whats going on, did i miss sth.? Anyway thanks for your lib and your effort.

@humazed
Copy link
Owner

humazed commented Feb 25, 2018 via email

@humazed
Copy link
Owner

humazed commented Mar 22, 2018

I'm closing this issue since no more info is added feel free to open it if you still face the same problem.

@humazed humazed closed this as completed Mar 22, 2018
@whatmattersmost
Copy link
Author

@humazed : Unfortunately i still have that or a similar problem. I try to point room to a database in /storage/emulated/0/Android/data/... , but it then uses one in /data/user/0/.... .

I have recently returned to the project i am trying to use RoomAsset in and specifying a path does not work.

seems to me that initializing roomasset with a path like:

sInstance = RoomAsset.databaseBuilder(context.getApplicationContext(),
                        AppDatabase.class,
                        "app.db",
                        "/storage/emulated/0/Android/data/com.........................../files/databases/"
                        )
                        .addCallback(new Callback() {

                            @Override
                            public void onCreate(@NonNull SupportSQLiteDatabase db) {
                                super.onCreate(db);
                                sInstance.updateDatabaseCreated(context.getApplicationContext());
                                Timber.d("getInstance - onCreate - "+(sInstance.mDatabase != null ?"sInstance.mDatabase.getPath(): "+sInstance.mDatabase.getPath() : "sInstance.mDatabase == null"));
                            }
                        })
                        .build();

results in the following path:
.... D/AppDatabase: updateDatabaseCreated - context.getDatabasePath(DATABASE_NAME): /data/user/0/com..................................../databases/app.db .....

@whatmattersmost
Copy link
Author

@humazed : I tested my abovementioned sample modification again by changing the onCreate method in the JavaActivity in order to provide a path the following way:

String path = getApplicationContext().getExternalFilesDir(null).getAbsolutePath()+"/db/";
        Log.d(TAG, "onCreate - path: "+path);
        final AppDatabase db = RoomAsset.databaseBuilder(
                getApplicationContext(),
                AppDatabase.class,
                "chinook.db",
                path)
                .addCallback(new RoomDatabase.Callback() {
                    @Override
                    public void onOpen(@NonNull SupportSQLiteDatabase db) {
                        super.onOpen(db);
                        Log.d(TAG,"getInstance - onOpen - "+(db != null ?"db.getPath(): "+db.getPath() : "db == null"));
                    }

                    @Override
                    public void onCreate(@NonNull SupportSQLiteDatabase db) {
                        super.onCreate(db);
                        Log.d(TAG,"getInstance - onCreate - "+(db != null ?"db.getPath(): "+db.getPath() : "db == null"));
                    }
                })
                .build();

And what I am seeing is unfortunately exactly what I saw in my project:
D/JavaActivity: onCreate - path: /storage/emulated/0/Android/data/com.huma.roomforasset/files/db/

D/JavaActivity: getInstance - onOpen - db.getPath(): /data/user/0/com.huma.roomforasset/databases/chinook.db

The database ends up in data/user instead of the specified path /storage/emulated/0/Android/data/ .

So specifying a path does not work. I would reopen this issue but it seems I don't have the required permission. Can you please confirm this issue and ideally fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants