Extended Stored Procedure is a special function packaged in a DLL.
Extended stored procedures for SQL Server can be written either in VC++ or Delphi (or any other compiler which supports function export - VB and C# can't unless of use SQL Server 2005). And yes, all the WinAPI can be used there.
Like regular T-SQL stored procedures (or .NET extended stored procedures for SQL Server 2005), they can accept input/output parameters and produce recordsets.
The great difference is that they can accept a variable list of input parameters of different datatypes! So, actual number of parameters and their datatypes can be determined by extended stored procedure at runtime.
Extended Stored Procedures are good for:
Although giving these benefits, the native Extended Stored Procedures API (former Open Data Services API) is rather complex in use.
It requires too much "housekeeping" work from the developer: manage memory buffers, handle I/O parameters, determine I/O datatypes, describe and produce recordsets, etc, etc, etc...
This, in turn, may require often debug.
Is there a better way?
Here is a VC++ class CXProc that hides all of that jazz from the developer and just exposes methods and properties.
It is compatible to VC++ 6 and 7.
No more dozens of srv_describe, srv_paramsetoutput, srv_rpcparams, srv_paraminfo, etc! Just CXProc xproc(srvproc); CxpFields& fd = xproc.Fields(); fd[0].SetInt(123);
srv_describe
srv_paramsetoutput
srv_rpcparams
srv_paraminfo
CXProc xproc(srvproc); CxpFields& fd = xproc.Fields(); fd[0].SetInt(123);
[+] This example does the following (click here to show/hide):
This code deals with two optional I/O parameters (first them is varchar and second is int), modifies first (when present), and then creates a recordset of 3 columns: int, datetime, and image.
varchar
int
int, datetime
image
#include "xproc.h" using namespace XProc; __declspec(dllexport) RETCODE xp_Class(SRV_PROC *srvproc) { CXProc xproc(srvproc); // Initialize CxpParams& p = xproc.Params(); // Remember the INPUT/OUTPUT params collection for future reference size_t cnt = 0; if (p.size()) { // Check if procedure parameters are present char* s = p[0].GetAnsiText(); // Read first procedure parameter (assume it is VARCHAR & OUTPUT) cnt = 21 + strlen(s); char* answer = new char[cnt]; memset(answer, 0, cnt); strcat(answer, "You've just passed: "); p[0].SetVarchar(strcat(answer, s)); // Send the modified text back to OUTPUT parameter delete answer; delete s; // IMPORTANT!!! } // Let's make a recordset of 20 rows and 3 columns: INT, DATETIME, and IMAGE CxpFields& fd = xproc.Fields(); // Remember the fields collection for future reference cnt = 300; // Let IMAGE field's length is 300 bytes fd[2].SetName("300 bytes of BLOB"); // Give an arbitrary name to an IMAGE field column // Just a dummy integer multiplicator value from 2nd INPUT parameter (optional) int nDummy = 1; if ((p.size() > 1) && (p[1].DataType() == ftInteger)) { nDummy = p[1].GetInt(); } SYSTEMTIME st; for (int i = 0; i < 20; i++) { // Field #1 fd[0].SetInt(i * nDummy); // Field #2 GetSystemTime(&st); fd[1].SetDateTime(st); // Field #3 void* p = malloc(cnt); memset(p, i, cnt); fd[2].SetImage(p, (ULONG)cnt); free(p); // Send a recordset row back to SQL Server fd.Next(); } return 1; };
#include
using namespace
__declspec(dllexport)
if
char
new char
delete
for (int
void
return
This class supports the following datatypes for I/O Parameters and Recordset Fields:
bigint
numeric
binarybitdatetimeuniqueidentifier
TGUID
float
intmoneynumeric
decimalnvarcharvarbinaryvarchar
Plus, it supports the following BLOB datatypes for Recordset Fields: imagentexttext
imagentexttext
Maximum length of varchar/nvarchar parameters data is 4000 symbols.
varchar/nvarchar
An arbitrary number of recordsets can be returned from a procedure.
Note: Instead of SQL Server 2000 (and later), SQL Server 7.0 does not support SELECT INTO/INSERT of text/ntext/image fields from extended stored procedure recordsets.
text/ntext/image
Includes:
Instant Delivery!Receive this product immediately* right after you have made your order!
Class source code (full version) for VC++ 6 and 7
Volume Discount Prices: Show
BUY NOW!
Show our Privacy Policy and Order Processing information.
* Applies to payments made by credit or debit cards.
Stored Procedures for SQL Server
Access file system and Internet, use data compression and cryptography with T-SQL.
Read more...
Create your own Extended Stored Procedures!
That's easy if use wrapper classes for Visual C++ or Delphi.
Folder Jump.com
Let Your Fingers Rest!Stop waste your time browsing directories!
Folder Size FREE shell extension, adds 'Folder Size' column to Windows Explorer
Delphi Components
Internet tools, PGP SDK wrapper component, User activity detection Smart message boxes...
GlyFy.com Quality icons, glyphs, and images for software development
Awards