Solved

Alternative to sqlite3_get_table

Posted on 2011-09-13
7
709 Views
Last Modified: 2012-05-12
I have this function called isadded(), which is giving me an error. And I ran debugdiag, and I found that the place where it errors out is sqlite3_get_table().

      sprintf_s(query,1024,"SELECT * FROM OServs WHERE oservname = '%s' ;", cOServID);
      cout<<query<<endl;
      rc = sqlite3_get_table(db, query, &results, &nrow, &ncol, &zErrMsg);

Basically, I am trying to see if the Oserv is already in the database or not. Is there an alternative function I can use?
Function     Arg 1     Arg 2     Arg 3   Source 
ntdll!RtlpWaitOnCriticalSection+df     00001484     00000002     00000000    
ntdll!RtlEnterCriticalSection+a8     09e10c08     006310a5     09e10c08    
sqlite3!sqlite3_mutex_leave+17b     09caf370     0c81d9c8     0063d240    
sqlite3!sqlite3_get_table+99     09caf370     0c81d9c8     0c81d9bc    
OServHandler!COServHandler::isAdded+17f     059a6fd8     0c8272e0     00000006    
OServHandler!COServHandler::getHierarchy+ba7     0c940020     00008000     6009fb27    
AdminConsoleInterface!CAdminConsoleInterface::handleConnection+178     00001254     00000000     00000000    
AdminConsoleInterface!CAdminConsoleInterface::setOServHandler+33     008c5cd0     0250e9c8     00000000

Open in new window

0
Comment
Question by:zystemsgo
  • 4
  • 3
7 Comments
 

Author Comment

by:zystemsgo
ID: 36531877
No Answers, it has been 6 hours since I posted it
0
 
LVL 32

Expert Comment

by:sarabande
ID: 36534121
what error did you get?

did you try the query with some admin tool?

Sara
0
 

Author Comment

by:zystemsgo
ID: 36536024
The error happens when two or more threads access this sqlite3_get_table function, and as per the dump I posted, it causes a ntdll.dll exception.

ntdll!RtlpWaitOnCriticalSection+df     00001484     00000002     00000000    
ntdll!RtlEnterCriticalSection+a8     09e10c08     006310a5     09e10c08    
sqlite3!sqlite3_mutex_leave+17b     09caf370     0c81d9c8     0063d240    
sqlite3!sqlite3_get_table+99     09caf370     0c81d9c8     0c81d9b

Read it in reverse, i.e bottom to top.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
ID: 36536086
if you access the same database by different threads you should open a new connection for each thread. all other things will fail sooner or later to my experience.

Sara
0
 

Assisted Solution

by:zystemsgo
zystemsgo earned 0 total points
ID: 36536246
There is a sqlite3_open and sqlite3_close at the beginning and ending of each function. But, I think it was bad design anyway to read the database each time.

I read the database once at the beginning of each thread and store it in a map container and do a map.find() to see if the object exists or not.
0
 

Author Closing Comment

by:zystemsgo
ID: 36558747
Cos, I answered my own question. I eliminated the sqlite3 call altogether.
0
 
LVL 32

Expert Comment

by:sarabande
ID: 36536379
the error in the wait for critical section probably means that you caused a dead-lock somehow. do you call the functions recursively somehow? or is there a way to miss the close?

a map is a good idea, though. you should use the main thread to initially load it and provide a static method or singleton class object to access map from any thread. if the map doesn't need to get refreshed that approach automatically is thread-safe.

Sara
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now