将数据库中的表从Dropbox复制到App

时间:2015-07-14 06:03:52

标签: dropbox dropbox-api

我编写了以下代码来将数据库文件从dropbox帐户复制到app数据库。但是我只想将特定的表从Dropbox复制到App数据库表。这是可能的。

 protected Boolean doInBackground(Void... params) {
        final File tempDir = context.getCacheDir();
        File tempFile;
        FileWriter fr;
        try {
            File data = Environment.getDataDirectory();

            String currentDBPath = "//data//"+ "loginscreen.example.com.girviapp" +"//databases//"+DATABASE_NAME;
            File currentDB = new File(data, currentDBPath);
            FileInputStream fileInputStream = new FileInputStream(currentDB);

            Entry existingentry= dropbox.metadata( path ,1000,null,true,null);


            if (existingentry.contents.size() != 0)
            {
                for (Entry ent :existingentry.contents)
                {
                    String name = ent.fileName();
                    if(name.equals(DATABASE_NAME))
                    {    FileOutputStream outputStream = new FileOutputStream(currentDB);
                        DropboxFileInfo info = dropbox.getFile(path + DATABASE_NAME, null, outputStream, null);

                        return true;
                    }

                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DropboxException e) {
            e.printStackTrace();
        }
        return false;
    }

1 个答案:

答案 0 :(得分:0)

这里的答案取决于你想要做什么。

如果您希望只能从Dropbox上存储的数据库文件中下载特定的表,为了通过不下载所有数据来节省带宽,那么不,这是不可能的。您正在使用的Dropbox API中的存储单元是文件,Dropbox不知道数据库文件中的各个表是什么,因此它无法指定特定的表。

另一方面,如果你不介意从Dropbox下载整个文件,那么是的,这是可能的。只需在您正在执行时下载文件,然后在本地将其作为数据库加载。然后只查询所需的数据,即所需的数据表,并用它做你需要的数据。

相关问题