开发者

Android - SQlite - Store null into a double field?

开发者 https://www.devze.com 2023-03-08 05:36 出处:网络
I am storing a double into a sqlite database. This value can be null, and I need to know whether the value is 0 or null.

I am storing a double into a sqlite database. This value can be null, and I need to know whether the value is 0 or null.

Is it possible to ach开发者_如何学Pythonieve this?

//grade is a type double in database
Double myValue =  cursor.getDouble(cursor.getColumnIndex("grade"));


To check for null use 'isNull(...)'...

Double myValue;
if (!cursor.isNull(cursor.getColumnIndex("grade"))
    myValue =  cursor.getDouble(cursor.getColumnIndex("grade"));
else
    // Handle null scenario


You could store it as a string and parse it on the way in and out.

0

精彩评论

暂无评论...
验证码 换一张
取 消