Bug? 1 <> 1?

alwaysbusy

Expert
Licensed User
Longtime User
will throw an error if dalinetype key does not exists, since at that point the map will return a Null String
Correct. In this case I knew it was an int and always exists as params with "...type" are always int in my programming ;-)

Would've been beter:
B4X:
Dim LineType As Int = m.GetDefault("dalinetype",0)

Alwaysbusy
 

Sandman

Expert
Licensed User
Longtime User
I feel very naïve here, but I'm also learning a lot so I feel I have to ask a couple of follow-ups.

1. You're sort of saying that the left side decides how the comparison should happen, and that the right side is cast'd to same type as left side, is that correct?

2. In your example above, is either "a" or 1 considered an object? Because if they're not, perhaps that example isn't relevant..?

3. I suspect this would cause a lot of problems that I can't foresee, but I have to ask: If both sides of the equality comparison are different types, wouldn't it make sense to just consider them different and return false, instead of crashing?

Update: Per Erels request below, I started a new thread for my follow-up questions: https://www.b4x.com/android/forum/t...et-expected-results-and-avoid-crashes.117088/
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Sorry for the delay, somehow I was not getting notifications for this thread.

Well, with a minimal program (Posted Below) I could not duplicate the problem either, I even tried throwing a couple of strings in the map as happens in the real code but it still worked.

Nevertheless I stand by my original statement. When you look at the watch expressions displayed in my original post:
B4X:
1 = 1 (0x1)

M.Get("Jr_Released") =  (0x1)

but

M.Get("Jr_Released") = 1 = False

That should NOT happen. If the Get doesn't know what it is then it should say so in the watch. Since we can't duplicate it we can't fix it but it is something to watch out for.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
   #AdditionalJar: sqlite-jdbc-3.7.2
    #AdditionalJar: mssql-jdbc-6.2.2.jre8.jar
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Public sql1 As SQL
    Public sql2 As SQL
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    sql1.InitializeSQLite("", ":memory:", True)
    sql1.ExecNonQuery("CREATE TABLE DATA (X  INTEGER)")
    sql1.ExecNonQuery("INSERT INTO DATA VALUES(1)")
    Dim rs As ResultSet = sql1.ExecQuery("SELECT X FROM DATA")
    Dim M As Map
    M.Initialize
    If rs.NextRow Then
        Log(rs.GetInt("X"))
        M.Put("X", rs.GetInt("X"))
        Log(M.Get("X") = 1)
        
    End If
    'sql1.InitializeAsync("Connect", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver:" & Srvr & ";databaseName=" & DB & ";user=" & UID & ";password=" & PWD & ";", UID, PWD)
    sql2.InitializeAsync("Connect", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver:" & "//XXXX" & ";databaseName=" & "XXXX"    & ";user=" & "XXXX" & ";password=" & "XXXX" & ";", "XXXX", "XXXX")
    
End Sub


Sub Connect_Ready (Success As Boolean)

    If Success  Then
        Log("Successs")
        sql2.ExecQuery("SELECT TOP 1 Jr_Released FROM JobRelease")
        Dim SenderFilter As Object = sql2.ExecQueryAsync("UnSchedOps", "SELECT TOP 1 Jr_Released, Jr_MasterType, Jr_JobNum FROM JobRelease WHERE Jr_Released  = 1;",   Null)   '1/30/19 - Added SW57
        Wait For (SenderFilter) UnSchedOps_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
        Dim M As Map
        M.Initialize
        If Crsr.NextRow Then
            Log(Crsr.GetInt("Jr_Released"))
            M.Put("Jr_JobNum", Crsr.GetString("Jr_JobNum"))
            M.Put("Jr_Released", Crsr.GetInt("Jr_Released"))
            M.Put("Jr_MasterType", Crsr.GetString("Jr_MasterType"))
            Log(M.Get("Jr_Released") = 1)
            
        End If
    End If
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
That should NOT happen.
It is a difficult problem to explain but it happens in the jdbc driver. This is why you are unable to reproduce it.

More importantly there is a new warning on this line (in B4J v8.30 and in the next versions of B4A and B4i):
B4X:
 Log(M.Get("Jr_Released") = 1)
Fix the warning and it will work as you expect.
 

MrKim

Well-Known Member
Licensed User
Longtime User
I'm sorry but this is not the place for this important discussion. @MrKim should post the full code and hopefully a small project that demonstrates it.

Start a new thread and I'll explain.
I missed the part about the full code - to big to post but I will post the relevant parts, perhaps someone will see where I botched things up. Note that the relevant line 115 has been fixed by doing as Erel suggested
I'm sorry but this is not the place for this important discussion. @MrKim should post the full code and hopefully a small project that demonstrates it.

Start a new thread and I'll explain.

. I put '1 = Map.Get...' rather than 'Map.Get = 1'


B4X:
Sub LoadJobs
    
    Sleep(1)
    Dim Li As List
    Li.Initialize2(Array(Main.SetUpUnitDivisor, Main.RunUnitDivisor, Main.ActiveWC, Main.ActiveWC))
    Dim SQLStr As String
    SQLStr = $"Select SchedMachines.SchM_Machine, [SchO_ID],  ScheduledOps.SchO_Order, FORMAT(Os_StartbyDate, 'MM/dd', 'en-US') AS Os_StartbyDate,Opstatus.Os_JobNum,Opstatus.Os_ReleaseNum,Opstatus.Os_SeqNum, SchedMachines.SchM_ID, SchedMachines.SchM_HrsPerWk,
            ScheduledOps.SchO_SchMTID,Opstatus.Os_WCCode,Opstatus.Os_FinishbyDate,Opstatus.Os_ID, Jobs.Jb_Part_Num, Jobs.Jb_Part_Rev, Jobs.Jb_Part_Desc, JobRelease.Jr_StartQty, SchedMachines.SchM_WCCode,
            SchedMachines.SchM_Group,Opstatus.Os_RunTime,Opstatus.Os_SetupTime,Opstatus.Os_HoursTodate, FORMAT((COALESCE(Os_SetupTime, 0) / ?) + ((COALESCE(Jr_StartQty, 1) * COALESCE(Os_RunTime, 0)) / ?), '0.0', 'en-us') BalHrs,Opstatus.Os_QtyToMake,Opstatus.Os_QtyTodate, SchedFirstDueDateQry.MinOfSh_Due_Date As FirstDueDate,
            JobShip.Sh_Note, SchedMachines.SchM_EmpAssignDayShift, SchedMachines.SchM_EmpAssignShift2, SchedMachines.SchM_EmpAssignShift3, SchedMachines.SchM_Cell, ScheduledOps.SchO_OSId,Opstatus.Os_Status,
            Opstatus.Os_Description, FORMAT(Jr_FirstDueDate, 'MM/dd', 'en-US') AS Jr_FirstDueDate,  --OpsByMachStatusCheckScheduleTemp.NewSchedStartDate, OpsByMachStatusCheckScheduleTemp.NewSchedFinishDate, OpsByMachStatusCheckScheduleTemp.OriginalStartbyDate,
            JobRelease.Jr_Released, Jobs.Jb_PO_Num
            FROM (((SchedMachines LEFT JOIN (ScheduledOps LEFT JOIN ((Opstatus LEFT JOIN Jobs ON Opstatus.Os_JobNum = Jobs.Jb_Job_Num)
            LEFT JOIN JobRelease ON (Opstatus.Os_ReleaseNum = JobRelease.Jr_ReleaseNum) And (Opstatus.Os_JobNum = JobRelease.Jr_JobNum)) ON ScheduledOps.SchO_OSId =Opstatus.Os_ID) ON SchedMachines.SchM_ID = ScheduledOps.SchO_SchMTID)
            LEFT JOIN (
            Select JobShip.Sh_Job_Num, CAST([Sh_Release_Num] As Int) As Rel, Min(JobShip.Sh_Due_Date) As MinOfSh_Due_Date, Max(JobShip.Sh_ID) As MaxOfSh_ID FROM JobShip WHERE (((JobShip.Sh_Qty_Shipped)=0 Or (JobShip.Sh_Qty_Shipped) Is Null))
            GROUP BY JobShip.Sh_Job_Num, Cast([Sh_Release_Num] As Int)
            ) SchedFirstDueDateQry ON (JobRelease.Jr_JobNum = SchedFirstDueDateQry.Sh_Job_Num) And (JobRelease.Jr_ReleaseNum = SchedFirstDueDateQry.Rel))
            LEFT JOIN JobShip ON SchedFirstDueDateQry.MaxOfSh_ID = JobShip.Sh_ID) --LEFT JOIN OpsByMachStatusCheckScheduleTemp ON (ScheduledOps.SchO_SchMTID = OpsByMachStatusCheckScheduleTemp.SchM_ID) And (ScheduledOps.SchO_Order = OpsByMachStatusCheckScheduleTemp.SchO_Order)
                WHERE (((SchedMachines.SchM_WCCode) Like ?) AND ((SchedMachines.SchM_Group) Like '%') AND ((SchedMachines.SchM_Cell)=0)
            And ((Opstatus.Os_Status)<>'C')) OR (((SchedMachines.SchM_WCCode) Like ?) AND ((SchedMachines.SchM_Group) Like '%') AND ((SchedMachines.SchM_Cell)=0) AND ((Opstatus.Os_Status) Is Null) AND ([SchO_ID] IS Not Null))
                ORDER BY SchedMachines.SchM_Machine, ScheduledOps.SchO_Order,Opstatus.Os_StartbyDate,Opstatus.Os_JobNum,Opstatus.Os_ReleaseNum,Opstatus.Os_SeqNum;"$
    Try
        Dim SenderFilter As Object = Main.sql1.ExecQueryAsync("WCMachinesJobs", SQLStr, Li)   '1/30/19 - Added SW57
        'Log(SQLStr)
        Wait For (SenderFilter) WCMachinesJobs_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
        Dim zx As Int, TTTTT As Long = DateTime.Now  'for testing
        If Success Then
            Sleep(1)
            Dim LV As ListView, P As B4XView
            LV.Initialize("")
            Dim TM As TextMetric
            TM.Initialize
            Do While Crsr.NextRow = True
                P = MachinesMap.Get(Crsr.GetString("SchM_Machine"))
                Dim T As TextArea, M As Map
                DADMod.FillJobMap(Crsr, M, False)
                T.Initialize("JobsTA")
                T.Editable = False
                LoadOpData(T, M)


                TM = ScheduleMod.MeasureText(T.Text, fx.DefaultFont(15))
                T.PrefWidth = TM.Width + 3dip  ' add dips for the vert scrollbar so we don't get a vert scrollbar
                T.PrefHeight = 50
                LV = P.GetView(1)
                LV.Items.Add(T)
                M.Put("ListView", LV)
                T.Tag = M
                T.TooltipText = Crsr.GetInt("SchO_ID")
                MoveMachine2.MakeDragSource(T, "MToMMoveS")
                MoveMachine2.MakeDragTarget(T, "MToMMoveT")
                zx=zx+1 'for testing
            Loop
            Log("Ops: " & ((DateTime.Now - TTTTT) / 1000) & " Seconds  " & zx & " Records")
            Sleep(1)
            ResizeLists(MachinesFrm.RootPane.Width)
            Loading = False
        Else
            Main.Msgbox.Show(LastException & CRLF & CRLF & SQLStr, "LoadJobs")
            Log(SQLStr)
        End If
    Catch
        Main.Msgbox.Show(LastException, "LoadJobs")
    End Try
    
End Sub



Sub FillJobMap(Crsr As JdbcResultSet, M As Map, Update As Boolean)
    If Not(M.IsInitialized) Then M.Initialize
    M.Put("Type", "JobData")
    M.Put("SchO_Order", Crsr.GetString("SchO_Order"))
    M.Put("SchO_OSId", Crsr.GetString("SchO_OSId"))
    M.Put("SchO_SchMTID", Crsr.GetString("SchM_ID"))
    M.Put("SchO_ID", Crsr.GetString("SchO_ID"))
    M.Put("SchM_Machine", Crsr.GetString("SchM_Machine"))
    M.Put("SchM_HrsPerWk", Crsr.GetString("SchM_HrsPerWk"))
    M.Put("SchM_ID", Crsr.GetLong("SchM_ID"))
    If Update Then Return
    M.Put("Os_JobNum", Crsr.GetString("Os_JobNum"))
    M.Put("Os_ReleaseNum", Crsr.GetString("Os_ReleaseNum"))
    M.Put("Os_SeqNum", Crsr.GetString("Os_SeqNum"))
    M.Put("Os_StartbyDate", Crsr.GetString("Os_StartbyDate"))
    M.Put("Os_FinishbyDate", Crsr.GetString("Os_FinishbyDate"))
    M.Put("Os_WCCode", Crsr.GetString("Os_WCCode"))
    M.Put("Os_ID", Crsr.GetLong("Os_ID"))
    M.Put("Os_RunTime", Crsr.GetString("Os_RunTime"))
    M.Put("Os_SetupTime", Crsr.GetString("Os_SetupTime"))
    M.Put("Os_HoursTodate", Crsr.GetString("Os_HoursTodate"))
    M.Put("Os_QtyToMake", Crsr.GetString("Os_QtyToMake"))
    M.Put("Os_QtyTodate", Crsr.GetString("Os_QtyTodate"))
    M.Put("Jb_Part_Num", Crsr.GetString("Jb_Part_Num"))
    M.Put("Jb_Part_Rev", Crsr.GetString("Jb_Part_Rev"))
    M.Put("Jb_Part_Desc", Crsr.GetString("Jb_Part_Desc"))
    M.Put("Jr_FirstDueDate", Crsr.GetString("Jr_FirstDueDate"))
    M.Put("BalHrs", Crsr.GetString("BalHrs"))
    M.Put("Os_Description", Crsr.GetString("Os_Description"))
    M.Put("Jr_Released", Crsr.GetInt("Jr_Released"))
    M.Put("Jb_PO_Num", Crsr.GetString("Jb_PO_Num"))
    
End Sub


Sub LoadOpData(T As TextArea, M As Map)
    
    T.Style = ";-fx-control-inner-background:rgba(95,158,160,.2)"
    SB.Initialize
    SB.Append(M.Get("Jb_Part_Num")).Append(CRLF).Append(M.Get("Os_JobNum")).Append(" Rel ").Append(M.Get("Os_ReleaseNum"))
    SB.Append("Seq ").Append(M.Get("Os_SeqNum")).Append(CRLF).Append(M.Get("Os_StartbyDate")).Append(" Qty:").Append(M.Get("Os_QtyToMake"))
    SB.Append(" Hr:").Append(M.Get("BalHrs")).Append(CRLF).Append(M.Get("Os_Description")).Append(CRLF).Append("NextDue:")
    SB.Append(M.Get("Jr_FirstDueDate")).Append(CRLF)
    
    If 1 = M.Get("Jr_Released") Then
        'Log("Inside True")
        SB.Append("HOT")
        T.Style = ";-fx-control-inner-background:rgba(255,93,84,1)"
    Else
        'Log("Inside False")
        SB.Append("PO:").Append(M.Get("Jb_PO_Num"))
    End If
    T.Text = SB.ToString
    'Log("Jr_Released = " & M.Get("Jr_Released"))

End Sub
 

MrKim

Well-Known Member
Licensed User
Longtime User
It is a difficult problem to explain but it happens in the jdbc driver. This is why you are unable to reproduce it.

More importantly there is a new warning on this line (in B4J v8.30 and in the next versions of B4A and B4i):
B4X:
Log(M.Get("Jr_Released") = 1)
Fix the warning and it will work as you expect.
Thanks so much for taking the time to go through this. Really appreciate it.
I had a hunch it might be something to do with the driver - not something you can control.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
If 1 = M.Get("Jr_Released") Then

Does this line fail?
No, as you said, putting the 1 before the Get solved the problem. Again, I am sorry I didn't respond sooner. Somehow notifications for this thread got dropped and I moved on...
 
Top