I have a database with a lot of tables. And one of these tables stores the name of some tables.

I would like to export just the tables that have their name in this table which store names.

For example: StoreTable stores the names A, B, C.

In my database, I have the tables A, B, D, E, F.

When I export, the method will export just the tables A and B, because their name are in the StoreTable.

I research a little, and notice that could be done with a select inside a select, but I am not familiar with SQLite yet.

The code I already did exports all tables from the database, it is bellowe:

    public void exportTableFiltered(SQLiteDatabase db, String tableName) {

        if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

            try {
                Cursor cursor = db.rawQuery("SELECT * FROM \"" + tableName + "\"", null);

                exportDir = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/EXPORTED/");

                if (!exportDir.exists())

                File file = new File(exportDir, tableName +".csv");

                CSVWriter csvWriter = new CSVWriter(new FileWriter(file.getAbsoluteFile(), true));

                //Writes content into .CSV
                while(cursor.moveToNext()) {

                    //just columm 1
                    String arrStr[] = { cursor.getString(1)};


            } catch (Exception e) {

                Toast.makeText(this, "Catch 04: " + e.getMessage(), Toast.LENGTH_LONG).show();


        else {

            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);


        Toast.makeText(getApplicationContext(), "CSV FILE GENERATED!!", Toast.LENGTH_SHORT).show();



0 Answers