iOS Question In B4i (v2.51) - ExecNonQuery error: cannot ATTACH database within transaction

Pendrush

Well-Known Member
Licensed User
Longtime User
I have app about 6 month old, now I want to update app and working code in previous b4i version, now won't work

B4X:
    If File.Exists(File.DirDocuments, "test1.db") = False Then
        File.Copy(File.DirAssets, "test1.db", File.DirDocuments, "test1.db")
    End If
  
    If File.Exists(File.DirDocuments, "test2.db") = False Then
        File.Copy(File.DirAssets, "test2.db", File.DirDocuments, "test2.db")
    End If
  
    Dim oSQL As SQL
    Dim cSQLAttach As String
    oSQL.Initialize(File.DirDocuments, "test1.db", False)
    cSQLAttach = "ATTACH DATABASE '" & File.DirDocuments & "test2.db' AS db2"
    oSQL.ExecNonQuery(cSQLAttach)

Error is on last line oSQL.ExecNonQuery(cSQLAttach)


Code was work in previous version of B4i.
I have also attach test project.

My question is: How to attach two databases in b4i v2.51?
Thank you in advance.

EDIT:
I'm using my own Mac
 

Attachments

  • test.zip
    1.5 KB · Views: 310

Pendrush

Well-Known Member
Licensed User
Longtime User
I'ts look like a bug in iSQL v1.30. After initialize database transaction is created and remain open I have try few things, but I'm unable to close it.
When i try this code
B4X:
cSQLAttach = "BEGIN; ATTACH DATABASE '" & File.DirDocuments & "test2.db' AS db2; END;"
returned error is:
ExecNonQuery error: cannot start a transaction within a transaction
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
ExecNonQuery starts a transaction if there is no active transaction. This change is related to the asynchronous methods.

You can use ExecQuery instead (make sure to close the ResultSet).

Another option which is equivalent to the old behavior of ExecNonQuery:
B4X:
Dim no As NativeObject = osql
no.RunMethod("ExecNonQueryInsideTransaction::", Array(cSQLAttach, Null))
 
Last edited:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
If I use ExecQuery then alias name (db2) does not exist in next INSERT statement. DB Error: 1 "no such table: db2.id"
NativeObject method work as expected.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…