SQLite Conversion

Help please. This is waaay beyond my expertise.
Starting with I have checked for errors, nils and everything else:

  1. The years old program with the following code using REAL database works fine.

  2. Same code with same REAL database after specifying SQLite works fine.

  3. Create a new database with SQLite, code fails (on first record) after db.InsertRecord(“AntList”,r) statement and never gets to the db.Error statement.

     .....  (inp is a text file, r is a DatabaseRecord, AntList is a table)
     r.column("Manuf") = s
     r.column("LowMHz") = strip(inp.ReadLine)
     r.column("HiMHz") = strip(inp.ReadLine)
     r.column("MaxGaindBd") = strip(inp.ReadLine)
     r.column("AvailPol") = strip(inp.ReadLine)
     r.column("AntPol") = strip(inp.ReadLine)
     r.column("HhpbwDeg") = strip(inp.ReadLine)
     r.column("VhpbwDeg") = strip(inp.ReadLine)
     r.column("PatMHz") = strip(inp.ReadLine)
     if db.Error then
       msgbox "Error GARALoop  - Don't know what to do."

Here is an excerpt of the error code.

Process: Obspat.debug [2232]
Path: /Obspat Security/Obspat.debug.app/Contents/MacOS/Obspat.debug
Identifier: ???
Version: ??? (
Code Type: X86 (Native)
Parent Process: launchd [145]
Responsible: Obspat.debug [2232]
User ID: 501

Date/Time: 2014-07-21 13:46:10.041 -0400
OS Version: Mac OS X 10.9.4 (13E28)
Report Version: 11
Anonymous UUID: 99294CED-C2AC-0BB5-6EBC-8B5D079557A9

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000

VM Regions Near 0:
–> __PAGEZERO 0000000000000000-0000000000001000 [ 4K] —/--- SM=NUL /Obspat Security/Obspat.debug.app/Contents/MacOS/Obspat.debug
__TEXT 0000000000001000-0000000000618000 [ 6236K] r-x/rwx SM=COW /Obspat Security/Obspat.debug.app/Contents/MacOS/Obspat.debug

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 RBSQLiteDatabase.xojo_plugin_0.dylib 0x05905d88 0x5900000 + 23944
1 rbframework.dylib 0x00727bd8 databaseInsertRecord + 72
2 Obspat.debug 0x00039555 Database.InsertRecord%%oso + 68
3 Obspat.debug 0x004806e0 wRebuild.wRebuild.GoAnt%%o<wRebuild.wRebuild> + 18601
4 Obspat.debug 0x0048841f wRebuild.wRebuild.init%b%o<wRebuild.wRebuild>o + 607
5 Obspat.debug 0x00576827 wBack.wBack.init%%o<wBack.wBack> + 139
6 Obspat.debug 0x00435d99 GlobalConstants_Methods.LoadContextMenu + 5573
7 Obspat.debug 0x00425020 GlobalConstants_Methods.GetPutPrefs%%b + 37865
8 Obspat.debug 0x001e0f82 App.Event_Open%%o + 481
9 rbframework.dylib 0x006ef2d5 0x69a000 + 348885
10 Obspat.debug 0x00009b5b Delegate.Invoke%% + 34
11 Obspat.debug 0x0008828a Application._CallFunctionWithExceptionHandling%%op + 248
12 rbframework.dylib 0x007227d4 0x69a000 + 559060
13 rbframework.dylib 0x006eda22 0x69a000 + 342562
14 Obspat.debug 0x0019bb6c REALbasic._RuntimeRegisterAppObject%%o + 48
15 Obspat.debug 0x000031fb _NewAppInstance + 264
16 Obspat.debug 0x000097f3 _EarlyStartup + 100
17 Obspat.debug 0x0000995e _Main + 153
18 Obspat.debug 0x0000253c % main + 36
19 Obspat.debug 0x005e10de _start + 116
20 Obspat.debug 0x005e1034 start + 43

Thread 1:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x99967992 kevent64 + 10
1 libdispatch.dylib 0x999e6899 _dispatch_mgr_invoke + 238
2 libdispatch.dylib 0x999e6532 _dispatch_mgr_thread + 52

Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x0098fe30 ebx: 0x00000000 ecx: 0x00000000 edx: 0x05900fae
edi: 0x00000005 esi: 0x00000002 ebp: 0xbfffd398 esp: 0xbfffd310
ss: 0x00000023 efl: 0x00010282 eip: 0x05905d88 cs: 0x0000001b
ds: 0x00000023 es: 0x00000023 fs: 0x00000000 gs: 0x0000000f
cr2: 0x00000000

Logical CPU: 2
Error Code: 0x00000004
Trap Number: 14

But did you create a NEW TABLE as well?

Dave, Thanks

My create db method creates the new database followed by the two tables it contains. Each operation checks for a db.error. The first row of each table is also inserted using an ‘Insert into …’ and db.execute() statement. I assume (hope) the db.error checks would warn if there were errors.

Don’t know if this will help, but here are 2 common mistakes:

  1. Failing to Commit the changes after you create the tables.
  2. Using a local variable in the create db method.

The old RealSQLDatabase automatically managed rowid’s. Maybe is something related to it.

My guess: Does the text file have that many lines?

Try putting a breakpoint before doing any database work, and step one line at a time until it crashes. It may not tell you the database error, but at least you’ll get an idea of what’s causing it to crash.

Thank you gentlemen.

Tim H - 1. Commit needs to be paired with transactions, I believe. I do not use transactions, maybe I should???
2. My db variable is global and is not nil.

Rick A. - I do not directly access rowid’s (to my knowledge). I just load the database sequentially.

Tim P - I do not understand your suggestion. In my context, the database is created and the first record is written which contains text in three of ten varchar columns. The first row is always used for housekeeping data (indexes, etc.). All rows beyond the first row are standard text data.

I was referring to strip(inp.ReadLine) which I would think wouldn’t be too happy if the input file had say 4 lines.

My suggestion however is to use a breakpoint right before any database work so you can step, one command a time, until it crashes. Then you’ll know what line caused the issue.

Is this a Carbon app? Does it work with Cocoa? There is an issue with SQLiteDatabase on Carbon in 2014r2 which is fixed for r2.1 (in beta testing).

Tim P - Thanks. I know precisely where things go awry. At the statement: db.InsertRecord(“AntList”,r)
This is after I load DatabaseRecord r from the files which I created using single line strings.

Paul L - Thanks. I am not certain if I am using carbon or cocoa. This program originated on carbon. I currently develop using OSX 10.9.4. I do remember seeing the option for compiling w/cocoa using carbon. But, I don’t know how to tell which system I am developing with now. I guess it is sort of dumb, but also attests to the fluidity of Xojo. It just works.

In the Navigator, click on “OS X” in the “Build Settings” section. In the Inspector, look at what is selected for the Framework property.

You need to commit any schema commands. I realize that Paul has put his finger on the reason for the crash, but once you get past that, you will likely run into the commit and rowid issues.

Paul L - Thanks. I am using cocoa.

Tim H - Thanks, I have assumed that Schema operations have to do with essentially everything excluding data (values of columns).
I have attempted to do a db.commit after everything (new database, new table, etc). I also tried db.commit after InsertRecord. Is that required?

You only need to commit when you change data within an explicit transaction (sqlexecute(“Begin Transaction”)). But you do need to commit when you alter table structure.

And in case it wasn’t already clear, nothing anyone except Paul has brought up would account for a crash. Everything else we’ve said would result in an error or missing data, but not a crash.

I’m not doing this and have yet to experience a problem - what problems aren’t I seeing/ could bite me in the !#@$@!# (just typed this knew bum wouldn’t work :))

Try following code:
catch e as RunTimeException
MsgBox("Runtime Error: "+e.Message)
if db.Error then
MsgBox("DB Error: "+ db.ErrorMessage)
end if
end try

You can’t Catch a crash.

It’s only a try. If you cannot catch the error, report it to the XOJO-Feedback.

Owe some an apology. In the panic of having to get a job completed and, well, you know…
The project is indeed a Carbon endeavor. When I installed the update it crashed and so did I.
My bet now is that Paul has it nailed and the new SQLite version is the culprit. I am back with an earlier version of my program and back in business. I’ll just wait 'til the next release.

Thanks to all. This is my first foray into the Forum - and it seems great.

By the way Hannes, the Try-Catch did not catch anything. It just reverts to the OS. But, Thanks.