Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 83
Registered: ‎02-05-2012
My Device: PRIV
My Carrier: T-Mobile
Accepted Solution

SqlDataAccess Threading

I've been using SqlDataAccess to insert into / query from an SQLite database. Everything was working fine until I added Threads into the mix. Does anyone know if SqlDataAccess is threadsafe?

 

I see messages indicating that removeDatabase is being run when none of my code calls that:

 

Jan 9 09:54:14.352 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::removeDatabase: connection '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetScanner8e1fec
79/app/native/assets/Databases/NetScanner.sq3' is still in use, all queries will cease to work.
Jan 09 09:54:14.352 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::addDatabase: duplicate connection name '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetS
canner8e1fec79/app/native/assets/Databases/NetScanner.sq3', old connection removed.
Jan 09 09:54:14.411 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  Unsupported query type: 0
Jan 09 09:54:14.439 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  Unsupported query type: 0
Jan 09 09:54:14.524 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  Unsupported query type: 0
Jan 09 09:54:14.612 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::removeDatabase: connection '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetScanner8e1fec
79/app/native/assets/Databases/NetScanner.sq3' is still in use, all queries will cease to work.
Jan 09 09:54:14.612 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::addDatabase: duplicate connection name '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetS
canner8e1fec79/app/native/assets/Databases/NetScanner.sq3', old connection removed.
Jan 09 09:54:32.515 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default      0  LGM - The call to counters_register in LGMon failed at time = 786795746110662 ns with error -5.
Jan 09 09:54:44.845 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::removeDatabase: connection '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetScanner8e1fec
79/app/native/assets/Databases/NetScanner.sq3' is still in use, all queries will cease to work.
Jan 09 09:54:44.845 com.rubion.NetScanner.testDev__NetScanner8e1fec79.387170505              default   9000  QSqlDatabasePrivate::addDatabase: duplicate connection name '/accounts/1000/appdata/com.rubion.NetScanner.testDev__NetS
canner8e1fec79/app/native/assets/Databases/NetScanner.sq3', old connection removed.

 

The App hangs for a few seconds, then I see this in the console tab:

 

Process 387170505 (NetScanner) terminated SIGSEGV code=1 fltno=11 ip=781d71be(/base/usr/lib/qt4/lib/libQtSql.so.4.8.4@_ZN10QSqlResult19detachFromResultSetEv+0x9) mapaddr=000171be. ref=00000000 bdslot=1

 

Any ideas?

Developer
Posts: 87
Registered: ‎07-23-2009
My Device: Z30
My Carrier: XL

Re: SqlDataAccess Threading

afaik, it is not threadsafe; as workaround you can use sqlworker to query database, ie. 

m_pSqlWorker = new SqlWorker(databasepath, mConnectionName, this);
m_pSqlConnection = new SqlConnection(m_pSqlWorker, this);

 with different connection name for every different operation. 

 

cmiiw

Developer
Posts: 83
Registered: ‎02-05-2012
My Device: PRIV
My Carrier: T-Mobile

Re: SqlDataAccess Threading

Thanks for the tip!

Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: SqlDataAccess Threading


hakimrie wrote:

afaik, it is not threadsafe; as workaround you can use sqlworker to query database, ie. 

m_pSqlWorker = new SqlWorker(databasepath, mConnectionName, this);
m_pSqlConnection = new SqlConnection(m_pSqlWorker, this);

 with different connection name for every different operation. 

 

cmiiw


I'm running into a similar situation trying to add threading to an app that currently uses SqlDataAccess in the main thread. I tried your suggestion but I'm still getting SIGSEGV crashes. Reading the SqlWorker documentation it clearly states that SqlDataAccess is used in the background to access the actual database, so I don't think you'll find that SqlWorker solves the OP's problem.

 

I am in the process of switching to QSqlDatabase and QSqlQuery, which seems to be thread safe and doesn't clobber the SqlDataAccess in the main thread either.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: SqlDataAccess Threading

I have switched to QSql for quite some time, as i found not only threading issues but also performance problems when using SqlDataAccess.
With QSqlQuery you can use setForwardOnly(true) and get a much better select performance.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter