Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » SQLite-insert/update in threads (please help!)
SQLite-insert/update in threads (please help!) [message #27212] Fri, 02 July 2010 21:24 Go to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

I'm getting asserts of Fetch and Execute methods, sometimes. I don't know how to avoid them, but threads are really needed.

Some info about task:
- Console application.
- Main loop of program - RPC-server, with functions for user (each of functions use SQLite database, through global SQL)
- Threads registers incoming hardware events and writes them into the SQLite database.

How can I make this task threadsafe?
Please help, two days of experiments, but I have no ideas.

I'll glad to see a little codesnippet with one safe thread.


P.S. Application crashes when I try close database by calling Close() method. Anybody know why so?


Sorry for my English,
Best regards
Anton

[Updated on: Sat, 03 July 2010 04:08]

Report message to a moderator

Re: SQLite-insert/update in threads (please help!) [message #27213 is a reply to message #27212] Sat, 03 July 2010 04:28 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

Friend suggested to use try-catch construction to control unexpected situations of external resources.
Re: SQLite-insert/update in threads (please help!) [message #27214 is a reply to message #27213] Sat, 03 July 2010 16:15 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

I used separate thread with queue which handles all the requests to add/fetch from SQLite database (actually it is MtAlt package with CallbackThread class). Until now, had NO runtime errors with SQLite.
Maybe you meet some synchronization issues.

[Updated on: Sat, 03 July 2010 16:15]

Report message to a moderator

Re: SQLite-insert/update in threads (please help!) [message #27224 is a reply to message #27212] Tue, 06 July 2010 09:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
Sc0rch wrote on Fri, 02 July 2010 15:24

I'm getting asserts of Fetch and Execute methods, sometimes. I don't know how to avoid them, but threads are really needed.

Some info about task:
- Console application.
- Main loop of program - RPC-server, with functions for user (each of functions use SQLite database, through global SQL)
- Threads registers incoming hardware events and writes them into the SQLite database.

How can I make this task threadsafe?



I would say that you should serialize (using Mutex) any access to global SQL - including creation of Sql cursors (where SQL is default parameter). I hope that would save the problem.

StaticMutex SQLMutex;


void MyThreadInsert() {
   Mutex::Lock __(SQLMutex);
   SQL * Insert(...)...
}

void MyGuiSelect() {
   Mutex::Lock __(SQLMutex);
   Sql sql;
   sql * Select(...
}


Mirek
Re: SQLite-insert/update in threads (please help!) [message #27225 is a reply to message #27213] Tue, 06 July 2010 09:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
Sc0rch wrote on Fri, 02 July 2010 22:28

Friend suggested to use try-catch construction to control unexpected situations of external resources.


That is a very bad idea.
Re: SQLite-insert/update in threads (please help!) [message #27235 is a reply to message #27225] Tue, 06 July 2010 22:21 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

luzr wrote on Tue, 06 July 2010 14:22

Sc0rch wrote on Fri, 02 July 2010 22:28

Friend suggested to use try-catch construction to control unexpected situations of external resources.


That is a very bad idea.

Don't know why bad idea, but I'm trying not use them in code at all =)

I moved all database calls to one thread (for now), and no crashes now, but app became more slow on database read =(
I'll try Mutex soon. Thank you!

[Updated on: Tue, 06 July 2010 22:23]

Report message to a moderator

Re: SQLite-insert/update in threads (please help!) [message #27297 is a reply to message #27224] Sun, 11 July 2010 12:54 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

No Message Body

[Updated on: Mon, 12 July 2010 08:13]

Report message to a moderator

Re: SQLite-insert/update in threads (please help!) [message #27313 is a reply to message #27212] Mon, 12 July 2010 08:12 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

I've tested the server (1000 incoming events, no delay): FAILED with Mutex =( I'm getting crashes in Execute, Fetch, GetColumnInfo methods. I've checked all functions with SQL and cursors, there are mutex in all at the start of functions. The crashes now not only from ASSERT, but sometimes even from sqlite3 funcs %)

Maybe, change the SQL engine?

[Updated on: Mon, 12 July 2010 08:14]

Report message to a moderator

Re: SQLite-insert/update in threads (please help!) [message #27317 is a reply to message #27313] Mon, 12 July 2010 09:40 Go to previous message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
Sc0rch wrote on Mon, 12 July 2010 02:12

I've tested the server (1000 incoming events, no delay): FAILED with Mutex =( I'm getting crashes in Execute, Fetch, GetColumnInfo methods. I've checked all functions with SQL and cursors, there are mutex in all at the start of functions. The crashes now not only from ASSERT, but sometimes even from sqlite3 funcs %)

Maybe, change the SQL engine?


Maybe you have some bug in the code.

Mirek
Previous Topic: MySQL bug: Missing FIELD_TYPE_TIMESTAMP
Next Topic: Oracle8: UTF8 charset Patch
Goto Forum:
  


Current Time: Sun Aug 18 15:48:21 CEST 2019

Total time taken to generate the page: 0.01527 seconds