90 |
|
FIREBIRD_EMBEDDED = 'fbembed.dll'; |
91 |
|
{$ENDIF} |
92 |
|
|
93 |
– |
{$IFNDEF FPC} |
94 |
– |
type |
95 |
– |
TLibHandle = THandle; |
96 |
– |
|
93 |
|
const |
94 |
< |
NilHandle = 0; |
95 |
< |
DirectorySeparator = '\'; |
96 |
< |
{$ENDIF} |
94 |
> |
IBLocalBufferLength = 512; |
95 |
> |
IBBigLocalBufferLength = IBLocalBufferLength * 2; |
96 |
> |
IBHugeLocalBufferLength = IBBigLocalBufferLength * 20; |
97 |
|
|
98 |
|
type |
99 |
|
TStatusVector = array[0..19] of NativeInt; |
121 |
|
procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages); |
122 |
|
end; |
123 |
|
|
124 |
+ |
{ TFBLibrary } |
125 |
+ |
|
126 |
+ |
TFBLibrary = class(TFBInterfacedObject,IFirebirdLibrary) |
127 |
+ |
private |
128 |
+ |
class var FEnvSetupDone: boolean; |
129 |
+ |
class var FLibraryList: array of IFirebirdLibrary; |
130 |
+ |
FFirebirdAPI: IFirebirdAPI; |
131 |
+ |
FRequestedLibName: string; |
132 |
+ |
function LoadIBLibrary: boolean; |
133 |
+ |
protected |
134 |
+ |
FFBLibraryName: string; |
135 |
+ |
FIBLibrary: TLibHandle; |
136 |
+ |
procedure FreeFBLibrary; |
137 |
+ |
function GetOverrideLibName: string; |
138 |
+ |
class procedure SetupEnvironment; |
139 |
+ |
protected |
140 |
+ |
function GetFirebird3API: IFirebirdAPI; virtual; abstract; |
141 |
+ |
function GetLegacyFirebirdAPI: IFirebirdAPI; virtual; abstract; |
142 |
+ |
public |
143 |
+ |
constructor Create(aLibPathName: string=''); |
144 |
+ |
destructor Destroy; override; |
145 |
+ |
class function GetFBLibrary(aLibPathName: string): IFirebirdLibrary; |
146 |
+ |
class procedure FreeLibraries; |
147 |
+ |
|
148 |
+ |
{IFirebirdLibrary} |
149 |
+ |
function GetHandle: TLibHandle; |
150 |
+ |
function GetLibraryName: string; |
151 |
+ |
function GetLibraryFilePath: string; |
152 |
+ |
function GetFirebirdAPI: IFirebirdAPI; |
153 |
+ |
property IBLibrary: TLibHandle read FIBLibrary; |
154 |
+ |
end; |
155 |
+ |
|
156 |
|
{ TFBClientAPI } |
157 |
|
|
158 |
|
TFBClientAPI = class(TFBInterfacedObject) |
159 |
|
private |
132 |
– |
FOwnsIBLibrary: boolean; |
160 |
|
class var FIBCS: TRTLCriticalSection; |
134 |
– |
procedure LoadIBLibrary; |
161 |
|
protected |
162 |
< |
class var FFBLibraryName: string; |
137 |
< |
class var IBLibrary: TLibHandle; |
138 |
< |
{$IFDEF WINDOWS} |
139 |
< |
class var FFBLibraryPath: string; |
140 |
< |
{$ENDIF} |
162 |
> |
FFBLibrary: TFBLibrary; |
163 |
|
function GetProcAddr(ProcName: PAnsiChar): Pointer; |
142 |
– |
function GetOverrideLibName: string; |
143 |
– |
{$IFDEF UNIX} |
144 |
– |
function GetFirebirdLibList: string; virtual; abstract; |
145 |
– |
{$ENDIF} |
146 |
– |
procedure LoadInterface; virtual; |
164 |
|
public |
165 |
|
{Taken from legacy API} |
166 |
|
isc_sqlcode: Tisc_sqlcode; |
167 |
|
isc_sql_interprete: Tisc_sql_interprete; |
151 |
– |
isc_interprete: Tisc_interprete; |
168 |
|
isc_event_counts: Tisc_event_counts; |
169 |
|
isc_event_block: Tisc_event_block; |
170 |
|
isc_free: Tisc_free; |
171 |
|
|
172 |
< |
constructor Create; |
157 |
< |
destructor Destroy; override; |
172 |
> |
constructor Create(aFBLibrary: TFBLibrary); |
173 |
|
procedure IBAlloc(var P; OldSize, NewSize: Integer); |
174 |
|
procedure IBDataBaseError; |
175 |
< |
procedure SetupEnvironment; |
175 |
> |
function LoadInterface: boolean; virtual; |
176 |
> |
function GetAPI: IFirebirdAPI; virtual; abstract; |
177 |
> |
{$IFDEF UNIX} |
178 |
> |
function GetFirebirdLibList: string; virtual; abstract; |
179 |
> |
{$ENDIF} |
180 |
|
|
181 |
|
{Encode/Decode} |
182 |
|
procedure EncodeInteger(aValue: integer; len: integer; buffer: PByte); |
187 |
|
function SQLDecodeTime(bufptr: PByte): TDateTime; virtual; abstract; |
188 |
|
procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); virtual; abstract; |
189 |
|
function SQLDecodeDateTime(bufptr: PByte): TDateTime; virtual; abstract; |
190 |
< |
|
190 |
> |
function FormatStatus(Status: TFBStatus): AnsiString; virtual; abstract; |
191 |
|
|
192 |
|
{IFirebirdAPI} |
193 |
|
function GetStatus: IStatus; virtual; abstract; |
194 |
|
function IsLibraryLoaded: boolean; |
195 |
|
function IsEmbeddedServer: boolean; virtual; abstract; |
196 |
< |
function GetLibraryName: string; |
197 |
< |
function GetCharsetName(CharSetID: integer): AnsiString; |
198 |
< |
function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean; |
199 |
< |
function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean; |
200 |
< |
function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean; |
182 |
< |
function CharSetWidth(CharSetID: integer; var Width: integer): boolean; |
183 |
< |
end; |
184 |
< |
|
185 |
< |
var FirebirdClientAPI: TFBClientAPI = nil; |
196 |
> |
function GetFBLibrary: IFirebirdLibrary; |
197 |
> |
function GetImplementationVersion: AnsiString; |
198 |
> |
function GetClientMajor: integer; virtual; abstract; |
199 |
> |
function GetClientMinor: integer; virtual; abstract; |
200 |
> |
end; |
201 |
|
|
202 |
|
implementation |
203 |
|
|
204 |
< |
uses IBUtils, Registry, {$IFDEF Unix} initc, {$ENDIF} |
204 |
> |
uses IBUtils, Registry, |
205 |
> |
{$IFDEF Unix} initc, dl, {$ENDIF} |
206 |
|
{$IFDEF FPC} |
207 |
|
{$IFDEF WINDOWS } |
208 |
|
WinDirs, |
218 |
|
{$I 'include/wloadlibrary.inc'} |
219 |
|
{$ENDIF} |
220 |
|
|
221 |
< |
type |
222 |
< |
TCharsetMap = record |
223 |
< |
CharsetID: integer; |
224 |
< |
CharSetName: AnsiString; |
225 |
< |
CharSetWidth: integer; |
226 |
< |
CodePage: TSystemCodePage; |
221 |
> |
|
222 |
> |
{ TFBLibrary } |
223 |
> |
|
224 |
> |
function TFBLibrary.GetOverrideLibName: string; |
225 |
> |
begin |
226 |
> |
Result := FFBLibraryName; |
227 |
> |
if (Result = '') and AllowUseOfFBLIB then |
228 |
> |
Result := GetEnvironmentVariable('FBLIB'); |
229 |
> |
if Result = '' then |
230 |
> |
begin |
231 |
> |
if assigned(OnGetLibraryName) then |
232 |
> |
OnGetLibraryName(Result) |
233 |
|
end; |
234 |
+ |
end; |
235 |
|
|
236 |
< |
const |
237 |
< |
CharSetMap: array [0..69] of TCharsetMap = ( |
238 |
< |
(CharsetID: 0; CharSetName: 'NONE'; CharSetWidth: 1; CodePage: CP_ACP), |
239 |
< |
(CharsetID: 1; CharSetName: 'OCTETS'; CharSetWidth: 1; CodePage: CP_NONE), |
240 |
< |
(CharsetID: 2; CharSetName: 'ASCII'; CharSetWidth: 1; CodePage: CP_ASCII), |
241 |
< |
(CharsetID: 3; CharSetName: 'UNICODE_FSS'; CharSetWidth: 3; CodePage: CP_UTF8), |
242 |
< |
(CharsetID: 4; CharSetName: 'UTF8'; CharSetWidth: 4; CodePage: CP_UTF8), |
243 |
< |
(CharsetID: 5; CharSetName: 'SJIS_0208'; CharSetWidth: 2; CodePage: 20932), |
244 |
< |
(CharsetID: 6; CharSetName: 'EUCJ_0208'; CharSetWidth: 2; CodePage: 20932), |
245 |
< |
(CharsetID: 7; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
246 |
< |
(CharsetID: 8; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
247 |
< |
(CharsetID: 9; CharSetName: 'DOS737'; CharSetWidth: 1; CodePage: 737), |
248 |
< |
(CharsetID: 10; CharSetName: 'DOS437'; CharSetWidth: 1; CodePage: 437), |
249 |
< |
(CharsetID: 11; CharSetName: 'DOS850'; CharSetWidth: 1; CodePage: 850), |
250 |
< |
(CharsetID: 12; CharSetName: 'DOS865'; CharSetWidth: 1; CodePage: 865), |
251 |
< |
(CharsetID: 13; CharSetName: 'DOS860'; CharSetWidth: 1; CodePage: 860), |
252 |
< |
(CharsetID: 14; CharSetName: 'DOS863'; CharSetWidth: 1; CodePage: 863), |
253 |
< |
(CharsetID: 15; CharSetName: 'DOS775'; CharSetWidth: 1; CodePage: 775), |
254 |
< |
(CharsetID: 16; CharSetName: 'DOS858'; CharSetWidth: 1; CodePage: 858), |
255 |
< |
(CharsetID: 17; CharSetName: 'DOS862'; CharSetWidth: 1; CodePage: 862), |
256 |
< |
(CharsetID: 18; CharSetName: 'DOS864'; CharSetWidth: 1; CodePage: 864), |
257 |
< |
(CharsetID: 19; CharSetName: 'NEXT'; CharSetWidth: 1; CodePage: CP_NONE), |
258 |
< |
(CharsetID: 20; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
259 |
< |
(CharsetID: 21; CharSetName: 'ISO8859_1'; CharSetWidth: 1; CodePage: 28591), |
260 |
< |
(CharsetID: 22; CharSetName: 'ISO8859_2'; CharSetWidth: 1; CodePage: 28592), |
261 |
< |
(CharsetID: 23; CharSetName: 'ISO8859_3'; CharSetWidth: 1; CodePage: 28593), |
239 |
< |
(CharsetID: 24; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
240 |
< |
(CharsetID: 25; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
241 |
< |
(CharsetID: 26; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
242 |
< |
(CharsetID: 27; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
243 |
< |
(CharsetID: 28; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
244 |
< |
(CharsetID: 29; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
245 |
< |
(CharsetID: 30; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
246 |
< |
(CharsetID: 31; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
247 |
< |
(CharsetID: 32; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
248 |
< |
(CharsetID: 33; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
249 |
< |
(CharsetID: 34; CharSetName: 'ISO8859_4'; CharSetWidth: 1; CodePage: 28594), |
250 |
< |
(CharsetID: 35; CharSetName: 'ISO8859_5'; CharSetWidth: 1; CodePage: 28595), |
251 |
< |
(CharsetID: 36; CharSetName: 'ISO8859_6'; CharSetWidth: 1; CodePage: 28596), |
252 |
< |
(CharsetID: 37; CharSetName: 'ISO8859_7'; CharSetWidth: 1; CodePage: 28597), |
253 |
< |
(CharsetID: 38; CharSetName: 'ISO8859_8'; CharSetWidth: 1; CodePage: 28598), |
254 |
< |
(CharsetID: 39; CharSetName: 'ISO8859_9'; CharSetWidth: 1; CodePage: 28599), |
255 |
< |
(CharsetID: 40; CharSetName: 'ISO8859_13'; CharSetWidth: 1; CodePage: 28603), |
256 |
< |
(CharsetID: 41; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
257 |
< |
(CharsetID: 42; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
258 |
< |
(CharsetID: 43; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
259 |
< |
(CharsetID: 44; CharSetName: 'KSC_5601'; CharSetWidth: 2; CodePage: 949), |
260 |
< |
(CharsetID: 45; CharSetName: 'DOS852'; CharSetWidth: 1; CodePage: 852), |
261 |
< |
(CharsetID: 46; CharSetName: 'DOS857'; CharSetWidth: 1; CodePage: 857), |
262 |
< |
(CharsetID: 47; CharSetName: 'DOS861'; CharSetWidth: 1; CodePage: 861), |
263 |
< |
(CharsetID: 48; CharSetName: 'DOS866'; CharSetWidth: 1; CodePage: 866), |
264 |
< |
(CharsetID: 49; CharSetName: 'DOS869'; CharSetWidth: 1; CodePage: 869), |
265 |
< |
(CharsetID: 50; CharSetName: 'CYRL'; CharSetWidth: 1; CodePage: 1251), |
266 |
< |
(CharsetID: 51; CharSetName: 'WIN1250'; CharSetWidth: 1; CodePage: 1250), |
267 |
< |
(CharsetID: 52; CharSetName: 'WIN1251'; CharSetWidth: 1; CodePage: 1251), |
268 |
< |
(CharsetID: 53; CharSetName: 'WIN1252'; CharSetWidth: 1; CodePage: 1252), |
269 |
< |
(CharsetID: 54; CharSetName: 'WIN1253'; CharSetWidth: 1; CodePage: 1253), |
270 |
< |
(CharsetID: 55; CharSetName: 'WIN1254'; CharSetWidth: 1; CodePage: 1254), |
271 |
< |
(CharsetID: 56; CharSetName: 'BIG_5'; CharSetWidth: 2; CodePage: 950), |
272 |
< |
(CharsetID: 57; CharSetName: 'GB_2312'; CharSetWidth: 2; CodePage: 936), |
273 |
< |
(CharsetID: 58; CharSetName: 'WIN1255'; CharSetWidth: 1; CodePage: 1255), |
274 |
< |
(CharsetID: 59; CharSetName: 'WIN1256'; CharSetWidth: 1; CodePage: 1256), |
275 |
< |
(CharsetID: 60; CharSetName: 'WIN1257'; CharSetWidth: 1; CodePage: 1257), |
276 |
< |
(CharsetID: 61; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
277 |
< |
(CharsetID: 62; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE), |
278 |
< |
(CharsetID: 63; CharSetName: 'KOI8R'; CharSetWidth: 1; CodePage: 20866), |
279 |
< |
(CharsetID: 64; CharSetName: 'KOI8U'; CharSetWidth: 1; CodePage: 21866), |
280 |
< |
(CharsetID: 65; CharSetName: 'WIN1258'; CharSetWidth: 1; CodePage: 1258), |
281 |
< |
(CharsetID: 66; CharSetName: 'TIS620'; CharSetWidth: 1; CodePage: 874), |
282 |
< |
(CharsetID: 67; CharSetName: 'GBK'; CharSetWidth: 2; CodePage: 936), |
283 |
< |
(CharsetID: 68; CharSetName: 'CP943C'; CharSetWidth: 2; CodePage: 943), |
284 |
< |
(CharsetID: 69; CharSetName: 'GB18030'; CharSetWidth: 4; CodePage: 54936) |
285 |
< |
); |
286 |
< |
|
287 |
< |
{$IFDEF Unix} |
288 |
< |
{SetEnvironmentVariable doesn't exist so we have to use C Library} |
289 |
< |
function setenv(name:Pchar; value:Pchar; replace:integer):integer;cdecl;external clib name 'setenv'; |
290 |
< |
function unsetenv(name:Pchar):integer;cdecl;external clib name 'unsetenv'; |
291 |
< |
function SetEnvironmentVariable(name:PAnsiChar; value:PAnsiChar):boolean; |
292 |
< |
// Set environment variable; if empty string given, remove it. |
236 |
> |
procedure TFBLibrary.FreeFBLibrary; |
237 |
> |
begin |
238 |
> |
if FIBLibrary <> NilHandle then |
239 |
> |
FreeLibrary(FIBLibrary); |
240 |
> |
FIBLibrary := NilHandle; |
241 |
> |
end; |
242 |
> |
|
243 |
> |
function TFBLibrary.GetLibraryName: string; |
244 |
> |
begin |
245 |
> |
Result := ExtractFileName(FFBLibraryName); |
246 |
> |
end; |
247 |
> |
|
248 |
> |
function TFBLibrary.GetFirebirdAPI: IFirebirdAPI; |
249 |
> |
begin |
250 |
> |
Result := FFirebirdAPI; |
251 |
> |
end; |
252 |
> |
|
253 |
> |
constructor TFBLibrary.Create(aLibPathName: string); |
254 |
> |
begin |
255 |
> |
inherited Create; |
256 |
> |
SetupEnvironment; |
257 |
> |
FFBLibraryName := aLibPathName; |
258 |
> |
FIBLibrary := NilHandle; |
259 |
> |
FFirebirdAPI := GetFirebird3API; |
260 |
> |
FRequestedLibName := aLibPathName; |
261 |
> |
if aLibPathName <> '' then |
262 |
|
begin |
263 |
< |
result:=false; //assume failure |
264 |
< |
if value = '' then |
265 |
< |
begin |
266 |
< |
// Assume user wants to remove variable. |
267 |
< |
if unsetenv(name)=0 then result:=true; |
268 |
< |
end |
269 |
< |
else |
263 |
> |
SetLength(FLibraryList,Length(FLibraryList)+1); |
264 |
> |
FLibraryList[Length(FLibraryList)-1] := self; |
265 |
> |
end; |
266 |
> |
if FFirebirdAPI <> nil then |
267 |
> |
begin |
268 |
> |
{First try Firebird 3} |
269 |
> |
if not LoadIBLibrary or not (FFirebirdAPI as TFBClientAPI).LoadInterface then |
270 |
> |
FFirebirdAPI := nil; |
271 |
> |
end; |
272 |
> |
|
273 |
> |
if FFirebirdAPI = nil then |
274 |
> |
begin |
275 |
> |
{now try Firebird 2.5. Under Unix we need to reload the library in case we |
276 |
> |
are to use the embedded library} |
277 |
> |
FFirebirdAPI := GetLegacyFirebirdAPI; |
278 |
> |
if FFirebirdAPI <> nil then |
279 |
|
begin |
280 |
< |
// Non empty so set the variable |
281 |
< |
if setenv(name, value, 1)=0 then result:=true; |
280 |
> |
{$IFDEF UNIX} |
281 |
> |
FreeFBLibrary; |
282 |
> |
{$ENDIF} |
283 |
> |
if not LoadIBLibrary or not (FFirebirdAPI as TFBClientAPI).LoadInterface then |
284 |
> |
FFirebirdAPI := nil; |
285 |
|
end; |
286 |
|
end; |
287 |
< |
{$ENDIF} |
287 |
> |
{Note: FFirebirdAPI will be set to nil if the Firebird API fails to load} |
288 |
> |
end; |
289 |
|
|
290 |
< |
{ TFBClientAPI } |
290 |
> |
destructor TFBLibrary.Destroy; |
291 |
> |
begin |
292 |
> |
FFirebirdAPI := nil; |
293 |
> |
FreeFBLibrary; |
294 |
> |
inherited Destroy; |
295 |
> |
end; |
296 |
|
|
297 |
< |
constructor TFBClientAPI.Create; |
297 |
> |
class function TFBLibrary.GetFBLibrary(aLibPathName: string): IFirebirdLibrary; |
298 |
> |
var i: integer; |
299 |
|
begin |
300 |
< |
inherited Create; |
301 |
< |
LoadIBLibrary; |
314 |
< |
if (IBLibrary <> NilHandle) then |
300 |
> |
Result := nil; |
301 |
> |
if aLibPathName <> '' then |
302 |
|
begin |
303 |
< |
SetupEnvironment; |
304 |
< |
LoadInterface; |
303 |
> |
for i := 0 to Length(FLibraryList) - 1 do |
304 |
> |
if (FLibraryList[i] as TFBLibrary).FRequestedLibName = aLibPathName then |
305 |
> |
begin |
306 |
> |
Result := FLibraryList[i]; |
307 |
> |
Exit; |
308 |
> |
end; |
309 |
> |
Result := Create(aLibPathName); |
310 |
|
end; |
311 |
< |
FirebirdClientAPI := self; |
311 |
> |
|
312 |
|
end; |
313 |
|
|
314 |
< |
destructor TFBClientAPI.Destroy; |
314 |
> |
class procedure TFBLibrary.FreeLibraries; |
315 |
> |
var i: integer; |
316 |
|
begin |
317 |
< |
FirebirdClientAPI := nil; |
318 |
< |
if FOwnsIBLibrary and (IBLibrary <> NilHandle) then |
319 |
< |
FreeLibrary(IBLibrary); |
320 |
< |
IBLibrary := NilHandle; |
321 |
< |
inherited Destroy; |
317 |
> |
for i := 0 to Length(FLibraryList) - 1 do |
318 |
> |
FLibraryList[i] := nil; |
319 |
> |
SetLength(FLibraryList,0); |
320 |
> |
end; |
321 |
> |
|
322 |
> |
function TFBLibrary.GetHandle: TLibHandle; |
323 |
> |
begin |
324 |
> |
Result := FIBLibrary; |
325 |
> |
end; |
326 |
> |
|
327 |
> |
{ TFBClientAPI } |
328 |
> |
|
329 |
> |
constructor TFBClientAPI.Create(aFBLibrary: TFBLibrary); |
330 |
> |
begin |
331 |
> |
inherited Create; |
332 |
> |
FFBLibrary := aFBLibrary; |
333 |
|
end; |
334 |
|
|
335 |
|
procedure TFBClientAPI.IBAlloc(var P; OldSize, NewSize: Integer); |
347 |
|
|
348 |
|
{Under Unixes, if using an embedded server then set up local TMP and LOCK Directories} |
349 |
|
|
346 |
– |
procedure TFBClientAPI.SetupEnvironment; |
347 |
– |
var TmpDir: AnsiString; |
348 |
– |
begin |
349 |
– |
{$IFDEF UNIX} |
350 |
– |
TmpDir := GetTempDir + |
351 |
– |
DirectorySeparator + 'firebird_' + sysutils.GetEnvironmentVariable('USER'); |
352 |
– |
if sysutils.GetEnvironmentVariable('FIREBIRD_TMP') = '' then |
353 |
– |
begin |
354 |
– |
if not DirectoryExists(tmpDir) then |
355 |
– |
mkdir(tmpDir); |
356 |
– |
SetEnvironmentVariable('FIREBIRD_TMP',PAnsiChar(TmpDir)); |
357 |
– |
end; |
358 |
– |
if sysutils.GetEnvironmentVariable('FIREBIRD_LOCK') = '' then |
359 |
– |
begin |
360 |
– |
if not DirectoryExists(tmpDir) then |
361 |
– |
mkdir(tmpDir); |
362 |
– |
SetEnvironmentVariable('FIREBIRD_LOCK',PAnsiChar(TmpDir)); |
363 |
– |
end; |
364 |
– |
{$ENDIF} |
365 |
– |
end; |
366 |
– |
|
350 |
|
procedure TFBClientAPI.EncodeInteger(aValue: integer; len: integer; buffer: PByte); |
351 |
|
begin |
352 |
|
while len > 0 do |
360 |
|
|
361 |
|
function TFBClientAPI.IsLibraryLoaded: boolean; |
362 |
|
begin |
363 |
< |
Result := IBLibrary <> NilHandle; |
363 |
> |
Result := FFBLibrary.IBLibrary <> NilHandle; |
364 |
|
end; |
365 |
|
|
366 |
< |
function TFBClientAPI.GetProcAddr(ProcName: PAnsiChar): Pointer; |
366 |
> |
function TFBClientAPI.GetFBLibrary: IFirebirdLibrary; |
367 |
|
begin |
368 |
< |
Result := GetProcAddress(IBLibrary, ProcName); |
386 |
< |
if not Assigned(Result) then |
387 |
< |
raise Exception.CreateFmt(SFirebirdAPIFuncNotFound,[ProcName]); |
368 |
> |
Result := FFBLibrary; |
369 |
|
end; |
370 |
|
|
371 |
< |
function TFBClientAPI.GetOverrideLibName: string; |
371 |
> |
function TFBClientAPI.GetImplementationVersion: AnsiString; |
372 |
|
begin |
373 |
< |
Result := ''; |
393 |
< |
if AllowUseOfFBLIB then |
394 |
< |
Result := GetEnvironmentVariable('FBLIB'); |
395 |
< |
if Result = '' then |
396 |
< |
begin |
397 |
< |
if assigned(OnGetLibraryName) then |
398 |
< |
OnGetLibraryName(Result) |
399 |
< |
end; |
373 |
> |
Result := Format('%d.%d',[GetClientMajor,GetClientMinor]); |
374 |
|
end; |
375 |
|
|
376 |
< |
procedure TFBClientAPI.LoadInterface; |
376 |
> |
function TFBClientAPI.GetProcAddr(ProcName: PAnsiChar): Pointer; |
377 |
> |
begin |
378 |
> |
Result := GetProcAddress(FFBLibrary.IBLibrary, ProcName); |
379 |
> |
if not Assigned(Result) then |
380 |
> |
raise Exception.CreateFmt(SFirebirdAPIFuncNotFound,[ProcName]); |
381 |
> |
end; |
382 |
> |
|
383 |
> |
function TFBClientAPI.LoadInterface: boolean; |
384 |
|
begin |
385 |
|
isc_sqlcode := GetProcAddr('isc_sqlcode'); {do not localize} |
386 |
|
isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize} |
406 |
– |
isc_interprete := GetProcAddr('isc_interprete'); {do not localize} |
387 |
|
isc_event_counts := GetProcAddr('isc_event_counts'); {do not localize} |
388 |
|
isc_event_block := GetProcAddr('isc_event_block'); {do not localize} |
389 |
|
isc_free := GetProcAddr('isc_free'); {do not localize} |
390 |
+ |
Result := assigned(isc_free); |
391 |
|
end; |
392 |
|
|
412 |
– |
function TFBClientAPI.GetLibraryName: string; |
413 |
– |
begin |
414 |
– |
Result := FFBLibraryName; |
415 |
– |
end; |
416 |
– |
|
417 |
– |
function TFBClientAPI.GetCharsetName(CharSetID: integer): AnsiString; |
418 |
– |
begin |
419 |
– |
Result := ''; |
420 |
– |
if (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) and |
421 |
– |
(CharSetMap[CharSetID].CharSetID = CharSetID) then |
422 |
– |
begin |
423 |
– |
Result := CharSetMap[CharSetID].CharSetName; |
424 |
– |
Exit; |
425 |
– |
end; |
426 |
– |
end; |
427 |
– |
|
428 |
– |
function TFBClientAPI.CharSetID2CodePage(CharSetID: integer; |
429 |
– |
var CodePage: TSystemCodePage): boolean; |
430 |
– |
begin |
431 |
– |
Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) |
432 |
– |
and (CharSetMap[CharSetID].CharSetID = CharSetID); |
433 |
– |
if Result then |
434 |
– |
begin |
435 |
– |
CodePage := CharSetMap[CharSetID].CodePage; |
436 |
– |
Result := true; |
437 |
– |
Exit; |
438 |
– |
end; |
439 |
– |
end; |
440 |
– |
|
441 |
– |
function TFBClientAPI.CodePage2CharSetID(CodePage: TSystemCodePage; |
442 |
– |
var CharSetID: integer): boolean; |
443 |
– |
var i: integer; |
444 |
– |
begin |
445 |
– |
Result := false; |
446 |
– |
for i := Low(CharSetMap) to High(CharSetMap) do |
447 |
– |
if CharSetMap[i].CodePage = CodePage then |
448 |
– |
begin |
449 |
– |
CharSetID := CharSetMap[i].CharSetID; |
450 |
– |
Result := true; |
451 |
– |
Exit; |
452 |
– |
end; |
453 |
– |
end; |
454 |
– |
|
455 |
– |
function TFBClientAPI.CharSetName2CharSetID(CharSetName: AnsiString; |
456 |
– |
var CharSetID: integer): boolean; |
457 |
– |
var i: integer; |
458 |
– |
begin |
459 |
– |
Result := false; |
460 |
– |
for i := Low(CharSetMap) to High(CharSetMap) do |
461 |
– |
if AnsiCompareStr(CharSetMap[i].CharSetName, CharSetName) = 0 then |
462 |
– |
begin |
463 |
– |
CharSetID := CharSetMap[i].CharSetID; |
464 |
– |
Result := true; |
465 |
– |
Exit; |
466 |
– |
end; |
467 |
– |
end; |
468 |
– |
|
469 |
– |
function TFBClientAPI.CharSetWidth(CharSetID: integer; var Width: integer |
470 |
– |
): boolean; |
471 |
– |
begin |
472 |
– |
Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) |
473 |
– |
and (CharSetMap[CharSetID].CharSetID = CharSetID); |
474 |
– |
if Result then |
475 |
– |
begin |
476 |
– |
Width := CharSetMap[CharSetID].CharSetWidth; |
477 |
– |
Result := true; |
478 |
– |
Exit; |
479 |
– |
end; |
480 |
– |
end; |
481 |
– |
|
482 |
– |
const |
483 |
– |
IBLocalBufferLength = 512; |
484 |
– |
IBBigLocalBufferLength = IBLocalBufferLength * 2; |
485 |
– |
IBHugeLocalBufferLength = IBBigLocalBufferLength * 20; |
486 |
– |
|
393 |
|
{ TFBStatus } |
394 |
|
|
395 |
|
constructor TFBStatus.Create(aOwner: TFBClientAPI); |
414 |
|
var local_buffer: array[0..IBHugeLocalBufferLength - 1] of AnsiChar; |
415 |
|
IBDataBaseErrorMessages: TIBDataBaseErrorMessages; |
416 |
|
sqlcode: Long; |
511 |
– |
psb: PStatusVector; |
417 |
|
begin |
418 |
|
Result := ''; |
419 |
|
IBDataBaseErrorMessages := FIBDataBaseErrorMessages; |
425 |
|
if (ShowSQLMessage in IBDataBaseErrorMessages) then |
426 |
|
begin |
427 |
|
with FOwner do |
428 |
< |
isc_sql_interprete(sqlcode, local_buffer, IBLocalBufferLength); |
428 |
> |
isc_sql_interprete(sqlcode, local_buffer, sizeof(local_buffer)); |
429 |
|
if (ShowSQLCode in FIBDataBaseErrorMessages) then |
430 |
|
Result := Result + CRLF; |
431 |
|
Result := Result + strpas(local_buffer); |
435 |
|
begin |
436 |
|
if (ShowSQLCode in IBDataBaseErrorMessages) or |
437 |
|
(ShowSQLMessage in IBDataBaseErrorMessages) then |
438 |
< |
Result := Result + CRLF; |
439 |
< |
psb := StatusVector; |
535 |
< |
with FOwner do |
536 |
< |
while (isc_interprete(@local_buffer, @psb) > 0) do |
537 |
< |
begin |
538 |
< |
if (Result <> '') and (Result[Length(Result)] <> LF) then |
539 |
< |
Result := Result + CRLF; |
540 |
< |
Result := Result + strpas(local_buffer); |
541 |
< |
end; |
438 |
> |
Result := Result + LineEnding; |
439 |
> |
Result := Result + LineEnding + FOwner.FormatStatus(self); |
440 |
|
end; |
441 |
|
if (Result <> '') and (Result[Length(Result)] = '.') then |
442 |
|
Delete(Result, Length(Result), 1); |
492 |
|
LeaveCriticalSection(TFBClientAPI.FIBCS); |
493 |
|
end; |
494 |
|
end; |
495 |
+ |
|
496 |
|
initialization |
497 |
< |
TFBClientAPI.IBLibrary := NilHandle; |
497 |
> |
TFBLibrary.FEnvSetupDone := false; |
498 |
|
{$IFNDEF FPC} |
499 |
|
InitializeCriticalSection(TFBClientAPI.FIBCS); |
500 |
|
{$ELSE} |
502 |
|
{$ENDIF} |
503 |
|
|
504 |
|
finalization |
505 |
+ |
TFBLibrary.FreeLibraries; |
506 |
|
{$IFNDEF FPC} |
507 |
|
DeleteCriticalSection(TFBClientAPI.FIBCS); |
508 |
|
{$ELSE} |
509 |
|
DoneCriticalSection(TFBClientAPI.FIBCS); |
510 |
|
{$ENDIF} |
611 |
– |
if TFBClientAPI.IBLibrary <> NilHandle then |
612 |
– |
begin |
613 |
– |
FreeLibrary(TFBClientAPI.IBLibrary); |
614 |
– |
TFBClientAPI.IBLibrary := NilHandle; |
615 |
– |
TFBClientAPI.FFBLibraryName := ''; |
616 |
– |
end; |
617 |
– |
|
511 |
|
end. |
512 |
|
|