I have been using sqlite+record-macros in hashlink, I had constantly segfaults, since hashlink doesn’t give stacktraces on some errors, I didn’t knew whay this happens.
I tried to restructure my application and use message passing where possible, but it didn’t helped.
For debugging I switched to hxcs where I can get better stacktraces, now I can see the AccessViolations happening within Sqlite
Per this document SQLite CVSTrac. Sqlite can support multple threads if I am using a connection per thread.
Is possible to give record macros a connection factory function, and it should open a connection per thread in a thread local variable?
Any suggestion ideas?
I tried my luck by extending the Manger class, however it doesn’t seem to work well with the macros.
import cs.system.threading.ThreadLocal_1;
class ThreadSafeMgr<T:sys.db.Object> extends sys.db.Manager<T> {
static var cnx_factory:Void->Connection;
static var cnx:ThreadLocal_1<Connection>;
public override function getCnx():sys.db.Connection {
if (!cnx.IsValueCreated){
cnx=new ThreadLocal_1(cnx_factory);
}
return cnx.Value;
}
}
Errors on my consuming classes
ThreadSafeMgr.hx:3: characters 21-22 : Table is missing unique id, use either SId, SUId, SBigID or @:id
Sweeper.hx:75: characters 29-35 : Unknown database field 'stamp'
Sweeper.hx:76: characters 31-37 : Unknown database field 'stamp'
SweepEmails.hx:20: characters 65-69 : No database field 'json_invalid'
SweepEmails.hx:21: characters 14-24 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
Sweeper.hx:121: characters 63-68 : Unknown database field
Sweeper.hx:202: characters 43-46 : Unknown database field 'id'
All my tables have the SId field and are working perfect with standard Manager class