什么会做SQLiteCursor如果列为空? [英] What will a SQLiteCursor do if a column is null?

查看:204
本文介绍了什么会做SQLiteCursor如果列为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个整数从游标从SQLite的查询返回的,但我知道整数可能为null。不幸的是,我找不到任何方法光标让我检查一下。

I want to get an integer from a Cursor returned from a SQLite query, but I know the integer may be null. Unfortunately I can't find any Cursor method allowing me to check this.

在code将

mModifiedDate = cursor.getInt(cursor.getColumnIndex(MODIFIED_DATE));

我期望一个可能的空值,这实际上是可取的各种原因,该字段指的是一个第二表被修改的时间,和之前的第二个是在第一表可以填充。不幸的是,光标的文件说,是否抛出一个异常,或者返回错误值,或其他行为,是留给实施和SQLiteCursor文件并没有说什么。

I would expect a possible null value, and this is in fact desirable for various reasons—the field refers to the time a second table was modified, and the first table can be populated before the second one is. Unfortunately, the documentation for Cursor says that whether an exception is thrown, or an error value is returned, or other behaviour, is left up to the implementation, and the SQLiteCursor documentation doesn't say ANYTHING.

如果该字段为空什么将在code呢?有没有一种方法调用之前检查这个调用getInt()?

What will this code do if the field is null? Is there a way to check this before calling getInt()?

推荐答案

有一个 ISNULL() -method,只是用事先是否检测空值。请记住:这是很常见的返回被命名的布尔 ISX()而不是的getX()方法,它可以是一些混乱的根源:)

there is an isNull()-method, just use if beforehand to detect null-values. Remember: It is quite common for methods that return a boolean to be named isX() instead of getX(), it can be the source of some confusion :)

这篇关于什么会做SQLiteCursor如果列为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆