?
Solved

Alternative to sqlite3_get_table

Posted on 2011-09-13
7
Medium Priority
?
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

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

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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 35

Accepted Solution

by:
sarabande earned 2000 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 35

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 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