B4J Question ExecuteTableView issue

hakha4

Member
Licensed User
Longtime User
I wan't to select a record from one TableView and put in a temporary TableView but code below returns zero records. Values in Row(1) and in Row(2) matches an existing record in log and one record in the second Tableview would be expected.

B4X:
Sub tw_devices_SelectedRowChanged(Index As Int, Row() As Object)
    Dim tmpSQL As String
    Dim tmpDevice_id As String = Row(1)
    Dim tmpDevice_no As String = Row(2)
    
    'put last selected row in tw_temp
    'check if IR or RF
    Log(send_type)
    Log( tmpDevice_id)
    Log(tmpDevice_no)
    tw_temp.Items.Clear
    
    Select Case send_type
        Case "IR"
            'ToDo when Select works!
            
        Case "RF"   
            tmpSQL = "SELECT * FROM RF_codes WHERE Device_id = ? AND Device_no = ?"
            
            Log(tmpSQL)
            
            DBUtils.ExecuteTableView(SQL1, tmpSQL,Array As String (tmpDevice_id,tmpDevice_no), 0, tw_temp)
            Log(tw_temp.Items.Size)
            
            
    End Select
    Dim w As Int = Round(tw_temp.Width / tw_temp.ColumnsCount)
    For i = 0 To tw_temp.ColumnsCount - 1
    tw_temp.SetColumnWidth(i, w)
    Next

    
    End Sub

Can someone give me a hint what I am missing ?
Regards Håkan
 

hakha4

Member
Licensed User
Longtime User
Output is zero.
After hours of struggle I've finally worked out what's wrong. I need to save id's as two chars like '01'..'13' etc. for a more straight parsing of data later. The problem is that SqlLite studio (3.1.1) wont accept a zero to be saved as text ('01' is saved as '1'). So I have saved data as BLOB and that seems to be the problem. Id's like '01' works ok but id's like 12 returns no record's.
I've googled why zeros can't be saved as text but no straight answers, so I either have to deal with the parsing routine or but better would be if numbers could be saved the way I wan't. The odd thing is that when I change fields to TEXT from BLOB in the table the zeros are there ?! in the old records and my routine works, returning correct record, but any new records added is saved without as before. Any idea for a workaround?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
How are you inserting the values in the database?

I tried a text field and it does retain the leading zero, providing the value is quoted.
ie,
B4X:
' theField is defined as type TEXT
Insert into myTable theField Values(01)   ' this will result in just 1 being stored its a number > string (loses leading zero)
...
Insert into myTable theField Values('01')  ' this will retain 01 as the value as it's explicitly a string
 
Upvote 0

hakha4

Member
Licensed User
Longtime User
You are correct. When testing I had records that was manually inserted in Sqlite Studio. And it is this program that makes funny stuff . Inserting from code works ok . Thank's all for help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…