ibconnection.pp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. unit IBConnection;
  2. {$mode objfpc}{$H+}
  3. {$Define LinkDynamically}
  4. interface
  5. uses
  6. Classes, SysUtils, sqldb, db, math, dbconst, bufdataset,
  7. {$IfDef LinkDynamically}
  8. ibase60dyn;
  9. {$Else}
  10. ibase60;
  11. {$EndIf}
  12. type
  13. EIBDatabaseError = class(EDatabaseError)
  14. public
  15. GDSErrorCode : Longint;
  16. end;
  17. { TIBCursor }
  18. TIBCursor = Class(TSQLCursor)
  19. protected
  20. Status : array [0..19] of ISC_STATUS;
  21. Statement : pointer;
  22. SQLDA : PXSQLDA;
  23. in_SQLDA : PXSQLDA;
  24. ParamBinding : array of integer;
  25. FieldBinding : array of integer;
  26. end;
  27. TIBTrans = Class(TSQLHandle)
  28. protected
  29. TransactionHandle : pointer;
  30. TPB : string; // Transaction parameter buffer
  31. Status : array [0..19] of ISC_STATUS;
  32. end;
  33. { TIBConnection }
  34. TIBConnection = class (TSQLConnection)
  35. private
  36. FSQLDatabaseHandle : pointer;
  37. FStatus : array [0..19] of ISC_STATUS;
  38. FDialect : integer;
  39. FBLobSegmentSize : word;
  40. procedure ConnectFB;
  41. function GetDialect: integer;
  42. procedure SetDBDialect;
  43. procedure AllocSQLDA(var aSQLDA : PXSQLDA;Count : integer);
  44. procedure TranslateFldType(SQLType, SQLLen, SQLScale : integer;
  45. var TrType : TFieldType; var TrLen : word);
  46. // conversion methods
  47. procedure GetDateTime(CurrBuff, Buffer : pointer; AType : integer);
  48. procedure SetDateTime(CurrBuff: pointer; PTime : TDateTime; AType : integer);
  49. procedure GetFloat(CurrBuff, Buffer : pointer; Size : Byte);
  50. procedure SetFloat(CurrBuff: pointer; Dbl: Double; Size: integer);
  51. procedure CheckError(ProcName : string; Status : PISC_STATUS);
  52. function getMaxBlobSize(blobHandle : TIsc_Blob_Handle) : longInt;
  53. procedure SetParameters(cursor : TSQLCursor;AParams : TParams);
  54. procedure FreeSQLDABuffer(var aSQLDA : PXSQLDA);
  55. protected
  56. procedure DoInternalConnect; override;
  57. procedure DoInternalDisconnect; override;
  58. function GetHandle : pointer; override;
  59. Function AllocateCursorHandle : TSQLCursor; override;
  60. Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); override;
  61. Function AllocateTransactionHandle : TSQLHandle; override;
  62. procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); override;
  63. procedure UnPrepareStatement(cursor : TSQLCursor); override;
  64. procedure FreeFldBuffers(cursor : TSQLCursor); override;
  65. procedure Execute(cursor: TSQLCursor;atransaction:tSQLtransaction; AParams : TParams); override;
  66. procedure AddFieldDefs(cursor: TSQLCursor;FieldDefs : TfieldDefs); override;
  67. function Fetch(cursor : TSQLCursor) : boolean; override;
  68. function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; override;
  69. function GetTransactionHandle(trans : TSQLHandle): pointer; override;
  70. function Commit(trans : TSQLHandle) : boolean; override;
  71. function RollBack(trans : TSQLHandle) : boolean; override;
  72. function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; override;
  73. procedure CommitRetaining(trans : TSQLHandle); override;
  74. procedure RollBackRetaining(trans : TSQLHandle); override;
  75. procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
  76. function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; override;
  77. procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField; cursor: TSQLCursor; ATransaction : TSQLTransaction); override;
  78. public
  79. constructor Create(AOwner : TComponent); override;
  80. procedure CreateDB; override;
  81. procedure DropDB; override;
  82. property BlobSegmentSize : word read FBlobSegmentSize write FBlobSegmentSize;
  83. published
  84. property Dialect : integer read GetDialect write FDialect;
  85. property DatabaseName;
  86. property KeepConnection;
  87. property LoginPrompt;
  88. property Params;
  89. property OnLogin;
  90. end;
  91. { TIBConnectionDef }
  92. TIBConnectionDef = Class(TConnectionDef)
  93. Class Function TypeName : String; override;
  94. Class Function ConnectionClass : TSQLConnectionClass; override;
  95. Class Function Description : String; override;
  96. end;
  97. implementation
  98. uses strutils;
  99. type
  100. TTm = packed record
  101. tm_sec : longint;
  102. tm_min : longint;
  103. tm_hour : longint;
  104. tm_mday : longint;
  105. tm_mon : longint;
  106. tm_year : longint;
  107. tm_wday : longint;
  108. tm_yday : longint;
  109. tm_isdst : longint;
  110. __tm_gmtoff : longint;
  111. __tm_zone : Pchar;
  112. end;
  113. procedure TIBConnection.CheckError(ProcName : string; Status : PISC_STATUS);
  114. var
  115. buf : array [0..1024] of char;
  116. Msg : string;
  117. E : EIBDatabaseError;
  118. begin
  119. if ((Status[0] = 1) and (Status[1] <> 0)) then
  120. begin
  121. msg := '';
  122. while isc_interprete(Buf, @Status) > 0 do
  123. Msg := Msg + LineEnding +' -' + StrPas(Buf);
  124. E := EIBDatabaseError.CreateFmt('%s : %s : %s',[self.Name,ProcName,Msg]);
  125. E.GDSErrorCode := Status[1];
  126. Raise E;
  127. end;
  128. end;
  129. constructor TIBConnection.Create(AOwner : TComponent);
  130. begin
  131. inherited;
  132. FConnOptions := FConnOptions + [sqSupportParams] + [sqEscapeRepeat];
  133. FBLobSegmentSize := 80;
  134. FDialect := -1;
  135. end;
  136. function TIBConnection.GetTransactionHandle(trans : TSQLHandle): pointer;
  137. begin
  138. Result := (trans as TIBtrans).TransactionHandle;
  139. end;
  140. function TIBConnection.Commit(trans : TSQLHandle) : boolean;
  141. begin
  142. result := false;
  143. with (trans as TIBTrans) do
  144. if isc_commit_transaction(@Status[0], @TransactionHandle) <> 0 then
  145. CheckError('Commit', Status)
  146. else result := true;
  147. end;
  148. function TIBConnection.RollBack(trans : TSQLHandle) : boolean;
  149. begin
  150. result := false;
  151. if isc_rollback_transaction(@TIBTrans(trans).Status[0], @TIBTrans(trans).TransactionHandle) <> 0 then
  152. CheckError('Rollback', TIBTrans(trans).Status)
  153. else result := true;
  154. end;
  155. function TIBConnection.StartDBTransaction(trans : TSQLHandle;AParams : String) : boolean;
  156. var
  157. DBHandle : pointer;
  158. tr : TIBTrans;
  159. i : integer;
  160. s : string;
  161. begin
  162. result := false;
  163. DBHandle := GetHandle;
  164. tr := trans as TIBtrans;
  165. with tr do
  166. begin
  167. TPB := chr(isc_tpb_version3);
  168. i := 1;
  169. s := ExtractSubStr(AParams,i,stdWordDelims);
  170. while s <> '' do
  171. begin
  172. if s='isc_tpb_write' then TPB := TPB + chr(isc_tpb_write)
  173. else if s='isc_tpb_read' then TPB := TPB + chr(isc_tpb_read)
  174. else if s='isc_tpb_consistency' then TPB := TPB + chr(isc_tpb_consistency)
  175. else if s='isc_tpb_concurrency' then TPB := TPB + chr(isc_tpb_concurrency)
  176. else if s='isc_tpb_read_committed' then TPB := TPB + chr(isc_tpb_read_committed)
  177. else if s='isc_tpb_rec_version' then TPB := TPB + chr(isc_tpb_rec_version)
  178. else if s='isc_tpb_no_rec_version' then TPB := TPB + chr(isc_tpb_no_rec_version)
  179. else if s='isc_tpb_wait' then TPB := TPB + chr(isc_tpb_wait)
  180. else if s='isc_tpb_nowait' then TPB := TPB + chr(isc_tpb_nowait)
  181. else if s='isc_tpb_shared' then TPB := TPB + chr(isc_tpb_shared)
  182. else if s='isc_tpb_protected' then TPB := TPB + chr(isc_tpb_protected)
  183. else if s='isc_tpb_exclusive' then TPB := TPB + chr(isc_tpb_exclusive)
  184. else if s='isc_tpb_lock_read' then TPB := TPB + chr(isc_tpb_lock_read)
  185. else if s='isc_tpb_lock_write' then TPB := TPB + chr(isc_tpb_lock_write)
  186. else if s='isc_tpb_verb_time' then TPB := TPB + chr(isc_tpb_verb_time)
  187. else if s='isc_tpb_commit_time' then TPB := TPB + chr(isc_tpb_commit_time)
  188. else if s='isc_tpb_ignore_limbo' then TPB := TPB + chr(isc_tpb_ignore_limbo)
  189. else if s='isc_tpb_autocommit' then TPB := TPB + chr(isc_tpb_autocommit)
  190. else if s='isc_tpb_restart_requests' then TPB := TPB + chr(isc_tpb_restart_requests)
  191. else if s='isc_tpb_no_auto_undo' then TPB := TPB + chr(isc_tpb_no_auto_undo);
  192. s := ExtractSubStr(AParams,i,stdWordDelims);
  193. end;
  194. TransactionHandle := nil;
  195. if isc_start_transaction(@Status[0], @TransactionHandle, 1,
  196. [@DBHandle, Length(TPB), @TPB[1]]) <> 0 then
  197. CheckError('StartTransaction',Status)
  198. else Result := True;
  199. end;
  200. end;
  201. procedure TIBConnection.CommitRetaining(trans : TSQLHandle);
  202. begin
  203. with trans as TIBtrans do
  204. if isc_commit_retaining(@Status[0], @TransactionHandle) <> 0 then
  205. CheckError('CommitRetaining', Status);
  206. end;
  207. procedure TIBConnection.RollBackRetaining(trans : TSQLHandle);
  208. begin
  209. with trans as TIBtrans do
  210. if isc_rollback_retaining(@Status[0], @TransactionHandle) <> 0 then
  211. CheckError('RollBackRetaining', Status);
  212. end;
  213. procedure TIBConnection.DropDB;
  214. begin
  215. CheckDisConnected;
  216. {$IfDef LinkDynamically}
  217. InitialiseIBase60;
  218. {$EndIf}
  219. ConnectFB;
  220. if isc_drop_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
  221. CheckError('DropDB', FStatus);
  222. {$IfDef LinkDynamically}
  223. ReleaseIBase60;
  224. {$EndIf}
  225. end;
  226. procedure TIBConnection.CreateDB;
  227. var ASQLDatabaseHandle,
  228. ASQLTransactionHandle : pointer;
  229. CreateSQL : String;
  230. begin
  231. CheckDisConnected;
  232. {$IfDef LinkDynamically}
  233. InitialiseIBase60;
  234. {$EndIf}
  235. ASQLDatabaseHandle := nil;
  236. ASQLTransactionHandle := nil;
  237. CreateSQL := 'CREATE DATABASE ';
  238. if HostName <> '' then CreateSQL := CreateSQL + ''''+ HostName+':'+DatabaseName + ''''
  239. else CreateSQL := CreateSQL + '''' + DatabaseName + '''';
  240. if isc_dsql_execute_immediate(@FStatus[0],@ASQLDatabaseHandle,@ASQLTransactionHandle,length(CreateSQL),@CreateSQL[1],Dialect,nil) <> 0 then
  241. CheckError('CreateDB', FStatus);
  242. if isc_detach_database(@FStatus[0], @ASQLDatabaseHandle) <> 0 then
  243. CheckError('CreateDB', FStatus);
  244. {$IfDef LinkDynamically}
  245. ReleaseIBase60;
  246. {$EndIf}
  247. end;
  248. procedure TIBConnection.DoInternalConnect;
  249. begin
  250. {$IfDef LinkDynamically}
  251. InitialiseIBase60;
  252. {$EndIf}
  253. inherited dointernalconnect;
  254. ConnectFB;
  255. end;
  256. procedure TIBConnection.DoInternalDisconnect;
  257. begin
  258. FDialect := -1;
  259. if not Connected then
  260. begin
  261. FSQLDatabaseHandle := nil;
  262. Exit;
  263. end;
  264. if isc_detach_database(@FStatus[0], @FSQLDatabaseHandle) <> 0 then
  265. CheckError('Close', FStatus);
  266. {$IfDef LinkDynamically}
  267. ReleaseIBase60;
  268. {$EndIf}
  269. end;
  270. procedure TIBConnection.SetDBDialect;
  271. var
  272. x : integer;
  273. Len : integer;
  274. Buffer : array [0..1] of byte;
  275. ResBuf : array [0..39] of byte;
  276. begin
  277. Buffer[0] := isc_info_db_sql_dialect;
  278. Buffer[1] := isc_info_end;
  279. if isc_database_info(@FStatus[0], @FSQLDatabaseHandle, Length(Buffer),
  280. pchar(@Buffer[0]), SizeOf(ResBuf), pchar(@ResBuf[0])) <> 0 then
  281. CheckError('SetDBDialect', FStatus);
  282. x := 0;
  283. while x < 40 do
  284. case ResBuf[x] of
  285. isc_info_db_sql_dialect :
  286. begin
  287. Inc(x);
  288. Len := isc_vax_integer(pchar(@ResBuf[x]), 2);
  289. Inc(x, 2);
  290. FDialect := isc_vax_integer(pchar(@ResBuf[x]), Len);
  291. Inc(x, Len);
  292. end;
  293. isc_info_end : Break;
  294. else
  295. inc(x);
  296. end;
  297. end;
  298. procedure TIBConnection.ConnectFB;
  299. var
  300. ADatabaseName: String;
  301. DPB: string;
  302. begin
  303. DPB := chr(isc_dpb_version1);
  304. if (UserName <> '') then
  305. begin
  306. DPB := DPB + chr(isc_dpb_user_name) + chr(Length(UserName)) + UserName;
  307. if (Password <> '') then
  308. DPB := DPB + chr(isc_dpb_password) + chr(Length(Password)) + Password;
  309. end;
  310. if (Role <> '') then
  311. DPB := DPB + chr(isc_dpb_sql_role_name) + chr(Length(Role)) + Role;
  312. if Length(CharSet) > 0 then
  313. DPB := DPB + Chr(isc_dpb_lc_ctype) + Chr(Length(CharSet)) + CharSet;
  314. FSQLDatabaseHandle := nil;
  315. if HostName <> '' then ADatabaseName := HostName+':'+DatabaseName
  316. else ADatabaseName := DatabaseName;
  317. if isc_attach_database(@FStatus[0], Length(ADatabaseName), @ADatabaseName[1],
  318. @FSQLDatabaseHandle,
  319. Length(DPB), @DPB[1]) <> 0 then
  320. CheckError('DoInternalConnect', FStatus);
  321. end;
  322. function TIBConnection.GetDialect: integer;
  323. begin
  324. if FDialect = -1 then
  325. SetDBDialect;
  326. Result := FDialect;
  327. end;
  328. procedure TIBConnection.AllocSQLDA(var aSQLDA : PXSQLDA;Count : integer);
  329. begin
  330. FreeSQLDABuffer(aSQLDA);
  331. if count > -1 then
  332. begin
  333. reAllocMem(aSQLDA, XSQLDA_Length(Count));
  334. { Zero out the memory block to avoid problems with exceptions within the
  335. constructor of this class. }
  336. FillChar(aSQLDA^, XSQLDA_Length(Count), 0);
  337. aSQLDA^.Version := sqlda_version1;
  338. aSQLDA^.SQLN := Count;
  339. end
  340. else
  341. reAllocMem(aSQLDA,0);
  342. end;
  343. procedure TIBConnection.TranslateFldType(SQLType, SQLLen, SQLScale : integer;
  344. var TrType : TFieldType; var TrLen : word);
  345. begin
  346. trlen := 0;
  347. if SQLScale < 0 then
  348. begin
  349. if (SQLScale >= -4) and (SQLScale <= -1) then //in [-4..-1] then
  350. begin
  351. TrLen := abs(SQLScale);
  352. TrType := ftBCD
  353. end
  354. else
  355. TrType := ftFMTBcd;
  356. end
  357. else case (SQLType and not 1) of
  358. SQL_VARYING,SQL_TEXT :
  359. begin
  360. TrType := ftString;
  361. if SQLLen > dsMaxStringSize then
  362. TrLen := dsMaxStringSize
  363. else
  364. TrLen := SQLLen;
  365. end;
  366. SQL_TYPE_DATE :
  367. TrType := ftDate{Time};
  368. SQL_TYPE_TIME :
  369. TrType := ftDateTime;
  370. SQL_TIMESTAMP :
  371. TrType := ftDateTime;
  372. SQL_ARRAY :
  373. begin
  374. TrType := ftArray;
  375. TrLen := SQLLen;
  376. end;
  377. SQL_BLOB :
  378. begin
  379. TrType := ftBlob;
  380. TrLen := SQLLen;
  381. end;
  382. SQL_SHORT :
  383. TrType := ftSmallint;
  384. SQL_LONG :
  385. TrType := ftInteger;
  386. SQL_INT64 :
  387. TrType := ftLargeInt;
  388. SQL_DOUBLE :
  389. TrType := ftFloat;
  390. SQL_FLOAT :
  391. TrType := ftFloat;
  392. else
  393. TrType := ftUnknown;
  394. end;
  395. end;
  396. Function TIBConnection.AllocateCursorHandle : TSQLCursor;
  397. var curs : TIBCursor;
  398. begin
  399. curs := TIBCursor.create;
  400. curs.sqlda := nil;
  401. curs.statement := nil;
  402. curs.FPrepared := False;
  403. AllocSQLDA(curs.SQLDA,0);
  404. result := curs;
  405. end;
  406. procedure TIBConnection.DeAllocateCursorHandle(var cursor : TSQLCursor);
  407. begin
  408. if assigned(cursor) then with cursor as TIBCursor do
  409. begin
  410. AllocSQLDA(SQLDA,-1);
  411. AllocSQLDA(in_SQLDA,-1);
  412. end;
  413. FreeAndNil(cursor);
  414. end;
  415. Function TIBConnection.AllocateTransactionHandle : TSQLHandle;
  416. begin
  417. result := TIBTrans.create;
  418. end;
  419. procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
  420. var dh : pointer;
  421. tr : pointer;
  422. x : shortint;
  423. begin
  424. with cursor as TIBcursor do
  425. begin
  426. dh := GetHandle;
  427. if isc_dsql_allocate_statement(@Status[0], @dh, @Statement) <> 0 then
  428. CheckError('PrepareStatement', Status);
  429. tr := aTransaction.Handle;
  430. if assigned(AParams) and (AParams.count > 0) then
  431. buf := AParams.ParseSQL(buf,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psInterbase,paramBinding);
  432. if isc_dsql_prepare(@Status[0], @tr, @Statement, 0, @Buf[1], Dialect, nil) <> 0 then
  433. CheckError('PrepareStatement', Status);
  434. FPrepared := True;
  435. if assigned(AParams) and (AParams.count > 0) then
  436. begin
  437. AllocSQLDA(in_SQLDA,Length(ParamBinding));
  438. if isc_dsql_describe_bind(@Status[0], @Statement, 1, in_SQLDA) <> 0 then
  439. CheckError('PrepareStatement', Status);
  440. if in_SQLDA^.SQLD > in_SQLDA^.SQLN then
  441. DatabaseError(SParameterCountIncorrect,self);
  442. {$R-}
  443. for x := 0 to in_SQLDA^.SQLD - 1 do with in_SQLDA^.SQLVar[x] do
  444. begin
  445. if ((SQLType and not 1) = SQL_VARYING) then
  446. SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen+2)
  447. else
  448. SQLData := AllocMem(in_SQLDA^.SQLVar[x].SQLLen);
  449. if (sqltype and 1) = 1 then New(SQLInd);
  450. end;
  451. {$R+}
  452. end
  453. else
  454. AllocSQLDA(in_SQLDA,0);
  455. if FStatementType = stselect then
  456. begin
  457. FPrepared := False;
  458. if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
  459. CheckError('PrepareSelect', Status);
  460. if SQLDA^.SQLD > SQLDA^.SQLN then
  461. begin
  462. AllocSQLDA(SQLDA,SQLDA^.SQLD);
  463. if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
  464. CheckError('PrepareSelect', Status);
  465. end;
  466. {$R-}
  467. for x := 0 to SQLDA^.SQLD - 1 do with SQLDA^.SQLVar[x] do
  468. begin
  469. if ((SQLType and not 1) = SQL_VARYING) then
  470. SQLData := AllocMem(SQLDA^.SQLVar[x].SQLLen+2)
  471. else
  472. SQLData := AllocMem(SQLDA^.SQLVar[x].SQLLen);
  473. if (SQLType and 1) = 1 then New(SQLInd);
  474. end;
  475. {$R+}
  476. end;
  477. end;
  478. end;
  479. procedure TIBConnection.UnPrepareStatement(cursor : TSQLCursor);
  480. begin
  481. with cursor as TIBcursor do
  482. begin
  483. if isc_dsql_free_statement(@Status[0], @Statement, DSQL_Drop) <> 0 then
  484. CheckError('FreeStatement', Status);
  485. Statement := nil;
  486. FPrepared := False;
  487. end;
  488. end;
  489. procedure TIBConnection.FreeSQLDABuffer(var aSQLDA : PXSQLDA);
  490. var x : shortint;
  491. begin
  492. {$R-}
  493. if assigned(aSQLDA) then
  494. for x := 0 to aSQLDA^.SQLN - 1 do
  495. begin
  496. reAllocMem(aSQLDA^.SQLVar[x].SQLData,0);
  497. if assigned(aSQLDA^.SQLVar[x].sqlind) then
  498. begin
  499. Dispose(aSQLDA^.SQLVar[x].sqlind);
  500. aSQLDA^.SQLVar[x].sqlind := nil;
  501. end
  502. end;
  503. {$R+}
  504. end;
  505. procedure TIBConnection.FreeFldBuffers(cursor : TSQLCursor);
  506. begin
  507. with cursor as TIBCursor do
  508. begin
  509. FreeSQLDABuffer(SQLDA);
  510. FreeSQLDABuffer(in_SQLDA);
  511. SetLength(FieldBinding,0);
  512. end;
  513. end;
  514. procedure TIBConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction; AParams : TParams);
  515. var tr : pointer;
  516. begin
  517. tr := aTransaction.Handle;
  518. if Assigned(APArams) and (AParams.count > 0) then SetParameters(cursor, AParams);
  519. with cursor as TIBCursor do
  520. if isc_dsql_execute2(@Status[0], @tr, @Statement, 1, in_SQLDA, nil) <> 0 then
  521. CheckError('Execute', Status);
  522. end;
  523. procedure TIBConnection.AddFieldDefs(cursor: TSQLCursor;FieldDefs : TfieldDefs);
  524. var
  525. x : integer;
  526. TransLen : word;
  527. TransType : TFieldType;
  528. FD : TFieldDef;
  529. begin
  530. {$R-}
  531. with cursor as TIBCursor do
  532. begin
  533. setlength(FieldBinding,SQLDA^.SQLD);
  534. for x := 0 to SQLDA^.SQLD - 1 do
  535. begin
  536. TranslateFldType(SQLDA^.SQLVar[x].SQLType, SQLDA^.SQLVar[x].SQLLen, SQLDA^.SQLVar[x].SQLScale,
  537. TransType, TransLen);
  538. FD := TFieldDef.Create(FieldDefs, SQLDA^.SQLVar[x].AliasName, TransType,
  539. TransLen, False, (x + 1));
  540. if TransType = ftBCD then FD.precision := SQLDA^.SQLVar[x].SQLLen;
  541. // FD.DisplayName := SQLDA^.SQLVar[x].AliasName;
  542. FieldBinding[FD.FieldNo-1] := x;
  543. end;
  544. end;
  545. {$R+}
  546. end;
  547. function TIBConnection.GetHandle: pointer;
  548. begin
  549. Result := FSQLDatabaseHandle;
  550. end;
  551. function TIBConnection.Fetch(cursor : TSQLCursor) : boolean;
  552. var
  553. retcode : integer;
  554. begin
  555. with cursor as TIBCursor do
  556. begin
  557. retcode := isc_dsql_fetch(@Status[0], @Statement, 1, SQLDA);
  558. if (retcode <> 0) and (retcode <> 100) then
  559. CheckError('Fetch', Status);
  560. end;
  561. Result := (retcode <> 100);
  562. end;
  563. procedure TIBConnection.SetParameters(cursor : TSQLCursor;AParams : TParams);
  564. var ParNr,SQLVarNr : integer;
  565. s : string;
  566. i : integer;
  567. li : LargeInt;
  568. currbuff : pchar;
  569. w : word;
  570. TransactionHandle : pointer;
  571. blobId : ISC_QUAD;
  572. blobHandle : Isc_blob_Handle;
  573. BlobSize,
  574. BlobBytesWritten : longint;
  575. procedure SetBlobParam;
  576. begin
  577. {$R-}
  578. with cursor as TIBCursor do
  579. begin
  580. TransactionHandle := transaction.Handle;
  581. blobhandle := nil;
  582. if isc_create_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @blobHandle, @blobId) <> 0 then
  583. CheckError('TIBConnection.CreateBlobStream', FStatus);
  584. s := AParams[ParNr].AsString;
  585. BlobSize := length(s);
  586. BlobBytesWritten := 0;
  587. i := 0;
  588. while BlobBytesWritten < (BlobSize-BlobSegmentSize) do
  589. begin
  590. isc_put_segment(@FStatus[0], @blobHandle, BlobSegmentSize, @s[(i*BlobSegmentSize)+1]);
  591. inc(BlobBytesWritten,BlobSegmentSize);
  592. inc(i);
  593. end;
  594. if BlobBytesWritten <> BlobSize then
  595. isc_put_segment(@FStatus[0], @blobHandle, BlobSize-BlobBytesWritten, @s[(i*BlobSegmentSize)+1]);
  596. if isc_close_blob(@FStatus[0], @blobHandle) <> 0 then
  597. CheckError('TIBConnection.CreateBlobStream isc_close_blob', FStatus);
  598. Move(blobId, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
  599. end;
  600. {$R+}
  601. end;
  602. begin
  603. {$R-}
  604. with cursor as TIBCursor do for SQLVarNr := 0 to High(ParamBinding){AParams.count-1} do
  605. begin
  606. ParNr := ParamBinding[SQLVarNr];
  607. if AParams[ParNr].IsNull then
  608. begin
  609. If Assigned(in_sqlda^.SQLvar[SQLVarNr].SQLInd) then
  610. in_sqlda^.SQLvar[SQLVarNr].SQLInd^ := -1;
  611. end
  612. else
  613. begin
  614. if assigned(in_sqlda^.SQLvar[SQLVarNr].SQLInd) then in_sqlda^.SQLvar[SQLVarNr].SQLInd^ := 0;
  615. case (in_sqlda^.SQLvar[SQLVarNr].sqltype and not 1) of
  616. SQL_LONG :
  617. begin
  618. i := AParams[ParNr].AsInteger;
  619. Move(i, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
  620. end;
  621. SQL_SHORT :
  622. begin
  623. i := AParams[ParNr].AsSmallInt;
  624. Move(i, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
  625. end;
  626. SQL_BLOB :
  627. SetBlobParam;
  628. SQL_VARYING, SQL_TEXT :
  629. begin
  630. s := AParams[ParNr].AsString;
  631. w := length(s); // a word is enough, since the max-length of a string in interbase is 32k
  632. if ((in_sqlda^.SQLvar[SQLVarNr].SQLType and not 1) = SQL_VARYING) then
  633. begin
  634. in_sqlda^.SQLvar[SQLVarNr].SQLLen := w;
  635. ReAllocMem(in_sqlda^.SQLvar[SQLVarNr].SQLData,in_SQLDA^.SQLVar[SQLVarNr].SQLLen+2);
  636. CurrBuff := in_sqlda^.SQLvar[SQLVarNr].SQLData;
  637. move(w,CurrBuff^,sizeof(w));
  638. inc(CurrBuff,2);
  639. end
  640. else
  641. CurrBuff := in_sqlda^.SQLvar[SQLVarNr].SQLData;
  642. Move(s[1], CurrBuff^, w);
  643. end;
  644. SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TIMESTAMP :
  645. SetDateTime(in_sqlda^.SQLvar[SQLVarNr].SQLData, AParams[ParNr].AsDateTime, in_SQLDA^.SQLVar[SQLVarNr].SQLType);
  646. SQL_INT64:
  647. begin
  648. li := AParams[ParNr].AsLargeInt;
  649. Move(li, in_sqlda^.SQLvar[SQLVarNr].SQLData^, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
  650. end;
  651. SQL_DOUBLE, SQL_FLOAT:
  652. SetFloat(in_sqlda^.SQLvar[SQLVarNr].SQLData, AParams[ParNr].AsFloat, in_SQLDA^.SQLVar[SQLVarNr].SQLLen);
  653. else
  654. DatabaseErrorFmt(SUnsupportedParameter,[Fieldtypenames[AParams[ParNr].DataType]],self);
  655. end {case}
  656. end;
  657. end;
  658. {$R+}
  659. end;
  660. function TIBConnection.LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer; out CreateBlob : boolean) : boolean;
  661. var
  662. x : integer;
  663. VarcharLen : word;
  664. CurrBuff : pchar;
  665. c : currency;
  666. begin
  667. CreateBlob := False;
  668. with cursor as TIBCursor do
  669. begin
  670. {$R-}
  671. x := FieldBinding[FieldDef.FieldNo-1];
  672. // Joost, 5 jan 2006: I disabled the following, since it's usefull for
  673. // debugging, but it also slows things down. In principle things can only go
  674. // wrong when FieldDefs is changed while the dataset is opened. A user just
  675. // shoudn't do that. ;) (The same is done in PQConnection)
  676. // if SQLDA^.SQLVar[x].AliasName <> FieldDef.Name then
  677. // DatabaseErrorFmt(SFieldNotFound,[FieldDef.Name],self);
  678. if assigned(SQLDA^.SQLVar[x].SQLInd) and (SQLDA^.SQLVar[x].SQLInd^ = -1) then
  679. result := false
  680. else
  681. begin
  682. with SQLDA^.SQLVar[x] do
  683. if ((SQLType and not 1) = SQL_VARYING) then
  684. begin
  685. Move(SQLData^, VarcharLen, 2);
  686. if VarcharLen > dsMaxStringSize then
  687. VarcharLen:=dsMaxStringSize;
  688. CurrBuff := SQLData + 2;
  689. end
  690. else
  691. begin
  692. CurrBuff := SQLData;
  693. VarCharLen := FieldDef.Size;
  694. end;
  695. Result := true;
  696. case FieldDef.DataType of
  697. ftBCD :
  698. begin
  699. c := 0;
  700. Move(CurrBuff^, c, SQLDA^.SQLVar[x].SQLLen);
  701. c := c*intpower(10,4+SQLDA^.SQLVar[x].SQLScale);
  702. Move(c, buffer^ , sizeof(c));
  703. end;
  704. ftInteger :
  705. begin
  706. FillByte(buffer^,sizeof(Longint),0);
  707. Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
  708. end;
  709. ftLargeint :
  710. begin
  711. FillByte(buffer^,sizeof(LargeInt),0);
  712. Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
  713. end;
  714. ftSmallint :
  715. begin
  716. FillByte(buffer^,sizeof(Smallint),0);
  717. Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
  718. end;
  719. ftDate, ftTime, ftDateTime:
  720. GetDateTime(CurrBuff, Buffer, SQLDA^.SQLVar[x].SQLType);
  721. ftString :
  722. begin
  723. Move(CurrBuff^, Buffer^, VarCharLen);
  724. PChar(Buffer + VarCharLen)^ := #0;
  725. end;
  726. ftFloat :
  727. GetFloat(CurrBuff, Buffer, SQLDA^.SQLVar[x].SQLLen);
  728. ftBlob : begin // load the BlobIb in field's buffer
  729. FillByte(buffer^,sizeof(TBufBlobField),0);
  730. Move(CurrBuff^, Buffer^, SQLDA^.SQLVar[x].SQLLen);
  731. end
  732. else result := false;
  733. end;
  734. end;
  735. {$R+}
  736. end;
  737. end;
  738. procedure TIBConnection.GetDateTime(CurrBuff, Buffer : pointer; AType : integer);
  739. var
  740. CTime : TTm; // C struct time
  741. STime : TSystemTime; // System time
  742. PTime : TDateTime; // Pascal time
  743. begin
  744. case (AType and not 1) of
  745. SQL_TYPE_DATE :
  746. isc_decode_sql_date(PISC_DATE(CurrBuff), @CTime);
  747. SQL_TYPE_TIME :
  748. isc_decode_sql_time(PISC_TIME(CurrBuff), @CTime);
  749. SQL_TIMESTAMP :
  750. isc_decode_timestamp(PISC_TIMESTAMP(CurrBuff), @CTime);
  751. end;
  752. STime.Year := CTime.tm_year + 1900;
  753. STime.Month := CTime.tm_mon + 1;
  754. STime.Day := CTime.tm_mday;
  755. STime.Hour := CTime.tm_hour;
  756. STime.Minute := CTime.tm_min;
  757. STime.Second := CTime.tm_sec;
  758. STime.Millisecond := 0;
  759. PTime := SystemTimeToDateTime(STime);
  760. Move(PTime, Buffer^, SizeOf(PTime));
  761. end;
  762. procedure TIBConnection.SetDateTime(CurrBuff: pointer; PTime : TDateTime; AType : integer);
  763. var
  764. CTime : TTm; // C struct time
  765. STime : TSystemTime; // System time
  766. begin
  767. DateTimeToSystemTime(PTime,STime);
  768. CTime.tm_year := STime.Year - 1900;
  769. CTime.tm_mon := STime.Month -1;
  770. CTime.tm_mday := STime.Day;
  771. CTime.tm_hour := STime.Hour;
  772. CTime.tm_min := STime.Minute;
  773. CTime.tm_sec := STime.Second;
  774. case (AType and not 1) of
  775. SQL_TYPE_DATE :
  776. isc_encode_sql_date(@CTime, PISC_DATE(CurrBuff));
  777. SQL_TYPE_TIME :
  778. isc_encode_sql_time(@CTime, PISC_TIME(CurrBuff));
  779. SQL_TIMESTAMP :
  780. isc_encode_timestamp(@CTime, PISC_TIMESTAMP(CurrBuff));
  781. end;
  782. end;
  783. function TIBConnection.GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string;
  784. var s : string;
  785. begin
  786. case SchemaType of
  787. stTables : s := 'select '+
  788. 'rdb$relation_id as recno, '+
  789. '''' + DatabaseName + ''' as catalog_name, '+
  790. ''''' as schema_name, '+
  791. 'rdb$relation_name as table_name, '+
  792. '0 as table_type '+
  793. 'from '+
  794. 'rdb$relations '+
  795. 'where '+
  796. '(rdb$system_flag = 0 or rdb$system_flag is null) ' + // and rdb$view_blr is null
  797. 'order by rdb$relation_name';
  798. stSysTables : s := 'select '+
  799. 'rdb$relation_id as recno, '+
  800. '''' + DatabaseName + ''' as catalog_name, '+
  801. ''''' as schema_name, '+
  802. 'rdb$relation_name as table_name, '+
  803. '0 as table_type '+
  804. 'from '+
  805. 'rdb$relations '+
  806. 'where '+
  807. '(rdb$system_flag > 0) ' + // and rdb$view_blr is null
  808. 'order by rdb$relation_name';
  809. stProcedures : s := 'select '+
  810. 'rdb$procedure_id as recno, '+
  811. '''' + DatabaseName + ''' as catalog_name, '+
  812. ''''' as schema_name, '+
  813. 'rdb$procedure_name as proc_name, '+
  814. '0 as proc_type, '+
  815. 'rdb$procedure_inputs as in_params, '+
  816. 'rdb$procedure_outputs as out_params '+
  817. 'from '+
  818. 'rdb$procedures '+
  819. 'WHERE '+
  820. '(rdb$system_flag = 0 or rdb$system_flag is null)';
  821. stColumns : s := 'select '+
  822. 'rdb$field_id as recno, '+
  823. '''' + DatabaseName + ''' as catalog_name, '+
  824. ''''' as schema_name, '+
  825. 'rdb$relation_name as table_name, '+
  826. 'rdb$field_name as column_name, '+
  827. 'rdb$field_position as column_position, '+
  828. '0 as column_type, '+
  829. '0 as column_datatype, '+
  830. ''''' as column_typename, '+
  831. '0 as column_subtype, '+
  832. '0 as column_precision, '+
  833. '0 as column_scale, '+
  834. '0 as column_length, '+
  835. '0 as column_nullable '+
  836. 'from '+
  837. 'rdb$relation_fields '+
  838. 'WHERE '+
  839. '(rdb$system_flag = 0 or rdb$system_flag is null) and (rdb$relation_name = ''' + Uppercase(SchemaObjectName) + ''') ' +
  840. 'order by rdb$field_name';
  841. else
  842. DatabaseError(SMetadataUnavailable)
  843. end; {case}
  844. result := s;
  845. end;
  846. procedure TIBConnection.UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string);
  847. var qry : TSQLQuery;
  848. begin
  849. if not assigned(Transaction) then
  850. DatabaseError(SErrConnTransactionnSet);
  851. qry := tsqlquery.Create(nil);
  852. qry.transaction := Transaction;
  853. qry.database := Self;
  854. with qry do
  855. begin
  856. ReadOnly := True;
  857. sql.clear;
  858. sql.add('select '+
  859. 'ind.rdb$index_name, '+
  860. 'ind.rdb$relation_name, '+
  861. 'ind.rdb$unique_flag, '+
  862. 'ind_seg.rdb$field_name, '+
  863. 'rel_con.rdb$constraint_type, '+
  864. 'ind.rdb$index_type '+
  865. 'from '+
  866. 'rdb$index_segments ind_seg, '+
  867. 'rdb$indices ind '+
  868. 'left outer join '+
  869. 'rdb$relation_constraints rel_con '+
  870. 'on '+
  871. 'rel_con.rdb$index_name = ind.rdb$index_name '+
  872. 'where '+
  873. '(ind_seg.rdb$index_name = ind.rdb$index_name) and '+
  874. '(ind.rdb$relation_name=''' + UpperCase(TableName) +''') '+
  875. 'order by '+
  876. 'ind.rdb$index_name;');
  877. open;
  878. end;
  879. IndexDefs.Clear;
  880. while not qry.eof do with IndexDefs.AddIndexDef do
  881. begin
  882. Name := trim(qry.fields[0].asstring);
  883. Fields := trim(qry.Fields[3].asstring);
  884. If qry.fields[4].asstring = 'PRIMARY KEY' then options := options + [ixPrimary];
  885. If qry.fields[2].asinteger = 1 then options := options + [ixUnique];
  886. If qry.fields[5].asInteger = 1 then options:=options+[ixDescending];
  887. qry.next;
  888. while (name = trim(qry.fields[0].asstring)) and (not qry.eof) do
  889. begin
  890. Fields := Fields + ';' + trim(qry.Fields[3].asstring);
  891. qry.next;
  892. end;
  893. end;
  894. qry.close;
  895. qry.free;
  896. end;
  897. procedure TIBConnection.SetFloat(CurrBuff: pointer; Dbl: Double; Size: integer);
  898. var
  899. Ext : extended;
  900. Sin : single;
  901. begin
  902. case Size of
  903. 4 :
  904. begin
  905. Sin := Dbl;
  906. Move(Sin, CurrBuff^, 4);
  907. end;
  908. 8 :
  909. begin
  910. Move(Dbl, CurrBuff^, 8);
  911. end;
  912. 10:
  913. begin
  914. Ext := Dbl;
  915. Move(Ext, CurrBuff^, 10);
  916. end;
  917. end;
  918. end;
  919. procedure TIBConnection.GetFloat(CurrBuff, Buffer : pointer; Size : byte);
  920. var
  921. Ext : extended;
  922. Dbl : double;
  923. Sin : single;
  924. begin
  925. case Size of
  926. 4 :
  927. begin
  928. Move(CurrBuff^, Sin, 4);
  929. Dbl := Sin;
  930. end;
  931. 8 :
  932. begin
  933. Move(CurrBuff^, Dbl, 8);
  934. end;
  935. 10:
  936. begin
  937. Move(CurrBuff^, Ext, 10);
  938. Dbl := double(Ext);
  939. end;
  940. end;
  941. Move(Dbl, Buffer^, 8);
  942. end;
  943. function TIBConnection.getMaxBlobSize(blobHandle : TIsc_Blob_Handle) : longInt;
  944. var
  945. iscInfoBlobMaxSegment : byte = isc_info_blob_max_segment;
  946. blobInfo : array[0..50] of byte;
  947. begin
  948. if isc_blob_info(@Fstatus[0], @blobHandle, sizeof(iscInfoBlobMaxSegment), pchar(@iscInfoBlobMaxSegment), sizeof(blobInfo) - 2, pchar(@blobInfo[0])) <> 0 then
  949. CheckError('isc_blob_info', FStatus);
  950. if blobInfo[0] = isc_info_blob_max_segment then
  951. begin
  952. result := isc_vax_integer(pchar(@blobInfo[3]), isc_vax_integer(pchar(@blobInfo[1]), 2));
  953. end
  954. else
  955. CheckError('isc_blob_info', FStatus);
  956. end;
  957. procedure TIBConnection.LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField; cursor: TSQLCursor; ATransaction : TSQLTransaction);
  958. const
  959. isc_segstr_eof = 335544367; // It's not defined in ibase60 but in ibase40. Would it be better to define in ibase60?
  960. var
  961. blobHandle : Isc_blob_Handle;
  962. blobSegment : pointer;
  963. blobSegLen : word;
  964. maxBlobSize : longInt;
  965. TransactionHandle : pointer;
  966. blobId : PISC_QUAD;
  967. ptr : Pointer;
  968. begin
  969. blobId := PISC_QUAD(@(ABlobBuf^.ConnBlobBuffer));
  970. TransactionHandle := Atransaction.Handle;
  971. blobHandle := nil;
  972. if isc_open_blob(@FStatus[0], @FSQLDatabaseHandle, @TransactionHandle, @blobHandle, blobId) <> 0 then
  973. CheckError('TIBConnection.CreateBlobStream', FStatus);
  974. maxBlobSize := getMaxBlobSize(blobHandle);
  975. blobSegment := AllocMem(maxBlobSize);
  976. with ABlobBuf^.BlobBuffer^ do
  977. begin
  978. Size := 0;
  979. while (isc_get_segment(@FStatus[0], @blobHandle, @blobSegLen, maxBlobSize, blobSegment) = 0) do
  980. begin
  981. ReAllocMem(Buffer,Size+blobSegLen);
  982. ptr := Buffer+Size;
  983. move(blobSegment^,ptr^,blobSegLen);
  984. inc(Size,blobSegLen);
  985. end;
  986. end;
  987. freemem(blobSegment);
  988. if FStatus[1] = isc_segstr_eof then
  989. begin
  990. if isc_close_blob(@FStatus[0], @blobHandle) <> 0 then
  991. CheckError('TIBConnection.CreateBlobStream isc_close_blob', FStatus);
  992. end
  993. else
  994. CheckError('TIBConnection.CreateBlobStream isc_get_segment', FStatus);
  995. end;
  996. { TIBConnectionDef }
  997. class function TIBConnectionDef.TypeName: String;
  998. begin
  999. Result:='Firebird';
  1000. end;
  1001. class function TIBConnectionDef.ConnectionClass: TSQLConnectionClass;
  1002. begin
  1003. Result:=TIBConnection;
  1004. end;
  1005. class function TIBConnectionDef.Description: String;
  1006. begin
  1007. Result:='Connect to Firebird/Interbase directly via the client library';
  1008. end;
  1009. initialization
  1010. RegisterConnection(TIBConnectionDef);
  1011. finalization
  1012. UnRegisterConnection(TIBConnectionDef);
  1013. end.