Author: Vassilis Perantzakis
Have you ever tried to create a stored procedure on an SQL Server?
What if the functionality you wish to incorporate is not inside the SQL but in your
Delphi project? Microsoft provides ODS (Open Data Services) which is an API to
help you create such functionality by adding DLL's to your SQL Server that contain
Extended Stored Procedures.
This is how you do it....
Answer:
As a special bonus, this article also is a simple solution to encrypting your data
inside SQL Server using Extended Stored Procedures.
What do we need?
opends60.dll (from a full installation with developer tools of MSSQL or MSDE)
MsOdsApi.pas (Header file to use opends60.dll) (included at the end of the article)
A Local SQL Server for testing (MSDE will do fine).
NOTE: For cryptography I used the components found under MIT license here:
http://www.cityinthesky.co.uk/cryptography.html
Steps:
Create a new DLL.
Create a unit and in the uses clause add the MsOdsApi unit.
In the Library file just under ther Uses clause add Exports and the names of the
functions to export:
1 library MyEncryptDll;
2
3 uses
4 SysUtils,
5 Classes,
6 Unit1 in 'Unit1.pas';
7
8 exports
9 xp_DoEncrypt,
10 xp_DoDecrypt;
11
12 begin
13 end.
4. In the Unit file just under the Uses clause add your function reference:
14
15 function xp_DoEncrypt(pSrvProc: SRV_PROC): Integer; cdecl;
16 function xp_DoDecrypt(pSrvProc: SRV_PROC): Integer; cdecl;
NOTES: cdecl is required for ODS to be able to call your functions. SRV_PROC is a
handle to the stored procedure information.
5. The code of the DoEncrypt is this: (DoDecrypt is exactly the same just with a
DecryptString(s) call.
17
18 function xp_Encrypt(pSrvProc: SRV_PROC): Integer;cdecl;
19 var
20 i, sz: Integer;
21 bType: Byte;
22 fNull: Bool;
23 cbMaxLen, cbActualLen: ULONG;
24 myData,myanswer,myKey:array [0..255] of char;
25 FDCP_3des: TDCP_3des;
26 s:string;
27 ps:pchar;
28 begin
29 for i:=0 to 255 do
30 begin
31 myData[i]:=#0;
32 myanswer[i]:=#0;
33 myKey[i]:=#0;
34 end;
35 if srv_rpcparams(pSrvProc) = 2 then // Check if input parameters are present...
36 begin
37 srv_paraminfo(pSrvProc, 1, @bType, // Let's use 1st input parameter!
38 @cbMaxLen, @cbActualLen, // NOTE: We assume here what only 2 parameters
39 @myData[0], @fNull); //of type String can be passed!!!
40 bType:=SRVVARCHAR;
41 srv_paraminfo(pSrvProc, 2, @bType,
42 @cbMaxLen, @cbActualLen,
43 @myKey[0], @fNull);
44 end
45 else
46 MyData := ''; // No input parameters? Use default value instead.
47
48 //ENCRYPTION CODE BELOW YOU CAN DO WHATEVER YOU NEED HERE WITH THE PARAMETER
49 VALUES
50
51 FDCP_3des:=TDCP_3des.Create(nil);
52 FDCP_3des.BlockSize:=64;
53 FDCP_3des.Algorithm:='3DES';
54 FDCP_3des.CipherMode:=cmCBC;
55 FDCP_3des.Id:=24;
56 FDCP_3des.MaxKeySize:=192;
57 FDCP_3des.InitStr(myKey,TDCP_sha1);
58 s:=string(mydata);
59 strpcopy(myAnswer,FDCP_3des.EncryptString(s));
60 FDCP_3des.Burn;
61
62 // SETTING UP ANSWER VALUES TO PCHAR AND GETTING SIZE
63
64 s:=string(myAnswer);
65 sz:=length(s);
66 ps:=allocmem(sz);
67 ps:=pchar(s);
68
69 // Describe columns
70 // (Actually, you are doing that for every datatype and every column you want to
71 return).
72 srv_describe(pSrvProc,1 , 'Value', SRV_NULLTERM,
73 SRVVARCHAR, sz,
74 SRVVARCHAR, sz, nil);
75 // Begin output...
76 srv_setcoldata(pSrvProc, 1, @ps[0]);
77 srv_sendrow(pSrvProc); // Send the row.
78 srv_senddone(pSrvProc, // Finally send data back to SQL Server:
79 (SRV_DONE_COUNT or SRV_DONE_MORE), 0, 1); // send results completion message.
80 // FREEING ENCRYPTION COMPONENT
81 FreeAndNil(FDCP_3des);
82 result := 1; // Report success (1 = SUCCEED, 0 = FAIL)
end;
NOTE: There are a number of things you can do with ODS. This is just an example for
Delphi. You can read the ODS help in MSDN and do even more.
6. Testing and Debugging:
A) Install SQL 7.0/2000 on your workstation (or install Delphi on workstation where
SQL Server is installed).
B) Register your Xp on SQL Server.
NOTES:
83 register Xp like this:
84 use master
85 go
86 sp_addextendedproc 'xp_DoEncrypt', 'MyEncryptDll.dll'
87 go
88 sp_addextendedproc 'xp_DoDecrypt', 'MyEncryptDll.dll'
89 go
90 Unregister Xp like this:
91 use master
92 go
93 sp_dropextendedproc 'xp_DoEncrypt'
94 go
95 sp_dropextendedproc 'xp_DoDecrypt'
96 go
97 Unlock DLL in case it still being used by SQL like this:
98 use master
99 go
100 DBCC MyEncryptDll(FREE)
101 go
C) In Delphi, select from main menu Run -> Run Parameters.
In the Host Application field, specify a pathname to your SQL Server executable
(sqlservr.exe). For SQL 7.0, this is enough. For SQL 2000, in the Parameters field
specify a command line parameter "-sYOUR_SQL_NAME", where YOUR_SQL_NAME is the name
assigned to your SQL Server during the installation.
Set breakpoints in your Delphi code and run project. SQL Server will start as a
console application.
D) You can execute your Xp from Query Analyzer and trace code in Delphi.
NOTE:
Executing an extended stored procedure is done like this:
exec master..xp_DoEncrypt 'ValueToEncrypt','KeyValue'
go
E) To exit application, press Ctrl+Pause in the SQL Server console window.
-------------------------------------------------------
End of article. Bellow follows a unit required for ODS.
-------------------------------------------------------
MsOdsApi.pas (Copy from line below)
102
103 unit MsOdsApi;
104
105 //------------------------------------------------------------
106 // Open Data Services header file: srv.h
107 // Copyright (c) 1989, 1990, 1991, 1997 by Microsoft Corp.
108 //
109
110 // Avoid double inclusion
111 //#ifndef _ODS_SRV_H_
112 // _ODS_SRV_H_
113
114 //#include "windows.h"
115
116 // ODS uses pack(4) on all CPU types
117 //#pragma pack(4)
118
119 //#ifdef __cplusplus
120 //extern "C" {
121 //#endif
122
123 // define model
124 //#if !defined( FAR )
125 // FAR far
126 //#endif
127
128 //------------------------------------------------------------
129 // Formats of data types
130 //#if !defined(DBTYPEDEFS) // Do not conflict with DBLIB definitions
131 //#if !defined(MAXNUMERICLEN) // Do not conflict with ODBC definitions
132
133 // DBTYPEDEFS
134
135 interface
136
137 uses
138 Windows;
139
140 type
141 DBBOOL = Byte;
142 DBBYTE = Byte;
143 DBTINYINT = Byte;
144 DBSMALLINT = Smallint;
145 DBUSMALLINT = Word;
146 DBINT = Longint;
147 DBCHAR = Char;
148 PDBCHAR = ^DBCHAR;
149 DBBINARY = Byte;
150 DBBIT = Byte;
151 DBFLT8 = Double;
152
153 srv_datetime = record
154 // Format for SRVDATETIME
155 dtdays: Longint; // number of days since 1/1/1900
156 dttime: Longword; // number 300th second since mid
157 end;
158 DBDATETIME = srv_datetime;
159
160 srv_dbdatetime4 = record
161 // Format for SRVDATETIM4
162 numdays: Word; // number of days since 1/1/1900
163 nummins: Word; // number of minutes sicne midnight
164 end;
165 DBDATETIM4 = srv_dbdatetime4;
166
167 srv_money = record
168 // Format for SRVMONEY
169 mnyhigh: Longint;
170 mnylow : Longword;
171 end;
172 DBMONEY = srv_money;
173
174 DBFLT4 = Double;
175 DBMONEY4 = Longint;
176
177 const
178 MAXNUMERICDIG = 38;
179 DEFAULTPRECISION = 19; // 18
180 DEFAULTSCALE = 0;
181 MAXNUMERICLEN = 16;
182
183 type
184 srv_dbnumeric = packed record
185 // Format for SRVNUMERIC,SRVNUMERICN,SRVDECIMAL,SRVDECIMALN
186 precision: Byte;
187 scale : Byte;
188 sign : Byte; // 1 = Positive, 0 = Negative
189 val : array [0..MAXNUMERICLEN-1] of Byte; // Padded little-endian value
190 end;
191 DBNUMERIC = srv_dbnumeric;
192 DBDECIMAL = DBNUMERIC;
193
194 //#endif // #if !defined(MAXNUMERICLEN)
195 //#endif // #if !defined( DBTYPEDEFS )
196
197 //------------------------------------------------------------
198 // Constants used by APIs
199
200 // Type Tokens
201 const
202 SRV_TDS_NULL = $1f;
203 SRV_TDS_TEXT = $23;
204 SRV_TDS_GUID = $24;
205 SRV_TDS_VARBINARY = $25;
206 SRV_TDS_INTN = $26;
207 SRV_TDS_VARCHAR = $27;
208 SRV_TDS_BINARY = $2d;
209 SRV_TDS_IMAGE = $22;
210 SRV_TDS_CHAR = $2f;
211 SRV_TDS_INT1 = $30;
212 SRV_TDS_BIT = $32;
213 SRV_TDS_INT2 = $34;
214 SRV_TDS_DECIMAL = $37;
215 SRV_TDS_INT4 = $38;
216 SRV_TDS_DATETIM4 = $3a;
217 SRV_TDS_FLT4 = $3b;
218 SRV_TDS_MONEY = $3c;
219 SRV_TDS_DATETIME = $3d;
220 SRV_TDS_FLT8 = $3e;
221 SRV_TDS_NUMERIC = $3f;
222 SRV_TDS_NTEXT = $63;
223 SRV_TDS_BITN = $68;
224 SRV_TDS_DECIMALN = $6a;
225 SRV_TDS_NUMERICN = $6c;
226 SRV_TDS_FLTN = $6d;
227 SRV_TDS_MONEYN = $6e;
228 SRV_TDS_DATETIMN = $6f;
229 SRV_TDS_MONEY4 = $7a;
230 SRV_TDS_INT8 = $7f; // SQL 2000 and later
231 SRV_TDS_BIGVARBINARY = $A5;
232 SRV_TDS_BIGVARCHAR = $A7;
233 SRV_TDS_BIGBINARY = $AD;
234 SRV_TDS_BIGCHAR = $AF;
235 SRV_TDS_NVARCHAR = $e7;
236 SRV_TDS_NCHAR = $ef;
237
238 // Datatypes
239 // Also: values of symbol parameter to srv_symbol when type = SRV_DATATYPE
240 SRVNULL = SRV_TDS_NULL;
241 SRVTEXT = SRV_TDS_TEXT;
242 SRVGUID = SRV_TDS_GUID;
243 SRVVARBINARY = SRV_TDS_VARBINARY;
244 SRVINTN = SRV_TDS_INTN;
245 SRVVARCHAR = SRV_TDS_VARCHAR;
246 SRVBINARY = SRV_TDS_BINARY;
247 SRVIMAGE = SRV_TDS_IMAGE;
248 SRVCHAR = SRV_TDS_CHAR;
249 SRVINT1 = SRV_TDS_INT1;
250 SRVBIT = SRV_TDS_BIT;
251 SRVINT2 = SRV_TDS_INT2;
252 SRVDECIMAL = SRV_TDS_DECIMAL;
253 SRVINT4 = SRV_TDS_INT4;
254 SRVDATETIM4 = SRV_TDS_DATETIM4;
255 SRVFLT4 = SRV_TDS_FLT4;
256 SRVMONEY = SRV_TDS_MONEY;
257 SRVDATETIME = SRV_TDS_DATETIME;
258 SRVFLT8 = SRV_TDS_FLT8;
259 SRVNUMERIC = SRV_TDS_NUMERIC;
260 SRVNTEXT = SRV_TDS_NTEXT;
261 SRVBITN = SRV_TDS_BITN;
262 SRVDECIMALN = SRV_TDS_DECIMALN;
263 SRVNUMERICN = SRV_TDS_NUMERICN;
264 SRVFLTN = SRV_TDS_FLTN;
265 SRVMONEYN = SRV_TDS_MONEYN;
266 SRVDATETIMN = SRV_TDS_DATETIMN;
267 SRVMONEY4 = SRV_TDS_MONEY4;
268 SRVINT8 = SRV_TDS_INT8; // SQL 2000 and later
269 SRVBIGVARBINARY = SRV_TDS_BIGVARBINARY;
270 SRVBIGVARCHAR = SRV_TDS_BIGVARCHAR;
271 SRVBIGBINARY = SRV_TDS_BIGBINARY;
272 SRVBIGCHAR = SRV_TDS_BIGCHAR;
273 SRVNVARCHAR = SRV_TDS_NVARCHAR;
274 SRVNCHAR = SRV_TDS_NCHAR;
275
276 // values for srv_symbol type parameter
277 SRV_ERROR = 0;
278 SRV_DONE = 1;
279 SRV_DATATYPE = 2;
280 SRV_EVENT = 4;
281
282 // values for srv_symbol symbol parameter, when type = SRV_ERROR
283 SRV_ENO_OS_ERR = 0;
284 SRV_INFO = 1;
285 SRV_FATAL_PROCESS = 10;
286 SRV_FATAL_SERVER = 19;
287
288 // Types of server events
289 // Also: values for srv_symbol symbol parameter, when type = SRV_EVENT
290 SRV_CONTINUE = 0;
291 SRV_LANGUAGE = 1;
292 SRV_CONNECT = 2;
293 SRV_RPC = 3;
294 SRV_RESTART = 4;
295 SRV_DISCONNECT = 5;
296 SRV_ATTENTION = 6;
297 SRV_SLEEP = 7;
298 SRV_START = 8;
299 SRV_STOP = 9;
300 SRV_EXIT = 10;
301 SRV_CANCEL = 11;
302 SRV_SETUP = 12;
303 SRV_CLOSE = 13;
304 SRV_PRACK = 14;
305 SRV_PRERROR = 15;
306 SRV_ATTENTION_ACK = 16;
307 SRV_CONNECT_V7 = 16; // TDS type for TDS 7 clients. Overloaded with
308 SRV_ATTENTION_ACK
309 SRV_SKIP = 17;
310 SRV_TRANSMGR = 18;
311 SRV_OLEDB = 20;
312 SRV_INTERNAL_HANDLER = 99;
313 SRV_PROGRAMMER_DEFINED = 100;
314
315 // values for srv_config option parameter
316 SRV_CONNECTIONS = 1;
317 SRV_LOGFILE = 2;
318 SRV_STACKSIZE = 3;
319 SRV_REMOTE_ACCESS = 7;
320 SRV_REMOTE_CONNECTIONS = 9;
321 SRV_MAX_PACKETS = 10;
322 SRV_MAXWORKINGTHREADS = 11;
323 SRV_MINWORKINGTHREADS = 12;
324 SRV_THREADTIMEOUT = 13;
325 SRV_MAX_PACKETSIZE = 17;
326 SRV_THREADPRIORITY = 18;
327 SRV_ANSI_CODEPAGE = 19;
328 SRV_DEFAULT_PACKETSIZE = 26;
329 SRV_PASSTHROUGH = 27;
330
331 // vlaues for srv_config value parameter when option = SRV_THREADPRIORITY
332 SRV_PRIORITY_LOW = THREAD_PRIORITY_LOWEST;
333 SRV_PRIORITY_NORMAL = THREAD_PRIORITY_NORMAL;
334 SRV_PRIORITY_HIGH = THREAD_PRIORITY_HIGHEST;
335 SRV_PRIORITY_CRITICAL = THREAD_PRIORITY_TIME_CRITICAL;
336
337 // values for srv_sfield field parameter
338 SRV_SERVERNAME = 0;
339 SRV_VERSION = 6;
340
341 // Length to indicate string is null terminated
342 SRV_NULLTERM = -1;
343
344 // values of msgtype parameter to srv_sendmsg
345 SRV_MSG_INFO = 1;
346 SRV_MSG_ERROR = 2;
347
348 // values of status parameter to srv_senddone
349 // Also: values for symbol parameters to srv_symbol when type = SRV_DONE
350 SRV_DONE_FINAL = $0000;
351 SRV_DONE_MORE = $0001;
352 SRV_DONE_ERROR = $0002;
353 SRV_DONE_COUNT = $0010;
354 SRV_DONE_RPC_IN_BATCH = $0080;
355
356 // return values of srv_paramstatus
357 SRV_PARAMRETURN = $0001;
358 SRV_PARAMDEFAULT = $0002;
359
360 // return values of srv_rpcoptions
361 SRV_RECOMPILE = $0001;
362 SRV_NOMETADATA = $0002;
363
364 // values of field parameter to srv_pfield
365 // SRV_LANGUAGE 1 already defined above
366 // SRV_EVENT 4 already defined above
367 SRV_SPID = 10;
368 SRV_NETSPID = 11;
369 SRV_TYPE = 12;
370 SRV_STATUS = 13;
371 SRV_RMTSERVER = 14;
372 SRV_HOST = 15;
373 SRV_USER = 16;
374 SRV_PWD = 17;
375 SRV_CPID = 18;
376 SRV_APPLNAME = 19;
377 SRV_TDS = 20;
378 SRV_CLIB = 21;
379 SRV_LIBVERS = 22;
380 SRV_ROWSENT = 23;
381 SRV_BCPFLAG = 24;
382 SRV_NATLANG = 25;
383 SRV_PIPEHANDLE = 26;
384 SRV_NETWORK_MODULE = 27;
385 SRV_NETWORK_VERSION = 28;
386 SRV_NETWORK_CONNECTION = 29;
387 SRV_LSECURE = 30;
388 SRV_SAXP = 31;
389 SRV_UNICODE_USER = 33;
390 SRV_UNICODE_PWD = 35;
391 SRV_SPROC_CODEPAGE = 36;
392
393 // return value of SRV_TDSVERSION macro
394 SRV_TDS_NONE = 0;
395 SRV_TDS_2_0 = 1;
396 SRV_TDS_3_4 = 2;
397 SRV_TDS_4_2 = 3;
398 SRV_TDS_6_0 = 4;
399 SRV_TDS_7_0 = 5;
400
401 // Return values from APIs
402 type
403 SRVRETCODE = Integer; // SUCCEED or FAIL
404 RETCODE = Integer;
405
406 const
407 SUCCEED = 1; // Successful return value
408 FAIL = 0; // Unsuccessful return value
409
410 SRV_DUPLICATE_HANDLER = 2; // additional return value for srv_pre/post_handle
411
412 //------------------------------------------------
413 //PreDeclare structures
414 //
415 {struct srv_server;
416 typedef struct srv_server SRV_SERVER;
417
418 struct srv_config;
419 typedef struct srv_config SRV_CONFIG;
420
421 struct srv_proc;
422 typedef struct srv_proc SRV_PROC;}
423 type
424 SRV_SERVER = Pointer;
425 SRV_CONFIG = Pointer;
426 SRV_PROC = Pointer;
427
428 //------------------------------------------------
429 //------------------------------------------------
430 // ODS MACROs & APIs
431
432 // Describing and sending a result set
433 function srv_describe(srvproc: SRV_PROC;
434 colnumber: Integer; column_name: PCHAR; namelen: Integer;
435 desttype, destlen, srctype, srclen: Integer; srcData: Pointer
436 ): Integer; cdecl;
437
438 function srv_setutype(srvproc: SRV_PROC; column: Integer; usertype: Longint):
439 Integer; cdecl;
440 function srv_setcoldata(srvproc: SRV_PROC; column: Integer; data: Pointer):
441 Integer; cdecl;
442 function srv_setcollen(srvproc: SRV_PROC; column, len: Integer): Integer; cdecl;
443 function srv_sendrow(srvproc: SRV_PROC): Integer; cdecl;
444 function srv_senddone(srvproc: SRV_PROC; status, curcmd: Word; count: Longint):
445 Integer; cdecl;
446
447 // Dealing with Extended Procedure parameters
448 function srv_rpcparams(srvproc: SRV_PROC): Integer; cdecl;
449 function srv_paraminfo(srvproc: SRV_PROC; n: Integer; pbType: PByte;
450 pcbMaxLen, pcbActualLen: PULONG; pbData: PByte; pfNull: PBOOL): Integer; cdecl;
451 function srv_paramsetoutput(srvproc: SRV_PROC;
452 n: Integer; pbData: PByte; cbLen: ULONG; fNull: BOOL): Integer; cdecl;
453
454 function srv_paramdata(srvproc: SRV_PROC; n: Integer): Pointer; cdecl;
455 function srv_paramlen(srvproc: SRV_PROC; n: Integer): Integer; cdecl;
456 function srv_parammaxlen(srvproc: SRV_PROC; n: Integer): Integer; cdecl;
457 function srv_paramtype(srvproc: SRV_PROC; n: Integer): Integer; cdecl;
458 function srv_paramset(srvproc: SRV_PROC; n: Integer; data: Pointer; int: Integer):
459 Integer; cdecl;
460
461 function srv_paramname(srvproc: SRV_PROC; n: Integer; var len: Integer): PChar;
462 cdecl;
463 function srv_paramnumber(srvproc: SRV_PROC; name: PChar; namelen: Integer):
464 Integer; cdecl;
465
466 //--------------------------------------------------------------
467 //--------------------------------------------------------------
468 // The rest of these APIs are still supported, in SQL Server 7.0,
469 // but may not be supported after SQL Server 7.0
470
471 // MACROs
472 { SRV_GETCONFIG(a) srv_getconfig ( a )
473 SRV_GETSERVER(a) srv_getserver ( a )
474 SRV_GOT_ATTENTION(a) srv_got_attention ( a )
475 SRV_EVENTDATA(a) srv_eventdata ( a )
476 SRV_IODEAD(a) srv_iodead ( a )
477 SRV_TDSVERSION(a) srv_tdsversion ( a )}
478
479 function srv_getconfig(server: SRV_SERVER): SRV_CONFIG; cdecl;
480 function srv_getserver(srvproc: SRV_PROC): SRV_SERVER; cdecl;
481 function srv_got_attention(srvproc: SRV_PROC): Bool; cdecl;
482 function srv_eventdata(srvproc: SRV_PROC): Pointer; cdecl;
483
484 // Memory
485 function srv_alloc(ulSize: Longint): Pointer; cdecl;
486 function srv_bmove(from: Pointer; pto: Pointer; count: Longint): Integer; cdecl;
487 function srv_bzero(location: Pointer; count: Longint): Integer; cdecl;
488 function srv_free(ptr: Pointer): Integer; cdecl;
489
490 function srv_config_fn(config: SRV_CONFIG; option: Longint; value: PChar; valuelen:
491 Integer): Integer; cdecl;
492 function srv_config_alloc: SRV_CONFIG; cdecl;
493 function srv_convert(srvproc: SRV_PROC; srctype: Integer; src: Pointer; srclen:
494 DBINT;
495 desttype: Integer; dest: Pointer; destlen: DBINT): Integer; cdecl;
496 {
497 int (* srv_errhandle(int (* handler)(SRV_SERVER * server,
498 SRV_PROC * srvproc,
499 int srverror,
500 BYTE severity,
501 BYTE state,
502 int oserrnum,
503 char * errtext,
504 int errtextlen,
505 char * oserrtext,
506 int oserrtextlen)))
507 ( SRV_SERVER * server,
508 SRV_PROC * srvproc,
509 int srverror,
510 BYTE severity,
511 BYTE state,
512 int oserrnum,
513 char * errtext,
514 int errtextlen,
515 char * oserrtext,
516 int oserrtextlen );
517 }
518 function srv_event_fn(srvproc: SRV_PROC; event: Integer; data: PByte): Integer;
519 cdecl;
520 function srv_getuserdata(srvproc: SRV_PROC): Pointer; cdecl;
521 function srv_getbindtoken(srvproc: SRV_PROC; token_buf: PChar): Integer; cdecl;
522 function srv_getdtcxact(srvproc: SRV_PROC; ppv: Pointer): Integer; cdecl;
523
524 //typedef int (* EventHandler)(void*);
525 type
526 EventHandler = Pointer;
527 function srv_handle(server: SRV_SERVER; int: Longint; handler: EventHandler):
528 EventHandler; cdecl;
529
530 function srv_impersonate_client(srvproc: SRV_PROC): Integer; cdecl;
531 function srv_init(config: SRV_CONFIG; connectname: PChar; namelen: Integer):
532 SRV_SERVER; cdecl;
533 function srv_iodead(srvproc: SRV_PROC): Bool; cdecl;
534
535 function srv_langcpy(srvproc: SRV_PROC; start, nbytes: Longint; buffer: PChar):
536 Longint; cdecl;
537 function srv_langlen(srvproc: SRV_PROC): Longint; cdecl;
538 function srv_langptr(srvproc: SRV_PROC): Pointer; cdecl;
539
540 function srv_log(server: SRV_SERVER; datestamp: Bool; msg: PChar; msglen: Integer):
541 Integer; cdecl;
542 function srv_paramstatus(srvproc: SRV_PROC; n: Integer): Integer; cdecl;
543 function srv_pfield(srvproc: SRV_PROC; field: Integer; len: PInteger): PChar; cdecl;
544
545 function srv_returnval(srvproc: SRV_PROC; value_name: PDBCHAR; len: Integer;
546 status: Byte;
547 iType, maxlen, datalen: DBINT; value: PByte): Integer; cdecl;
548
549 function srv_revert_to_self(srvproc: SRV_PROC): Integer; cdecl;
550
551 function srv_rpcdb(srvproc: SRV_PROC; len: PInteger): PChar; cdecl;
552 function srv_rpcname(srvproc: SRV_PROC; len: PInteger): PChar; cdecl;
553 function srv_rpcnumber(srvproc: SRV_PROC): Integer; cdecl;
554 function srv_rpcoptions(srvproc: SRV_PROC): Word; cdecl;
555 function srv_rpcowner(srvproc: SRV_PROC; len: PInteger): PChar; cdecl;
556
557 function srv_run(server: SRV_SERVER): Integer; cdecl;
558
559 function srv_sendmsg(srvproc: SRV_PROC;
560 msgtype: Integer; msgnum: DBINT; msgClass, state: DBTINYINT;
561 rpcname: PChar; rpcnamelen: Integer;
562 linenum: Word; msg: PChar; msglen: Integer): Integer; cdecl;
563
564 function srv_ansi_sendmsg(srvproc: SRV_PROC;
565 msgtype: Integer; msgnum: DBINT; msgClass, state: DBTINYINT;
566 rpcname: PChar; rpcnamelen: Integer;
567 linenum: Word; msg: PChar; msglen: Integer): Integer; cdecl;
568
569 function srv_sendstatus(srvproc: SRV_PROC; status: Longint): Integer; cdecl;
570 function srv_setuserdata(srvproc: SRV_PROC; ptr: Pointer): Integer; cdecl;
571 function srv_sfield(server: SRV_SERVER; field: Integer; len: PInteger): PChar;
572 cdecl;
573 function srv_symbol(iType, symbol: Integer; len: PInteger): PChar; cdecl;
574 function srv_tdsversion(srvproc: SRV_PROC): Integer; cdecl;
575 function srv_writebuf(srvproc: SRV_PROC; ptr: Pointer; count: Word): Integer; cdecl;
576 function srv_willconvert(srctype, desttype: Integer): Bool; cdecl;
577 procedure srv_ackattention(srvproc: SRV_PROC); cdecl;
578 function srv_terminatethread(srvproc: SRV_PROC): Integer; cdecl;
579 function srv_sendstatistics(srvproc: SRV_PROC): Integer; cdecl;
580 function srv_clearstatistics(srvproc: SRV_PROC): Integer; cdecl;
581 function srv_setevent(server: SRV_SERVER; event: Integer): Integer; cdecl;
582 function srv_message_handler(srvproc: SRV_PROC;
583 errornum: Integer; severity, state: Byte; oserrnum: Integer; errtext: PChar;
584 errtextlen: Integer; oserrtext: PChar; oserrtextlen: Integer): Integer; cdecl;
585
586 function srv_pre_handle(server: SRV_SERVER; srvproc: SRV_PROC;
587 event: Longint; handler: EventHandler; remove: Bool): Integer;
588 cdecl;
589 function srv_post_handle(server: SRV_SERVER; srvproc: SRV_PROC;
590 event: Longint; handler: EventHandler; remove: Bool): Integer;
591 cdecl;
592
593 function srv_post_completion_queue(srvproc: SRV_PROC; inbuf: PChar; inbuflen:
594 PChar): Integer; cdecl;
595 function srv_IgnoreAnsiToOem(srvproc: SRV_PROC; bTF: BOOL): Integer; cdecl;
596
597 //#ifdef __cplusplus
598 //}
599 //#endif
600
601 //#pragma pack()
602
603 const
604 SS_MAJOR_VERSION = 7;
605 SS_MINOR_VERSION = 00;
606 SS_LEVEL_VERSION = 0000;
607 SS_MINIMUM_VERSION = '7.00.00.0000';
608 ODS_VERSION = ((SS_MAJOR_VERSION shl 24) or (SS_MINOR_VERSION shl 16));
609
610 //#endif //_ODS_SRV_H_
611
612 //////////////////////////////////////////////////////////////////
613 // Suggested implementation of __GetXpVersion
614 //
615 //__declspec(dllexport) ULONG __GetXpVersion()
616 // {
617 // return ODS_VERSION;
618 // }
619 //////////////////////////////////////////////////////////////////
620
621 implementation
622
623 const
624 sLibName = 'Opends60.DLL';
625
626
627 function srv_describe; external sLibName name 'srv_describe';
628 function srv_setutype; external sLibName name 'srv_setutype';
629 function srv_setcoldata; external sLibName name 'srv_setcoldata';
630 function srv_setcollen; external sLibName name 'srv_setcollen';
631 function srv_sendrow; external sLibName name 'srv_sendrow';
632 function srv_senddone; external sLibName name 'srv_senddone';
633
634 // Dealing with Extended Procedure parameters
635 function srv_rpcparams; external sLibName name 'srv_rpcparams';
636 function srv_paraminfo; external sLibName name 'srv_paraminfo';
637 function srv_paramsetoutput; external sLibName name 'srv_paramsetoutput';
638
639 function srv_paramdata; external sLibName name 'srv_paramdata';
640 function srv_paramlen; external sLibName name 'srv_paramlen';
641 function srv_parammaxlen; external sLibName name 'srv_parammaxlen';
642 function srv_paramtype; external sLibName name 'srv_paramtype';
643 function srv_paramset; external sLibName name 'srv_paramset';
644
645 function srv_paramname; external sLibName name 'srv_paramname';
646 function srv_paramnumber; external sLibName name 'srv_paramnumber';
647
648 //--------------------------------------------------------------
649 // The rest of these APIs are still supported, in SQL Server 7.0,
650 // but may not be supported after SQL Server 7.0
651
652 function srv_getconfig; external sLibName name 'srv_getconfig';
653 function srv_getserver; external sLibName name 'srv_getserver';
654 function srv_got_attention; external sLibName name 'srv_got_attention';
655 function srv_eventdata; external sLibName name 'srv_eventdata';
656
657 // Memory
658 function srv_alloc; external sLibName name 'srv_alloc';
659 function srv_bmove; external sLibName name 'srv_bmove';
660 function srv_bzero; external sLibName name 'srv_bzero';
661 function srv_free; external sLibName name 'srv_free';
662
663 function srv_config_fn; external sLibName name 'srv_config';
664 function srv_config_alloc; external sLibName name 'srv_config_alloc';
665 function srv_convert; external sLibName name 'srv_convert';
666 function srv_event_fn; external sLibName name 'srv_event';
667 function srv_getuserdata; external sLibName name 'srv_getuserdata';
668 function srv_getbindtoken; external sLibName name 'srv_getbindtoken';
669 function srv_getdtcxact; external sLibName name 'srv_getdtcxact';
670 function srv_handle; external sLibName name 'srv_handle';
671 function srv_impersonate_client; external sLibName name
672 'srv_impersonate_client';
673 function srv_init; external sLibName name 'srv_init';
674 function srv_iodead; external sLibName name 'srv_iodead';
675 function srv_langcpy; external sLibName name 'srv_langcpy';
676 function srv_langlen; external sLibName name 'srv_langlen';
677 function srv_langptr; external sLibName name 'srv_langptr';
678 function srv_log; external sLibName name 'srv_log';
679 function srv_paramstatus; external sLibName name 'srv_paramstatus';
680 function srv_pfield; external sLibName name 'srv_pfield';
681 function srv_returnval; external sLibName name 'srv_returnval';
682 function srv_revert_to_self; external sLibName name 'srv_revert_to_self';
683
684 function srv_rpcdb; external sLibName name 'srv_rpcdb';
685 function srv_rpcname; external sLibName name 'srv_rpcname';
686 function srv_rpcnumber; external sLibName name 'srv_rpcnumber';
687 function srv_rpcoptions; external sLibName name 'srv_rpcoptions';
688 function srv_rpcowner; external sLibName name 'srv_rpcowner';
689
690 function srv_run; external sLibName name 'srv_run';
691
692 function srv_sendmsg; external sLibName name 'srv_sendmsg';
693 function srv_ansi_sendmsg; external sLibName name 'srv_ansi_sendmsg';
694
695 function srv_sendstatus; external sLibName name 'srv_sendstatus';
696 function srv_setuserdata; external sLibName name 'srv_setuserdata';
697 function srv_sfield; external sLibName name 'srv_sfield';
698 function srv_symbol; external sLibName name 'srv_symbol';
699 function srv_tdsversion; external sLibName name 'srv_tdsversion';
700 function srv_writebuf; external sLibName name 'srv_writebuf';
701 function srv_willconvert; external sLibName name 'srv_willconvert';
702 procedure srv_ackattention; external sLibName name 'srv_ackattention';
703 function srv_terminatethread; external sLibName name
704 'srv_terminatethread';
705 function srv_sendstatistics; external sLibName name 'srv_sendstatistics';
706 function srv_clearstatistics; external sLibName name
707 'srv_clearstatistics';
708 function srv_setevent; external sLibName name 'srv_setevent';
709 function srv_message_handler; external sLibName name
710 'srv_message_handler';
711
712 function srv_pre_handle; external sLibName name 'srv_pre_handle';
713 function srv_post_handle; external sLibName name 'srv_post_handle';
714 function srv_post_completion_queue; external sLibName name
715 'srv_post_completion_queue';
716 function srv_IgnoreAnsiToOem; external sLibName name
717 'srv_IgnoreAnsiToOem';
718
719 end.
|