-
Notifications
You must be signed in to change notification settings - Fork 0
/
oci_unit.pas
128 lines (106 loc) · 3.2 KB
/
oci_unit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit oci_unit;
interface
uses
sysutils, windows;
const
OCI_HTYPE_ENV = 1; // environment handle
OCI_HTYPE_ERROR = 2; // error handle
OCI_SUCCESS = 0; // maps to SQL_SUCCESS of SAG CLI
OCI_ERROR = -1; // maps to SQL_ERROR
OCI_SUCCESS_WITH_INFO = 1; // maps to SQL_SUCCESS_WITH_INFO
OCI_DEFAULT = $00; // the default value for parameters and attributes
OCI_OBJECT = $02; // the application is in object environment
OCI_NUMBER_SIZE = 22;
dllOK = 0;
dllNoFile = 1; // No dll file found
type
sb4 = LongInt;
ub4 = LongInt;
sword = Integer;
uword = Integer;
ub1 = Byte;
OCINumber = record
OCINumberPart: array[0..OCI_NUMBER_SIZE] of ub1;
end;
OCIEnv = pointer; // OCI environment handle
OCIError = pointer; // OCI error handle
var
HDLL: THandle;
OCIDLL: String = ''; // Name of OCI DLL
InitOCILog: String = ''; // InitOCI logging
OCIHandleAlloc:
function(parenth:pointer;
var hndlpp:pointer;
htype: ub4;
xtramem_sz: Integer;
usrmempp: pointer): sword; cdecl;
OCIHandleFree:
function(hndlp: pointer;
hType: ub4): sword; cdecl;
OCIErrorGet:
function(hndlp: pointer;
recordno: ub4;
sqlstate: PAnsiChar;
var errcodep: sb4;
bufp: PAnsiChar;
bufsiz: ub4;
eType: ub4): sword; cdecl;
OCIEnvCreate:
function(var envhp: OCIEnv;
mode: ub4;
ctxp: Pointer;
malocfp: Pointer;
ralocfp: Pointer;
mfreefp: Pointer;
xtramemsz: Integer;
usrmempp: Pointer): sword; cdecl;
OCINumberFromReal:
function(errhp: OCIError;
rnum: Pointer;
rnum_length: uword;
number: Pointer): sword; cdecl;
OCITerminate:
function(mode: ub4): sword; cdecl;
procedure InitOCI;
function DLLInit: Integer;
procedure DLLExit;
implementation
procedure InitOCI;
var Error: Integer;
oraclehome: string;
begin
oraclehome := GetEnvironmentVariable('ORACLE_HOME');
if oraclehome = '' then
OCIDLL := 'oci.dll'
else
OCIDLL := oraclehome + '\oci.dll';
Error := DLLInit;
if Error <> dllOK then
begin
DLLExit;
raise Exception.Create('Initialization error: ' + OCIDLL);
end
else
InitOCILog := 'oci.dll forced to ' + OCIDLL;
end;
function DLLInit:Integer;
begin
Result := dllOK;
HDLL := LoadLibrary(PChar(OCIDLL));
if HDLL <> 0 then
begin
OCIHandleAlloc := GetProcAddress(HDLL, 'OCIHandleAlloc');
OCIEnvCreate := GetProcAddress(HDLL, 'OCIEnvCreate');
OCINumberFromReal := GetProcAddress(HDLL, 'OCINumberFromReal');
OCIHandleFree := GetProcAddress(HDLL, 'OCIHandleFree');
OCITerminate := GetProcAddress(HDLL, 'OCITerminate');
OCIErrorGet := GetProcAddress(HDLL, 'OCIErrorGet');
end
else
Result := dllNoFile;
end;
procedure DLLExit;
begin
if HDLL <> 0 then FreeLibrary(HDLL);
end;
end.