//  Beta release only.
//
//  Copyright(c) Ivyware Pty Ltd 2007-2013  (all rights reserved)
//               MELBOURNE, VICTORIA, AUSTRALIA, 3130
//
//  Provided no fee is charged (either by the distributer or user)
//  permission to use, copy, modify, and distribute this software and
//  its documentation for any purpose and without fee is hereby granted,
//  provided that the above copyright notice appear in all copies and
//  that both that copyright notice and this permission notice appear
//  in supporting documentation.
//
//  No waranty or suitablity for purpose is implied.
//
//
//  P2PeerHubODBC definitions and prototypes
//  NOTES: Integrates SQL database, using ODBC API into a P2Peer virtual
//         network
//       : Supports ODBC connection and disconnection, execution of SQL
//         statements and stored procedures.
//         
//         

#pragma once
#include "P2PmsgODBC.h"
#include "P2Peerhub.h"

#include <Sqlext.h>

class P2PmsgODBC_EXT P2PeerHubODBC : public P2PeerHub
{
      void
        RenderThisSafe();

    // Constructors and destructor
    public:
        P2PeerHubODBC ( P2PaddrSTR strP2PaddrThis );
      virtual
       ~P2PeerHubODBC ( );

    // Attributes
    private:
      P2PumpID   m_nSQLPumpID;
      SQLHANDLE  m_hSQL;
      SQLHDBC    m_hDBC;
      SQLHENV    m_hEnv;

    // P2PeerCon_MAP handlers
    // NOTES: Placemarker for map.  Default set of handlers reside
    //        in P2PeerTarget.  Usually this default set is customised
    protected:
    DECLARE_P2PeerCon_MAP()

    // P2PeerMsg_MAP handlers
    // NOTES: Placemarker for map.  Default set of handlers reside
    //        in P2PeerTarget.  Usually this default set is customised
    protected:
	  DECLARE_P2PeerMsg_MAP()
      virtual msgRESULT
        On_SQLconnect2server ( P2PeerMsg *pMsg );
      virtual msgRESULT
        On_SQLDriverConnect ( P2PeerMsg *pMsg );
      virtual msgRESULT
        On_SQLdisconnectServer ( P2PeerMsg *pMsg );
      virtual msgRESULT
        On_SQLselect  ( P2PeerMsg *pMsg );
      virtual msgRESULT
        On_ExecuteSP  ( P2PeerMsg *pMsg );
};

//
//
//  P2PeventODBC events
//  NOTES: Implementation to simplify ODBC error collation and
//         reporting
//       : Usage EVSQL->MessageSQLGetDiagRec(...)
//                    ->Module(...)
//                    ->Message(...)
//                    ->etc
//
class P2PeventODBC : public P2Pevent
{
    // Operations
    public:
      P2PeventODBC*
        MessageSQLGetDiagRec ( SQLSMALLINT hType, SQLHANDLE hSQL );
};
#define EVSQL ((P2PeventODBC *)(new P2PeventODBC())->InitEvent(P2Pevent_ERROR))
