Android Question error while inserting record

Kiran Raotole

Active Member
Licensed User
I'm trying to download and insert record in sql
I'm inserting 250 records at a time with ExecNonQuery.
sometimes while inserting records show this log

Error occurred on line: 656 (all)
android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11 SQLITE_CORRUPT)
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:748)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1771)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1698)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery(SQL.java:74)
at com.ctron.mobile.all$ResumableSub_MoTrInsert.resume(all.java:2603)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1680)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

What should I do?
 

Kiran Raotole

Active Member
Licensed User
B4X:
    Dim sql_string,sql As String
    sql_string = "INSERT INTO GL " & _
                 "(fbook,faccode,fdesc,fplace,fitcu,fin1,ftype," & _
                 "famt,fq1,fq2,fq3,frate1,frate2,frate3,fgst1,fvat2,fnum1,fnum2,fnum3,fnum4,fnum5,fcamt,fcq1,fadd5,fadd6) VALUES "
    
    Dim sb As StringBuilder
    sb.Initialize
    
    Dim i,mbatch As Int
    i = 0
    Do While i <= record
        If i Mod 500 = 0 Then
            Sleep(0)
        End If
        
        sb.Remove(0,sb.Length)
        sb.Insert(0,sql_string)
        
        mbatch = i + 249
        Do While i <= mbatch And i <= record
            m = list1.Get(i)
        
            book         = m.Get("mbook")    '1
            accode         = m.Get("maccode")    '2
            desc         = m.Get("mdesc")    '3
            place        = m.Get("mplace")    '4
            itcu         = m.Get("mitcu")    '5
            in1          = m.Get("min1")        '6
            ftype         = m.Get("mtype")    '7
            amt            = m.Get("mamt")
            'amt          = Round2(m.Get("mamt"),2)        '8
            q1           = m.Get("mq1")        '9
            q2           = m.Get("mq2")        '10
            q3           = m.Get("mq3")        '11
            rate1          = m.Get("mrate1")    '12
            rate2        = m.Get("mrate2")    '13
            rate3        = m.Get("mrate3")    '14
            gst1         = m.Get("mgst1")    '15
            vat3         = m.Get("mvat3")    '16
            num1         = m.Get("mnum1")    '17
            num2         = m.Get("mnum2")    '18
            num3         = m.Get("mnum3")    '19
            num4         = m.Get("mnum4")    '20
            num5         = m.Get("mnum5")    '21
            camt         = m.Get("mcamt")    '22
            cq1         = m.Get("mcq1")        '23
            add5         = m.Get("madd5")    '24
            add6         = m.Get("madd6")    '25

            sb.Append($"(""$).Append(book).Append($"",""$).Append(accode).Append($"",""$)
            sb.Append(desc).Append($"",""$).Append(place).Append($"",""$)
            sb.Append(itcu).Append($"",""$).Append(in1).Append($"",""$)
            sb.Append(ftype).Append($"",""$).Append(amt).Append($"",""$)
            sb.Append(q1).Append($"",""$).Append(q2).Append($"",""$)
            sb.Append(q3).Append($"",""$).Append(rate1).Append($"",""$)
            sb.Append(rate2).Append($"",""$).Append(rate3).Append($"",""$)
            sb.Append(gst1).Append($"",""$).Append(vat3).Append($"",""$)
            sb.Append(num1).Append($"",""$).Append(num2).Append($"",""$)
            sb.Append(num3).Append($"",""$).Append(num4).Append($"",""$)
            sb.Append(num5).Append($"",""$).Append(camt).Append($"",""$)
            sb.Append(cq1).Append($"",""$).Append(add5).Append($"",""$)
            sb.Append(add6).Append($""),"$)
        
            i = i + 1
        Loop
        sql = sb.Remove(sb.Length-1,sb.Length).tostring
        year.ExecNonQuery(sql)
    Loop
 
Upvote 0

Kiran Raotole

Active Member
Licensed User
I'm using DButils insertmap
showing this error:

mo inserting
java.lang.RuntimeException: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1682)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:748)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1771)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1698)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery(SQL.java:74)
at com.ctron.mobile.all$ResumableSub_MoInsert1.resume(all.java:1972)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1680)
... 7 more
*** Service (starter) Create ***
** Service (starter) Start **
 
Upvote 0

OliverA

Expert
Licensed User
Make a test app that reproduces your issues and post it or post the minimum code (all) that reproduces the issue. Right now, shooting from the hip, you are opening the DB more than once. DBUtils does not do that on its own. But I'm just guessing here and more code or a sample project are necessary to figure this one out.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
I'm using DButils insertmap
showing this error:

mo inserting
java.lang.RuntimeException: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1682)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:748)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1771)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1698)
at anywheresoftware.b4a.sql.SQL.ExecNonQuery(SQL.java:74)
at com.ctron.mobile.all$ResumableSub_MoInsert1.resume(all.java:1972)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1680)
... 7 more
*** Service (starter) Create ***
** Service (starter) Start **
Is this a different question to the one you originally posted? If so, you should start a new thread. If not, then as Erel said there are a lot of things wrong with the code you posted.

It's very hard to help you without the relevant code that is causing the issue, or ideally the entire project zipped up & added to your post.

Hint: If you are inserting multiple records in a loop, you'd be better off using a transaction. It will execute faster & will also stop conflicts happening if your loop is faster than the query can complete.

- Colin.
 
Upvote 0
Top