REAL or INTEGER column values from db that are NULL, getter returns 0.0 or 0
See original GitHub issueDBFlow Version: 4.0.3 Issue Kind (Bug, Question, Feature): Bug
Description: When I do a Select on a table with columns REAL or INTEGER that are nullable, if the row values are NULL for those columns when I call the getter for the values of those columns I get 0 by default instead of NULL. This issue only occurs to me after I migrated from dbflow 3.1.1 to 4.0.3.
Example Table:
@Table(name = "schedule_work",
database = ISDatabase.class,
primaryKeyConflict = ConflictAction.REPLACE,
insertConflict = ConflictAction.REPLACE,
updateConflict = ConflictAction.REPLACE)
public class ScheduleWork extends BaseModel {
@PrimaryKey
@Column(name = "schedule_work_id")
@SerializedName("schedule_work_id")
@Expose
private Integer scheduleWorkId;
@Column(name = "work_name")
@SerializedName("work_name")
@Expose
private String workName;
@Column(name = "failure_id")
@SerializedName("failure_id")
@Expose
private Integer failureId;
/**
* No args constructor for use in serialization
*/
public ScheduleWork() {
super();
}
/**
* @return The scheduleWorkId
*/
public Integer getScheduleWorkId() {
return scheduleWorkId;
}
/**
* @param scheduleWorkId The schedule_work_id
*/
public void setScheduleWorkId(Integer scheduleWorkId) {
this.scheduleWorkId = scheduleWorkId;
}
public ScheduleWork withScheduleWorkId(Integer scheduleWorkId) {
this.scheduleWorkId = scheduleWorkId;
return this;
}
/**
* @return The workName
*/
public String getWorkName() {
return workName;
}
/**
* @param workName The work_name
*/
public void setWorkName(String workName) {
this.workName = workName;
}
public ScheduleWork withWorkName(String workName) {
this.workName = workName;
return this;
}
public Integer getFailureId() {
return failureId;
}
public void setFailureId(Integer failureId) {
this.failureId = failureId;
}
}
The query:
new Select().from(ScheduleWork.class)
.where(ScheduleWork_Table.failure_id.withTable().isNull()).async()
.queryListResultCallback(callback).execute();
On the callback I call getFailureId() on an entry and I obtain 0 instead of null. Or just by doing:
List<ScheduleWork> swl = new Select().from(ScheduleWork.class)
.where(ScheduleWork_Table.failure_id.isNull()).queryList();
for(ScheduleWork sw : swl)
Log.e("Debug", "MY FAILURE_ID: "+sw.getFailureId());
I get the output: MY FAILURE_ID: 0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ResultSet.getFloat return 0 instead of NULL - Stack Overflow
Yes. You can call ResultSet.wasNull() which reports whether the last column read had a value of SQL NULL . Note that you must...
Read more >Keep default value as 0.0 for 0 or NULL for numeric column
I have a numeric column Number(28,3) in which I have to insert value as 0.0 , whenever I encounter 0 or NULL/blank at...
Read more >Get 0 from database with data type is numeric - OutSystems
How can i get data 0 from database field column with data type numeric,. because in OutSystems entity with data type numeric 0...
Read more >Database Engine events and errors - SQL Server
ls' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.
Read more >Inserting Null Into an Integer Column Using JDBC - Baeldung
It represents a special value. It's a common perception that null has no value or that it represents nothing. Having a null stored...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a good temporary solution while awaiting to fix it on DbFlow lib. developers side. I added four converters to avoid using standard functionality. It is also possible to use String in converters as db type but in this case is possible to face problem with Primary keys and default values.
fixed in
develop
. should be in 4.0.4