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

📄 proc.cpp

📁 关于SQL SERVER 的加密和解密包
💻 CPP
字号:
// proc.cpp
// Implementation of xp_rot13 extended stored procedure.
// Michael Coles, MCDBA, 7/2005
//
// Ver. 0.9.0.0: Modified to fix potential memory fragmentation for very large
//               datasets
//
#include "../common/stdafx/stdafx.h"
#include "../common/params/params.h"
#include "ROT13_Encode.h"

#define XP_ERROR			1
#define XP_NOERROR			0

#define ERR_USAGE			"Usage: EXEC xp_rot13 @param1 [, @param2]"
#define ERR_OUTPUT			"If @param2 is specified, it must be OUTPUT type"

#ifdef __cplusplus
extern "C" {
#endif

	RETCODE __declspec(dllexport) xp_rot13(SRV_PROC *srvproc);

#ifdef __cplusplus
}
#endif

#ifdef __DEBUG
void PrintString (SRV_PROC *srvproc, char *Msg);
#endif

void PrintError (SRV_PROC *srvproc, char *ErrorMsg);

RETCODE __declspec(dllexport) xp_rot13(SRV_PROC *srvproc)
{
	SRVRETCODE sqlerr = XP_NOERROR;

	// First we declare a new SQL Parameter object to hold our SQL Parameter.
	params *P1 = new params;
	params *P2 = new params;
	DBCHAR spText[500];

	int j = params::getparamcount(srvproc);

	// Now we check the SQL Parameter Count.  We only want one or two parameters here.
	if (j > 2 || j < 1) {
		PrintError(srvproc, ERR_USAGE);
		sqlerr = XP_ERROR;
	} else {
		// Now we get the data from SQL Parameter 1
		params::getparam(srvproc, 1, P1);

		// Now we encode the string passed in using ROT13
		ROT13_Encode_String(P1->cdata, P1->length);

		if (P1->isnull) P1->length = 0;

		if (j == 1) {
			// Here we output our result.
			// First we set up our single output column name, type and length
			DBCHAR colname[25];
			_snprintf(colname, 25, "ROT13");
			srv_describe(srvproc, 1, colname, SRV_NULLTERM, SRVVARCHAR, P1->length, SRVVARCHAR, 0, 0);

			// Next we set the output column data to the encoded ROT13 string
			srv_setcoldata(srvproc, 1, P1->cdata);
			srv_setcollen(srvproc, 1, static_cast<int>(P1->length));

			// Now we send the row and alert the SQL Server that we are done
			srv_sendrow(srvproc);
			srv_senddone(srvproc, SRV_DONE_MORE | SRV_DONE_COUNT, (DBUSMALLINT)0, (DBINT)1);
		} else {
			params::getparam(srvproc, 2, P2);
			if (!P2->isoutput) {
				PrintError(srvproc, ERR_OUTPUT);
				sqlerr = XP_ERROR;
			} else {
				srv_paramsetoutput(srvproc, 2, P1->cdata, P1->length, P1->isnull);
				srv_senddone(srvproc, SRV_DONE_MORE, (DBUSMALLINT)0, (DBINT)0);
			}
		}
	}
	if (P1 != NULL) {
		delete P1;
		P1 = NULL;
	}
	if (P2 != NULL) {
		delete P2;
		P2 = NULL;
	}
	// Finally we return with no errors
	return sqlerr;
}
// This routine sends an error message to the SQL Server Output Window
//
// Parameters:
//		SRV_PROC *srvproc		the server process pointer passed in by SQL Server
//		char *ErrorMsg			the error message string to print
//
void PrintError (SRV_PROC *srvproc, char *ErrorMsg)
{
	// Print the error message on the SQL Server output screen
	srv_sendmsg(srvproc, SRV_MSG_ERROR, XP_ERROR, SRV_INFO, 1,
		NULL, 0, (DBUSMALLINT) __LINE__, 
		ErrorMsg,
		SRV_NULLTERM);
	// Alert SQL Server that an error has occurred
	srv_senddone(srvproc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
}

⌨️ 快捷键说明

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