Android Question Close o not close DataBase SqLite always? and close or no a var CURSOR?

netsistemas

Active Member
Licensed User
Longtime User
i have some problems simil to this:

that is:
android.database.sqlite.sqlitediskioException: disk i/o error (code 522 sqlite_ioerr_short_read

the cause a read is by:
- No memory: https://stackoverflow.com/questions...kioexception-code-522-sqlite-ioerr-short-read
- No close cursor : https://www.b4x.com/android/forum/threads/sqlite-disk-io-error-1034.43530/

but i thing to do something like this:
B4X:
PUBLIC Sub SqLLocal_ExecNonQuery( ComandoSql As String)
    Try
        OpenDBLocal(False)
        SqLLocal.ExecNonQuery (ComandoSql)
        SqLLocal.Close
    Catch
        Log(LastException)
    End Try
End Sub

PUBLIC Sub SqLLocal_ExecNonQuery2( ComandoSql As String,Args As List )
    Try
        OpenDBLocal(False)
        SqLLocal.ExecNonQuery2 (ComandoSql,Args )
        SqLLocal.close
    Catch
        Log(LastException)
    End Try
End Sub

public Sub GetSqlLocal As SQL
    OpenDBLocal(False)
    Return SqLLocal 'this is a public var
End Sub


the question is: is good idea open - execute - and close database
or is better make open alway the database (now, i do this: always open. )

And other cuestion: is necesary to close the cursor if the var are definid into a sub (not in a public module)

(i use 3 database in my system), beacuse any database are download from dropbox, other as for job and to insert and send by dropbox, and other for control of device.)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is usually not needed to close the database at all, however if you want to backup or replace the database files then you should close it.

And other cuestion: is necesary to close the cursor if the var are definid into a sub (not in a public module)
It doesn't matter. Just make sure to close the ResultSets after they are no longer used.
 
Upvote 0
Top