Skip to Content.
Sympa Menu

freetds - Re: [freetds] Error/Message handling techniques in C++

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Sharan Rao <sharanrao AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: Re: [freetds] Error/Message handling techniques in C++
  • Date: Sun, 2 Dec 2007 01:27:21 +0530

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



  • Re: [freetds] Error/Message handling techniques in C++, Sharan Rao, 12/01/2007

Archive powered by MHonArc 2.6.24.

Top of Page