A
A
Anatoly2015-08-18 16:30:19
Android
Anatoly, 2015-08-18 16:30:19

How to properly pull all SQlite data?

There is a database with 30 PC users, each line has about 10 fields. Tell me how to properly extract all the data to store it in a string or array. I want to write this line to a file in the future, for example.
In principle, I can unload everything, but how to do it and organize it correctly , that's what's interesting. That is, for greater convenience of working with this data by writing to a file, for example.
I would like to see real code examples with a similar task or links to such examples. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LeEnot, 2015-08-19
@TonyWrong

It will be most convenient to simply copy the file with the database to the smartphone's memory card, don't you think? Of course, you can get confused with libraries like Jackson or GSON, but WHY, if you still have to copy to a place accessible to the user, because. "Personal space" of the application is also deleted when uninstalled?

public void exportDatabse(String databaseName) {
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();

            if (sd.canWrite()) {
                String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
                String backupDBPath = "backupname.db";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {

        }
    }

Not forget
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Usage:exportDatabse("Имя базы данных")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question