[freetds] Error/Message handling techniques in C++

Sharan Rao sharanrao at gmail.com
Sat Dec 1 14:57:21 EST 2007


On Friday 30 Nov 2007 8:01:16 am James K. Lowden wrote:
> Sharan Rao wrote:
> > I am using db-lib alongwith C++ code. Are there any alternatives for
> > error  retrieval / message retrieval other than using callback functions
> > ? Using callbacks is not really enjoyable in C++ code. As the callback
> > interface  is not accessible, AFAIK, I'll have to resort to some global
> > variable stuff  :( ( Any better methods ? )
>
> You don't need any global variables.  Here's what I do for my C++
> framework:
>
> 1.  Write two file-scope functions.  These are the callbacks.  Install
> them immediately after you call db_init().
> 2.  In your C++ class, add a static std::map<DBPROCESS*, your_class*>.
> 3.  Give the callbacks access to that static map.
> 4.  Write instance-level functions for the callbacks to call.
> 5.  On connecting to the database, have your object add its 'this' pointer
> (and the new DBPROCESS*) to the class's static map.
>
> When a message is received, the callback can look up the instance in the
> static map and call the appropriate function, passing whatever it
> received.
>

Nifty! Thanks a lot !! It seems all so simple now ( as with good solutions, 
ah ! )

Cheers!
 Sharan Rao



More information about the FreeTDS mailing list