Solved

Alternative to sqlite3_get_table

Posted on 2011-09-13
7
721 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 33

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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 33

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 33

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 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

8 Experts available now in Live!

Get 1:1 Help Now