ISAPIQRY.CPP

//-------------------------------------------------------------------- 
// Microsoft OLE DB ISAPI Sample
// Copyight(c) 1996 Microsoft Corporation. All Rights Reserved.
//
// @doc
//
// @module ISAPIQRY.CPP | Internet Server Extention. Created by VC++ 4.1
// ISAPI extention wizard. This class is used by the MFC file
// ISAPI.cpp. Standard IS calls are mapped to this class.
//
// @rev 1 | 06-11-96 | Created
//


//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
//#include <afx.h>
#include <afxwin.h>
#include <afxisapi.h>
#include "resource.h"
#include "ISAPIQRY.h"

//Headers needed to run OLE DB DO
//Note : #define DBINITCONSTANTS is not present
#include <afxole.h>
#include <iostream.h>
#include <assert.h>
#include <oledb.h>
#include <oledberr.h>
#include "DOclient.h" //Data Objects Client Header File

//-----------------------------------------------------------------------------
// Externals
//-----------------------------------------------------------------------------

extern g_pIMalloc; //Global memory allocator

TCHAR szTitle[] = _T("OLE DB - Internet Demo (Results)");

// command-parsing map
BEGIN_PARSE_MAP(CIsapiqryExtension, CHttpServer)
ON_PARSE_COMMAND(MainFunction, CIsapiqryExtension, ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR)
ON_PARSE_COMMAND_PARAMS ("DSN=~ UserName=~ Password=~ SQL=~")
DEFAULT_PARSE_COMMAND(MainFunction, CIsapiqryExtension)
END_PARSE_MAP(CIsapiqryExtension)



CIsapiqryExtension theExtension;


//-----------------------------------------------------------------------------
// CIsapiqryExtension implementation

CIsapiqryExtension::CIsapiqryExtension()
{

}

CIsapiqryExtension::~CIsapiqryExtension()
{
}


LPCTSTR CIsapiqryExtension::GetTitle (void) const
{
return szTitle;
}

BOOL CIsapiqryExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
// Call default implementation for initialization
CHttpServer::GetExtensionVersion(pVer);

// Load description string
TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
_tcscpy(pVer->lpszExtensionDesc, sz);
return TRUE;
}


//-----------------------------------------------------------------------------------
// CFirstExtension::MainFunction
//
// @mfunc void| MainFunction | All the code functions are called from here.
// 1. Initialize DataObjects
// 2. Set the SQL command
// 3. etc.
//
// @rdesc NONE
//
//-----------------------------------------------------------------------------------
void CIsapiqryExtension::MainFunction
(
CHttpServerContext* pCtxt, //@param IN | Place where output is directed
LPCSTR pstrDSN, //@param IN | DSN connection name
LPCSTR pstrUserName, //@param IN | User name
LPCSTR pstrPassword, //@param IN | Passwd
LPCSTR pstrSQLCommand //@param IN | SQL Command to executed
)
{

//************************************ BEGIN OLE DB DO Variables ***********************************************
WCHAR wszSQLCommand[MAXBUFLEN+1];
ULONG cCol;

//Bindings and accessor
DBBINDING * prgBind=NULL;
ULONG cBind;
HACCESSOR hAccessor=NULL;
ULONG cbMaxRowSize;

//Column Info
DBCOLUMNINFO * pColumnInfo=NULL;
WCHAR * pStringBuffer=NULL;

IRowset* pIRowset = NULL;
IDBCreateCommand *pIDBCreateCommand = NULL;// IDBCreateCommand

//***************************** END OLE DB DO Variables **********************************


StartContent(pCtxt);
//********************************** OLE DB Calls ****************************************
WriteTitle(pCtxt);

if( FAILED(ConnectDB(&pIDBCreateCommand, pstrDSN, pstrUserName, pstrPassword, pCtxt)) )
goto error;

if (0==MultiByteToWideChar (CP_ACP,0,pstrSQLCommand,-1,wszSQLCommand,MAXBUFLEN+1))
{
*pCtxt << "MultiByteToWideChar Failed!!!\n";
goto error;
};

if( FAILED(SetAndExecute(wszSQLCommand, pIDBCreateCommand, &pIRowset, &pColumnInfo, &pStringBuffer,
&cCol, &prgBind, &cBind, &hAccessor, &cbMaxRowSize, pCtxt)) )
goto error;

if( FAILED(GetAndWrite(pIRowset, cbMaxRowSize, hAccessor, prgBind, cBind,
pColumnInfo, cCol, pCtxt)) )
goto error;

error :
FreeEnvironment(pIRowset, hAccessor, pColumnInfo, pStringBuffer);
delete [] prgBind;
//********************************** END OLE DB Calls ************************************
EndContent(pCtxt);


}//MainFunction