Android Question How to update SQL

Scantech

Well-Known Member
Licensed User
Longtime User
How do i update the SQL in starter service for Samsung s10+.

The code here works in emulator (Android 9 and 10) without any problem. But my samsung S10+ (Andorid 10) will not work? The B4XTable gets updated on both android emulator and Samsung s10+, but not with Starter.SQL1 on Samsung s10+. Basically I can't update Samsung s10+ database with starter.sql1.
B4X:
            Starter.SQL1.ExecNonQuery2("UPDATE diagnosticlog SET RO = ?, Date = ?, FirstName = ?, LastName = ?, VIN = ?, Year = ?, Make = ?, Model = ?, FileName = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))

My codes as follow
B4X:
Sub btnEdit_Click

    Try
        Dim RowId As Long = GetRowId(Sender)
        Dim Item As Map = B4XTable1.GetRow(RowId)

        Dim WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename As String

        'Get the b4xtable values and store it in variable
        WhatRo = Item.GetDefault("RO", "")
        WhatDate = Item.GetDefault("Date", "")
        WhatFirstName = Item.GetDefault("First Name", "")
        WhatLastName = Item.GetDefault("Last Name", "")
        WhatVin = Item.GetDefault("VIN", "")
        WhatYear = Item.GetDefault("Year", "")
        WhatMake = Item.GetDefault("Make", "")
        WhatModel = Item.GetDefault("Model", "")
        WhatFilename = Item.GetDefault("File Name", "")

'        Private Query As String
'        Private Cursor1 As Cursor
'
'        'first we check if the entry already does exist
'        Query = "SELECT * FROM diagnosticlog WHERE RO = ? AND Date = ? AND FirstName = ? AND LastName = ? AND VIN = ? AND Year = ? AND Make = ? AND Model = ? AND FileName = ?"
'        Cursor1 = Starter.SQL1.ExecQuery2(Query, Array As String (WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename))
'
'        If Cursor1.RowCount > 0 Then
'            Log("yes")
'        End If

        'Set the maps with the coloumn values from b4xtable
        Dim Options1 As Map
        Options1.Initialize
        Options1.Put("WhatRO", WhatRo)
        Options1.Put("WhatFirstName", WhatFirstName)
        Options1.Put("WhatLastName", WhatLastName)
        Options1.Put("WhatVin", WhatVin)
        Options1.Put("WhatYear", WhatYear)
        Options1.Put("WhatMake", WhatMake)
        Options1.Put("WhatModel", WhatModel)
       
        Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
        If Result = xui.DialogResponse_Positive Then
            'Get the updated maps
            WhatRo = Options1.GetDefault("WhatRO", "")
            WhatFirstName = Options1.GetDefault("WhatFirstName", "")
            WhatLastName = Options1.GetDefault("WhatLastName", "")
            WhatVin = Options1.GetDefault("WhatVin", "")
            WhatYear = Options1.GetDefault("WhatYear", "")
            WhatMake = Options1.GetDefault("WhatMake", "")
            WhatModel = Options1.GetDefault("WhatModel", "")
   
            'Update the Start SQL (Main one used)
            Starter.SQL1.ExecNonQuery2("UPDATE diagnosticlog SET RO = ?, Date = ?, FirstName = ?, LastName = ?, VIN = ?, Year = ?, Make = ?, Model = ?, FileName = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))

            'Update the B4xTable just for viewing only
            B4XTable1.SQL1.ExecNonQuery2("UPDATE data SET c2 = ?, c3 = ?, c4 = ?, c5 = ?, c6 = ?, c7 = ?, c8 = ?, c9 = ?, c10 = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
            B4XTable1.Refresh
'            B4XTable1.UpdateTableCounters

'            Cursor1.Close
   
            'Update the File
            Dim TempFileName As String
            Dim WhatPath As String
   
            If WhatFilename.Length > 1 Then
                If WhatFilename.SubString2(0,1) = "*" Then
                    TempFileName = WhatFilename.SubString(1)
                    WhatPath = File.DirRootExternal
                Else
                    TempFileName = WhatFilename
                    WhatPath = File.DirInternal
                End If
            End If
   
            'Init map to file
            Dim Map1 As Map
            Map1.Initialize
            File.ReadMap2(WhatPath, Starter.DiagReportDir2 & TempFileName, Map1)
   
            'Date and Filename cannot be changed

            'Update the map with lastest info from b4xpreference
            Map1.Put("Date", WhatDate)
            Map1.Put("RO", WhatRo)
            Map1.Put("FirstName", WhatFirstName)
            Map1.Put("LastName", WhatLastName)
            Map1.Put("Vin", WhatVin)
            Map1.Put("Year", WhatYear)
            Map1.Put("Make", WhatMake)
            Map1.Put("Model", WhatModel)
               
            'Write the updated map values to the file
            If File.Exists(WhatPath, Starter.DiagReportDir2 & TempFileName) Then
                File.Delete(WhatPath, Starter.DiagReportDir2 & TempFileName)
            End If
            File.WriteMap(WhatPath, Starter.DiagReportDir2 & TempFileName, Map1)    '.cdl

        End If

    Catch
        Msgbox2Async("The following error occurred" & Chr(10) & Chr(10) & LastException.Message, "Database Edit Error", "OK", "", "", LoadBitmap(File.DirAssets, "disclaimer.png"), True)
    End Try
End Sub
 
Last edited:

Myr0n

Active Member
Licensed User
Longtime User
Try changing "Array As String" by "Array As Object"

SQL:
SQL1.ExecNonQuery2("UPDATE diagnosticlog SET RO = ?, Date = ?, FirstName = ?, LastName = ?, VIN = ?, Year = ?, Make = ?, Model = ?, FileName = ? WHERE rowid = ?", Array As Object(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
How do i update the SQL in starter service for Samsung s10+.
Put Sleep(0) where I show you in the code. It will work: I have S10e and it worked for me
B4X:
Starter.SQL1.ExecNonQuery2("UPDATE diagnosticlog SET RO = ?, Date = ?, FirstName = ?, LastName = ?, VIN = ?, Year = ?, Make = ?, Model = ?, FileName = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
Sleep(0)
            'Update the B4xTable just for viewing only
            B4XTable1.SQL1.ExecNonQuery2("UPDATE data SET c2 = ?, c3 = ?, c4 = ?, c5 = ?, c6 = ?, c7 = ?, c8 = ?, c9 = ?, c10 = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
            B4XTable1.Refresh
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Sleep(0) did not work and Array As Object did not work either. I even increased to Sleep(100) and no good. Hopefully Erel can help. Its strange it works with other phones but not samsung s10+.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I deleted the .db and .db_journal files and added new database. Now its working OK. I have no idea why the old db files cannot be updated but I can delete and insert.
 
Upvote 0
Top