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

Pendrush

Well-Known Member
Licensed 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)

Application_Start
Error calling sqlite3_step (1: cannot ATTACH database within transaction) SQLITE_ERROR
DB Query: ATTACH DATABASE '/var/mobile/Containers/Data/Application/E9E51494-A4DD-41FF-8F1B-4C2749D70692/Documents/test2.db' AS db2
Unknown error finalizing or resetting statement (1: cannot ATTACH database within transaction)
DB Query: ATTACH DATABASE '/var/mobile/Containers/Data/Application/E9E51494-A4DD-41FF-8F1B-4C2749D70692/Documents/test2.db' AS db2
Error occurred on line: 43 (Main)
ExecNonQuery error: cannot ATTACH database within transaction
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
B4i Example -[B4ISQL ExecNonQueryInsideTransaction::] + 592
B4i Example -[B4ISQL ExecNonQuery2::] + 200
B4i Example -[b4i_main _application_start:] + 5242
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
B4i Example -[B4IShell runMethod:] + 574
B4i Example -[B4IShell raiseEventImpl:method:args::] + 1998
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1442
B4i Example __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1532
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1590
CoreFoundation CFRunLoopRunSpecific + 516
CoreFoundation CFRunLoopRunInMode + 108
GraphicsServices GSEventRunModal + 160
UIKit UIApplicationMain + 144
B4i Example main + 108
libdyld.dylib <redacted> + 2
)
Application_Active
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
B4i Build Server
Build server is running.
Version: 2.51
Server time: 11:32:13
Mac SSL Key
Key IP: 192.168.1.240
SSL port: 51042
h files
  • iAd: 1.00
  • iAdMob: 1.30
  • iAnalytics: 1.0
  • iArchiver: 1.01
  • iBarcode: 1.20
  • iBLE: 1.40
  • iContacts: 1.00
  • iCore: 2.52
  • iDebug: 1.60
  • iDebug2: 1.60
  • iDesigner: 1.20
  • iDropboxSync: 1.00
  • iEncryption: 1.02
  • iGoogleMaps: 1.10
  • iHttp: 1.01
  • iHUD: 1.00
  • iJSON: 1.0
  • iLeadbolt: 2.00
  • iLocation: 1.20
  • iMedia: 1.21
  • iMQTT: 1.0
  • iNet: 1.20
  • iNetwork: 1.11
  • iPhone: 1.70
  • iRandomAccessFile: 1.50
  • iReleaseLogger: 1.00
  • iSideMenu: 1.01
  • iSQL: 1.30
  • iStore: 1.0
  • iStringUtils: 1.00
  • iSVG: 1.00
  • iTableView: 1.21
  • iUI8: 1.20
  • iWebSocket: 1.00
  • iXmlBuilder: 1.00
  • iXmlSax: 1.10
a files
  • libAppTracker, size=3933908, modified=09/17/2014 09:29:48
  • libCore, size=3507040, modified=02/28/2016 16:38:34
  • libGoogleAnalyticsServices, size=34153904, modified=11/12/2015 05:06:06
  • libiAd, size=36880, modified=02/22/2016 12:22:22
  • libiAdMob, size=68176, modified=02/22/2016 12:22:22
  • libiAnalytics, size=39504, modified=02/08/2016 14:49:24
  • libiArchiver, size=245120, modified=02/22/2016 12:22:22
  • libiBarcode, size=247568, modified=01/27/2016 15:12:28
  • libiBLE, size=145120, modified=03/16/2016 07:23:32
  • libiContacts, size=111512, modified=02/22/2016 14:07:24
  • libiDebug, size=1022464, modified=06/30/2015 06:15:48
  • libiDebug2, size=1077520, modified=02/22/2016 12:22:22
  • libiDesigner, size=846912, modified=02/22/2016 12:22:24
  • libiDropboxSync, size=80960, modified=02/22/2016 12:22:24
  • libiEncryption, size=67752, modified=02/22/2016 12:22:24
  • libiGoogleMaps, size=160616, modified=02/22/2016 12:22:24
  • libiHttp, size=121800, modified=02/22/2016 12:22:24
  • libiHUD, size=285496, modified=02/22/2016 12:22:24
  • libiJSON, size=53320, modified=02/22/2016 12:22:24
  • libiLeadbolt, size=21440, modified=02/22/2016 12:22:24
  • libiLocation, size=122192, modified=02/22/2016 12:22:24
  • libiMedia, size=254864, modified=02/07/2016 08:05:26
  • libiMQTT, size=1575592, modified=02/22/2016 12:22:24
  • libiNet, size=532392, modified=02/22/2016 12:22:24
  • libiNetwork, size=260272, modified=02/18/2016 16:53:34
  • libiPhone, size=294336, modified=02/23/2016 14:06:22
  • libiRandomAccessFile, size=385184, modified=02/22/2016 12:22:24
  • libiReleaseLogger, size=49976, modified=02/22/2016 12:22:24
  • libiSideMenu, size=504704, modified=02/22/2016 12:22:24
  • libiSQL, size=401008, modified=02/15/2016 11:55:44
  • libiStore, size=51224, modified=02/22/2016 12:22:24
  • libiStringUtils, size=55328, modified=02/22/2016 12:22:24
  • libiSVG, size=57360, modified=02/22/2016 12:22:24
  • libiTableView, size=194152, modified=02/22/2016 12:22:24
  • libiUI8, size=501424, modified=02/29/2016 09:36:58
  • libiWebSocket, size=391936, modified=02/22/2016 12:22:24
  • libiXmlBuilder, size=151200, modified=02/22/2016 12:22:24
  • libiXmlSax, size=61888, modified=02/22/2016 12:22:24
  • libLeadboltOverlay, size=3721828, modified=12/01/2014 11:03:42
 

Attachments

Pendrush

Well-Known Member
Licensed 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
 

Erel

Administrator
Staff member
Licensed 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:

Pendrush

Well-Known Member
Licensed 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.
 
Top