Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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 如何检查BLOB是否为空_Android_Sql_Sqlite - Fatal编程技术网

Android 如何检查BLOB是否为空

Android 如何检查BLOB是否为空,android,sql,sqlite,Android,Sql,Sqlite,如果SQLite数据库中的列的值为Blob类型,如何检查该列的值是否为null 我正在获取一个如下所示的光标: public Cursor fetchArticle(int i) throws SQLException { Cursor mCursor = mDatabase.query(true, "api_content", new String[] { "_id", "ArticleName", "ArticleText","ImageLink", "Ima

如果SQLite数据库中的列的值为Blob类型,如何检查该列的值是否为null

我正在获取一个如下所示的光标:

public Cursor fetchArticle(int i) throws SQLException {
    Cursor mCursor = mDatabase.query(true, "api_content",
        new String[] { "_id", "ArticleName",     "ArticleText","ImageLink", "Image" },
        KEY_ID + "=" + i, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
如何检查图像列索引4的值是否为空?我尝试了以下方法:

  • 使用该方法,该方法总是返回false,而实际上该值应该是null
  • 使用
    articleCursor.getBlob(4)=null
    ,其中
    articleCursor
    是有效的游标(返回false)

为了进一步复杂化,当我打印出<代码> PosialCurror。GETBROB(4)[0 ] < /代码>时,返回值如<代码> 78 <代码>或<代码> 91 > /代码>,这与我认为的“代码> NULL/<代码>无关。


同样,数据库不可能在该列中包含任何数据;它必须为空。有什么想法吗?谢谢

请查找下面的查询以获取值Y或N

select id, 
 case
      when myblob is not null then 'Y'
      else 'N'
 end,
 myblob
如果blob为null,则返回N else Y。

方法getBlob()始终有一个值。如果此列的值为空或null,则使用方法长度时,结果为1

例如:

byte[] image = cursor.getBlob(cursor.getColumnIndex("image"));
if(image.length == 1) {
   //column data is empty
} else{
   //column has data
}

我希望它能对您有所帮助。

命令行上的普通SQL查询会为该列/行返回什么?您是否尝试过查询“length(x)”而不是“x”或补充“x”?如果x为Null,则它将返回Null,并且任何数据库驱动程序和/或客户端缓冲区都不应被任意八位字节序列混淆。@DaDaDom普通查询返回Null。@collapsar,当你说“x”时,你是指articleCursor返回的字节数组。getBlob(4)?@alejandro:不,实际上我指的是sql语句,或游标构造函数的参数,分别为。;您不必选择结果集列,而应该能够在这样的列上指定sql表达式,即示例中的“length(Image)”-您最好参考手册或类api以获得正确的语法。空blob的length()返回0,而不是1。