Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正确使用Android SQLiteStatement';s simpleQueryForBlobFileDescriptor()_Android_Sqlite_Android 3.0 Honeycomb - Fatal编程技术网

正确使用Android SQLiteStatement';s simpleQueryForBlobFileDescriptor()

正确使用Android SQLiteStatement';s simpleQueryForBlobFileDescriptor(),android,sqlite,android-3.0-honeycomb,Android,Sqlite,Android 3.0 Honeycomb,Android的SQLiteStatement中的函数simpleQueryForBlobFileDescriptor()对我来说是个谜。而且似乎没有人在任何地方使用它。似乎这是一种针对单个blob访问的快速方法,就性能而言(如果文档可信的话),SQLiteStatement和Parcel的组合在用于将blob数据从数据库中流出来时应该会产生非常快的结果。我不知道,因为我不能让它工作,所以我可以测试。。。如有任何帮助或见解,将不胜感激: SQLiteStatement get = mDb.com

Android的SQLiteStatement中的函数simpleQueryForBlobFileDescriptor()对我来说是个谜。而且似乎没有人在任何地方使用它。似乎这是一种针对单个blob访问的快速方法,就性能而言(如果文档可信的话),SQLiteStatement和Parcel的组合在用于将blob数据从数据库中流出来时应该会产生非常快的结果。我不知道,因为我不能让它工作,所以我可以测试。。。如有任何帮助或见解,将不胜感激:

SQLiteStatement get = mDb.compileStatement(
    "SELECT blobColumn" + 
    " FROM tableName" +
    " WHERE _id = 1" +
    " LIMIT 1"
);

ParcelFileDescriptor result = get.simpleQueryForBlobFileDescriptor();
// now what?
我可能应该注意到,我正在使用并且只真正关心Honeycomb(3.2),并提前感谢您提供的任何见解

SQLiteStatement get = mDb.compileStatement(
    "SELECT blobColumn" + 
    " FROM tableName" +
    " WHERE _id = 1" +
    " LIMIT 1"
);

ParcelFileDescriptor result = get.simpleQueryForBlobFileDescriptor();
FileInputStream fis = new FileInputStream(result.getFileDescriptor()); // read like any other

我可以验证这对于我的用例来说是非常快的

我发现这一点特别有用(如果您需要像我一样创建自己的自定义脱机webview文件缓存)是在内容提供商的openFile覆盖中,您可以直接返回描述符(或者理想情况下覆盖openTypedAssetFile())

示例: files是DB助手,getFileDescriptor(String)与上面的代码类似

public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, android.os.Bundle opts) throws FileNotFoundException {
    ParcelFileDescriptor pfd = files.getFileDescriptor(uri.toString());
    if (pfd != null) {
        return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
    }
    return null;
}
或者对类似问题的另一个重要用途: (您希望将自定义文件从db提供给webview的位置)


祝贺你的解决方案。当你有能力时,请将你的答案标记为“已接受”,以便其他人可以从你的成功中学习。干杯~“我可以验证这对于我的用例来说是非常快的。”。我做了一些测试,我认为它比使用带有c.getBlob()的简单游标慢;请参阅@user1344545中的我的测试,尝试在不使用
simpleQueryForBlobFileDescriptor()
的情况下执行我演示的操作,结果大约慢了5-10倍,因此,事实上,没有它的版本基本上是不可用的,至少在我编写本文时是如此。。。
private WebViewClient webViewClient = new WebViewClient() {
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

        ParcelFileDescriptor pfd = files.getFileDescriptor(url);
        if (pfd != null) {
            return new WebResourceResponse(null, null, new FileInputStream(pfd.getFileDescriptor()));
        }

        return null; 
    }