B4J Question B4XTable - null once again rears it's ugly head

MrKim

Well-Known Member
Licensed User
Longtime User
I am populating a B4XTable with data from SQL server. I have found - at least with text data columns, if a value of null is returned from SQL then that column in the B4XTable is not cleared when you page through the data, it retains whatever value was on the previous page. It should be blank, or at the very least contain 'null'. This is a subtle bug that can lead to some very misleading results.
I have solved the problem by testing for null and replacing it with a zero length string before populating the B4XTable.
My code looks like this, except I have NZ'd the nullable columns to solve the problem for now.

B4X:
        Do While Crsr.NextRow = True
            Dim M As Map
            M.Initialize
            M.Put("Os_JobNum", Crsr.GetString("Os_JobNum"))
            M.Put("Os_ReleaseNum", Crsr.GetString("Os_ReleaseNum"))
            M.Put("Os_SeqNum", Crsr.GetInt("Os_SeqNum"))
            M.Put("Os_WCCode", Crsr.GetString("Os_WCCode"))
            M.Put("Os_ID", Crsr.GetInt("Os_ID"))
            M.Put("Os_StartbyDate", Crsr.GetString("Os_StartbyDate"))
            M.Put("Scheduled", False)
            'need an extra item in the array for the picture column that is the ""
            data.Add(Array(Crsr.GetString("Pmp_PictureName"), "", Crsr.GetInt("Os_ID"), DateTime.DateParse(Crsr.GetString("Os_StartbyDate")), Crsr.GetString("Os_JobNum"), _
            Crsr.GetInt("Os_ReleaseNum"), DADMod.NZ(Crsr.GetString("Jb_Status"), ""), DADMod.NZ(Crsr.GetString("Jb_Status2"), ""), DADMod.NZ(Crsr.GetString("Jb_Status3"), ""), DADMod.NZ(Crsr.GetString("Jb_Planner"), "") _
            , Crsr.GetInt("Os_SeqNum"), Crsr.GetString("Jb_Part_Num"), Crsr.GetString("Jb_ItemNum"), DADMod.NZ(Crsr.GetString("Os_ProcessCode"), "") _
            , Crsr.GetDouble("Hours"), Crsr.GetString("Os_FinishbyDate"), Crsr.GetString("Jr_FirstDueDate"), Crsr.GetString("Customer") _
            , Crsr.GetInt("Jr_SchedulePriority"), DADMod.NZ(Crsr.GetString("Os_Note"), ""), Crsr.GetString("Jr_Released") _
            ))
            Log(Crsr.GetString("Os_JobNum") & "  " & Crsr.GetString("Jb_Status2"))
            zx=zx+1
            If zx = 12 Then
            Sleep(0)  'forces view of what is loaded so far
            End If
            'Sleep(1)
        Loop
'        Log("Data: " & data)
        Log("UnschOps: " & ((DateTime.Now - TTTTT) / 1000) & " Seconds  " & zx & " Records")
        Crsr.Close
        UnSchedOpsList.SetData(data)
        UnSchedOpsList.RefreshNow
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is a bad idea to pass real nulls as string values. The correct solution is to modify the query and to convert the nulls to whatever you need.

With that said, I'm unable to reproduce the behavior you describe. I'm using this code to create a null string (null strings are not something that is expected):
B4X:
Dim row() As Object = data.Get(0)
row(1) = CallSub2(Me, "CreateNullString", Null)

Sub CreateNullString(s As String) As String
    Return s
End Sub
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Yes, I am just used to using system that throw an error when you try to set a sting to a null.

This is my bad :mad::mad::mad:I have modified B4XTable and it was my mod that caused the problem.
Even worse, the modification was my attempt to handle nulls.
Sorry I wasted your time.
 
Upvote 0
Top