⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 params.cpp

📁 关于SQL SERVER 的加密和解密包
💻 CPP
字号:
// params.cpp
// SQL Server Parameter class; retrieves parameters from SQL Server
//
// Methods:
//		params()					Default constructor
//		~params()					Custom destructor releases data pointer
//		static int getparamcount()	Retrieves number of SQL Server parameters passed in
//		static void getparam()		Retrieves specified parameter from SQL Server
// Properties:
//		SRVRETCODE success			Set to FAIL if retrieving parameter failed, SUCCESS
//									if it was successful
//		ULONG length				The actual length of the data passed in the parameter
//		ULONG maxlength				The max length of the parameter passed in
//		BYTE *cdata					The BYTE pointer to the character data passed in
//		BOOL isnull					Set to TRUE if SQL NULL is passed in; FALSE if parameter
//									is not SQL NULL
//		BYTE type					The type of the parameter
//
// Michael Coles, MCDBA
// 7/2005
//
#include "../stdafx/stdafx.h"
#include "../params/params.h"
// getparamcount()
//
// This little routine retrieves the total number of parameters passed in to us.
// Always call this before calling getparam, to ensure that we are not trying to
// retrieve more parameters than were passsed in.
//
// Parameters:
//		SRV_PROC *srvproc	Server process pointer
// Returns:
//		int					Number of parameters passed in to from SQL Server
//
int params::getparamcount(SRV_PROC *srvproc) {
	return (srv_rpcparams(srvproc));
}
// getparam()
//
// This handy little routine retrieves the specified parameter.  For some reason, 
// SQL numbers parameters beginning with 1, not C-standard 0 as we might expect.
//
// Parameters:
//		SRV_PROC *srvproc	Server process pointer
//		int paramnum		Number of the SQL Server parameter to retrieve
//		params *p			Pointer to a params object
//
void params::getparam(SRV_PROC *srvproc, int paramnum, params *p) {
	// Set the success/failure code
	SRVRETCODE rc = SUCCEED;
	// Get the parameter length first
	rc = srv_paraminfo(srvproc, paramnum, &p->type, &p->maxlength, &p->length, NULL, &p->isnull);
	if (rc == SUCCEED) 
	{
		// Now we reserve the required space, +1 extra byte for a '\0' string end marker.
		p->cdata = new BYTE[p->length + 1];
		memset(p->cdata, 0, p->length + 1);
		// Now we retrieve the actual parameter value.
		rc = srv_paraminfo(srvproc, paramnum, &p->type, &p->maxlength, &p->length, p->cdata, &p->isnull);
		p->isoutput = (srv_paramstatus(srvproc, paramnum) & SRV_PARAMRETURN);
	}
	p->success = rc;
}
// ~params()
//
// This destructor will release the cdata array of dynamically allocated memory.
//
params::~params() {
	// Only if it was assigned.
	if (this->cdata != NULL) {
		delete [] this->cdata;
		this->cdata = NULL;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -