sqldbtoolsunit.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. unit SQLDBToolsUnit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, toolsunit
  6. ,db, sqldb
  7. ,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn,ibconnection
  8. {$IFNDEF WIN64}
  9. {See packages\fcl-db\src\sqldb\postgres\fpmake.pp: postgres connector won't be present on Win64}
  10. ,pqconnection
  11. {$ENDIF WIN64}
  12. ,odbcconn
  13. {$IFNDEF WIN64}
  14. {See packages\fcl-db\fpmake.pp: Oracle connector is not built if PostgreSQL connectoris not built}
  15. ,oracleconnection
  16. {$ENDIF WIN64}
  17. ,sqlite3conn
  18. {$IFNDEF WIN64}
  19. {This won't be available on Windows 64, either; perhaps other systems as well}
  20. ,mssqlconn
  21. {$ENDIF WIN64}
  22. ;
  23. type
  24. TSQLConnType = (mysql40,mysql41,mysql50,mysql51,mysql55,postgresql,interbase,odbc,oracle,sqlite3,mssql,sybase);
  25. TSQLServerType = (ssFirebird, ssInterbase, ssMSSQL, ssMySQL, ssOracle, ssPostgreSQL, ssSQLite, ssSybase, ssUnknown);
  26. const
  27. MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
  28. SQLConnTypesNames : Array [TSQLConnType] of String[19] =
  29. ('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL','SYBASE');
  30. STestNotApplicable = 'This test does not apply to this sqldb-connection type';
  31. type
  32. { TSQLDBConnector }
  33. TSQLDBConnector = class(TDBConnector)
  34. private
  35. FConnection : TSQLConnection;
  36. FTransaction : TSQLTransaction;
  37. FQuery : TSQLQuery;
  38. FUniDirectional: boolean;
  39. procedure CreateFConnection;
  40. procedure CreateFTransaction;
  41. Function CreateQuery : TSQLQuery;
  42. protected
  43. procedure SetTestUniDirectional(const AValue: boolean); override;
  44. function GetTestUniDirectional: boolean; override;
  45. procedure CreateNDatasets; override;
  46. procedure CreateFieldDataset; override;
  47. procedure DropNDatasets; override;
  48. procedure DropFieldDataset; override;
  49. Function InternalGetNDataset(n : integer) : TDataset; override;
  50. Function InternalGetFieldDataset : TDataSet; override;
  51. procedure TryDropIfExist(ATableName : String);
  52. public
  53. destructor Destroy; override;
  54. constructor Create; override;
  55. procedure ExecuteDirect(const SQL: string);
  56. procedure CommitDDL;
  57. property Connection : TSQLConnection read FConnection;
  58. property Transaction : TSQLTransaction read FTransaction;
  59. property Query : TSQLQuery read FQuery;
  60. end;
  61. var SQLConnType : TSQLConnType;
  62. SQLServerType : TSQLServerType;
  63. FieldtypeDefinitions : Array [TFieldType] of String[20];
  64. implementation
  65. uses StrUtils;
  66. type
  67. TSQLServerTypesMapItem = record
  68. s: string;
  69. t: TSQLServerType;
  70. end;
  71. const
  72. FieldtypeDefinitionsConst : Array [TFieldType] of String[20] =
  73. (
  74. '',
  75. 'VARCHAR(10)',
  76. 'SMALLINT',
  77. 'INTEGER',
  78. '', // ftWord
  79. 'BOOLEAN',
  80. 'DOUBLE PRECISION', // ftFloat
  81. '', // ftCurrency
  82. 'DECIMAL(18,4)',// ftBCD
  83. 'DATE',
  84. 'TIME',
  85. 'TIMESTAMP', // ftDateTime
  86. '', // ftBytes
  87. '', // ftVarBytes
  88. '', // ftAutoInc
  89. 'BLOB', // ftBlob
  90. 'BLOB', // ftMemo
  91. 'BLOB', // ftGraphic
  92. '',
  93. '',
  94. '',
  95. '',
  96. '',
  97. 'CHAR(10)', // ftFixedChar
  98. '', // ftWideString
  99. 'BIGINT', // ftLargeInt
  100. '',
  101. '',
  102. '',
  103. '',
  104. '',
  105. '',
  106. '',
  107. '',
  108. '',
  109. '', // ftGuid
  110. 'TIMESTAMP', // ftTimestamp
  111. 'NUMERIC(18,6)',// ftFmtBCD
  112. '', // ftFixedWideChar
  113. '' // ftWideMemo
  114. );
  115. // names as returned by ODBC SQLGetInfo(..., SQL_DBMS_NAME, ...) and GetConnectionInfo(citServerType)
  116. SQLServerTypesMap : array [0..7] of TSQLServerTypesMapItem = (
  117. (s: 'Firebird'; t: ssFirebird),
  118. (s: 'Interbase'; t: ssInterbase),
  119. (s: 'Microsoft SQL Server'; t: ssMSSQL),
  120. (s: 'MySQL'; t: ssMySQL),
  121. (s: 'Oracle'; t: ssOracle),
  122. (s: 'PostgreSQL'; t: ssPostgreSQL),
  123. (s: 'SQLite3'; t: ssSQLite),
  124. (s: 'ASE'; t: ssSybase)
  125. );
  126. // fall back mapping (e.g. in case GetConnectionInfo(citServerType) is not implemented)
  127. SQLConnTypeToServerTypeMap : array[TSQLConnType] of TSQLServerType =
  128. (ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase);
  129. { TSQLDBConnector }
  130. procedure TSQLDBConnector.CreateFConnection;
  131. var t : TSQLConnType;
  132. i : integer;
  133. s : string;
  134. begin
  135. for t := low(SQLConnTypesNames) to high(SQLConnTypesNames) do
  136. if UpperCase(dbconnectorparams) = SQLConnTypesNames[t] then SQLConnType := t;
  137. if SQLConnType = MYSQL40 then Fconnection := TMySQL40Connection.Create(nil);
  138. if SQLConnType = MYSQL41 then Fconnection := TMySQL41Connection.Create(nil);
  139. if SQLConnType = MYSQL50 then Fconnection := TMySQL50Connection.Create(nil);
  140. if SQLConnType = MYSQL51 then Fconnection := TMySQL51Connection.Create(nil);
  141. if SQLConnType = MYSQL55 then Fconnection := TMySQL55Connection.Create(nil);
  142. if SQLConnType = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil);
  143. if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil);
  144. if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil);
  145. if SQLConnType = ODBC then Fconnection := TODBCConnection.Create(nil);
  146. {$IFNDEF Win64}
  147. if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil);
  148. {$ENDIF Win64}
  149. if SQLConnType = MSSQL then Fconnection := TMSSQLConnection.Create(nil);
  150. if SQLConnType = SYBASE then Fconnection := TSybaseConnection.Create(nil);
  151. if not assigned(Fconnection) then writeln('Invalid database type, check if a valid database type for your achitecture was provided in the file ''database.ini''');
  152. with Fconnection do
  153. begin
  154. DatabaseName := dbname;
  155. UserName := dbuser;
  156. Password := dbpassword;
  157. HostName := dbhostname;
  158. if (dbhostname='') and (SQLConnType=interbase) then
  159. begin
  160. // Firebird embedded: create database file if it doesn't yet exist
  161. // Note: pagesize parameter has influence on behavior. We're using
  162. // Firebird default here.
  163. if not(fileexists(dbname)) then
  164. CreateDB; //Create testdb
  165. end;
  166. if length(dbQuoteChars)>1 then
  167. FieldNameQuoteChars:=dbQuoteChars;
  168. Open;
  169. end;
  170. // determine remote SQL Server to which we are connected
  171. s := Fconnection.GetConnectionInfo(citServerType);
  172. if s = '' then
  173. SQLServerType := SQLConnTypeToServerTypeMap[SQLConnType] // if citServerType isn't implemented
  174. else
  175. for i := low(SQLServerTypesMap) to high(SQLServerTypesMap) do
  176. if SQLServerTypesMap[i].s = s then
  177. SQLServerType := SQLServerTypesMap[i].t;
  178. FieldtypeDefinitions := FieldtypeDefinitionsConst;
  179. case SQLServerType of
  180. ssFirebird:
  181. begin
  182. FieldtypeDefinitions[ftBoolean] := '';
  183. FieldtypeDefinitions[ftMemo] := 'BLOB SUB_TYPE TEXT';
  184. end;
  185. ssInterbase:
  186. begin
  187. FieldtypeDefinitions[ftMemo] := 'BLOB SUB_TYPE TEXT';
  188. FieldtypeDefinitions[ftLargeInt] := 'NUMERIC(18,0)';
  189. end;
  190. ssMSSQL, ssSybase:
  191. // todo: Sybase: copied over MSSQL; verify correctness
  192. begin
  193. FieldtypeDefinitions[ftBoolean] := 'BIT';
  194. FieldtypeDefinitions[ftFloat] := 'FLOAT';
  195. FieldtypeDefinitions[ftCurrency]:= 'MONEY';
  196. FieldtypeDefinitions[ftDate] := 'DATETIME';
  197. FieldtypeDefinitions[ftTime] := '';
  198. FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
  199. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  200. FieldtypeDefinitions[ftVarBytes]:= 'VARBINARY(10)';
  201. FieldtypeDefinitions[ftBlob] := 'IMAGE';
  202. FieldtypeDefinitions[ftMemo] := 'TEXT';
  203. FieldtypeDefinitions[ftGraphic] := '';
  204. end;
  205. ssMySQL:
  206. begin
  207. //MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
  208. FieldtypeDefinitions[ftBoolean] := '';
  209. // Use 'DATETIME' for datetime-fields instead of timestamp, because
  210. // mysql's timestamps are only valid in the range 1970-2038.
  211. // Downside is that fields defined as 'TIMESTAMP' aren't tested
  212. FieldtypeDefinitions[ftDateTime] := 'DATETIME';
  213. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  214. FieldtypeDefinitions[ftVarBytes] := 'VARBINARY(10)';
  215. FieldtypeDefinitions[ftMemo] := 'TEXT';
  216. end;
  217. ssOracle:
  218. begin
  219. FieldtypeDefinitions[ftBoolean] := '';
  220. FieldtypeDefinitions[ftTime] := 'TIMESTAMP';
  221. FieldtypeDefinitions[ftMemo] := 'CLOB';
  222. end;
  223. ssPostgreSQL:
  224. begin
  225. FieldtypeDefinitions[ftCurrency] := 'MONEY'; // ODBC?!
  226. FieldtypeDefinitions[ftBlob] := 'BYTEA';
  227. FieldtypeDefinitions[ftMemo] := 'TEXT';
  228. FieldtypeDefinitions[ftGraphic] := '';
  229. end;
  230. ssSQLite:
  231. begin
  232. FieldtypeDefinitions[ftWord] := 'WORD';
  233. FieldtypeDefinitions[ftCurrency] := 'CURRENCY';
  234. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  235. FieldtypeDefinitions[ftVarBytes] := 'VARBINARY(10)';
  236. FieldtypeDefinitions[ftMemo] := 'CLOB'; //or TEXT SQLite supports both, but CLOB is sql standard (TEXT not)
  237. FieldtypeDefinitions[ftWideString] := 'NVARCHAR(10)';
  238. FieldtypeDefinitions[ftWideMemo] := 'NCLOB';
  239. end;
  240. end;
  241. if SQLConnType in [mysql40,mysql41] then
  242. begin
  243. // Mysql versions prior to 5.0.3 removes the trailing spaces on varchar
  244. // fields on insertion. So to test properly, we have to do the same
  245. for i := 0 to testValuesCount-1 do
  246. testStringValues[i] := TrimRight(testStringValues[i]);
  247. end;
  248. if SQLServerType in [ssMySQL] then
  249. begin
  250. // Some DB's do not support milliseconds in datetime and time fields.
  251. for i := 0 to testValuesCount-1 do
  252. begin
  253. testTimeValues[i] := copy(testTimeValues[i],1,8)+'.000';
  254. testValues[ftTime,i] := copy(testTimeValues[i],1,8)+'.000';
  255. if length(testValues[ftDateTime,i]) > 19 then
  256. testValues[ftDateTime,i] := copy(testValues[ftDateTime,i],1,19)+'.000';
  257. end;
  258. end;
  259. if SQLServerType in [ssFirebird, ssInterbase, ssMSSQL, ssPostgreSQL, ssSybase] then
  260. begin
  261. // Some db's do not support times > 24:00:00
  262. testTimeValues[3]:='13:25:15.000';
  263. testValues[ftTime,3]:='13:25:15.000';
  264. if SQLServerType in [ssFirebird, ssInterbase] then
  265. begin
  266. // Firebird does not support time = 24:00:00
  267. testTimeValues[2]:='23:00:00.000';
  268. testValues[ftTime,2]:='23:00:00.000';
  269. end;
  270. end;
  271. if SQLServerType in [ssMSSQL, ssSybase] then
  272. // Some DB's do not support datetime values before 1753-01-01
  273. for i := 18 to testValuesCount-1 do
  274. begin
  275. testValues[ftDate,i] := testValues[ftDate,0];
  276. testValues[ftDateTime,i] := testValues[ftDateTime,0];
  277. end;
  278. // DecimalSeparator must correspond to monetary locale (lc_monetary) set on PostgreSQL server
  279. // Here we assume, that locale on client side is same as locale on server
  280. if SQLServerType in [ssPostgreSQL] then
  281. for i := 0 to testValuesCount-1 do
  282. testValues[ftCurrency,i] := QuotedStr(CurrToStr(testCurrencyValues[i]));
  283. // SQLite does not support fixed length CHAR datatype
  284. // MySQL by default trimms trailing spaces on retrieval; so set sql-mode="PAD_CHAR_TO_FULL_LENGTH" - supported from MySQL 5.1.20
  285. // MSSQL set SET ANSI_PADDING ON
  286. // todo: verify Sybase behaviour
  287. if SQLServerType in [ssSQLite] then
  288. for i := 0 to testValuesCount-1 do
  289. testValues[ftFixedChar,i] := PadRight(testValues[ftFixedChar,i], 10);
  290. end;
  291. procedure TSQLDBConnector.CreateFTransaction;
  292. begin
  293. Ftransaction := tsqltransaction.create(nil);
  294. with Ftransaction do
  295. database := Fconnection;
  296. end;
  297. function TSQLDBConnector.CreateQuery: TSQLQuery;
  298. begin
  299. Result := TSQLQuery.create(nil);
  300. with Result do
  301. begin
  302. database := Fconnection;
  303. transaction := Ftransaction;
  304. PacketRecords := -1; // To avoid: "Connection is busy with results for another hstmt" (ODBC,MSSQL)
  305. end;
  306. end;
  307. procedure TSQLDBConnector.SetTestUniDirectional(const AValue: boolean);
  308. begin
  309. FUniDirectional:=avalue;
  310. FQuery.UniDirectional:=AValue;
  311. end;
  312. function TSQLDBConnector.GetTestUniDirectional: boolean;
  313. begin
  314. result := FUniDirectional;
  315. end;
  316. procedure TSQLDBConnector.CreateNDatasets;
  317. var CountID : Integer;
  318. begin
  319. try
  320. Ftransaction.StartTransaction;
  321. TryDropIfExist('FPDEV');
  322. Fconnection.ExecuteDirect('create table FPDEV (' +
  323. ' ID INT NOT NULL, ' +
  324. ' NAME VARCHAR(50), ' +
  325. ' PRIMARY KEY (ID) ' +
  326. ')');
  327. FTransaction.CommitRetaining;
  328. for countID := 1 to MaxDataSet do
  329. Fconnection.ExecuteDirect('insert into FPDEV (ID,NAME)' +
  330. 'values ('+inttostr(countID)+',''TestName'+inttostr(countID)+''')');
  331. Ftransaction.Commit;
  332. except
  333. if Ftransaction.Active then Ftransaction.Rollback
  334. end;
  335. end;
  336. procedure TSQLDBConnector.CreateFieldDataset;
  337. var CountID : Integer;
  338. FType : TFieldType;
  339. Sql,sql1: String;
  340. begin
  341. try
  342. Ftransaction.StartTransaction;
  343. TryDropIfExist('FPDEV_FIELD');
  344. Sql := 'create table FPDEV_FIELD (ID INT NOT NULL,';
  345. for FType := low(TFieldType)to high(TFieldType) do
  346. if FieldtypeDefinitions[FType]<>'' then
  347. sql := sql + 'F' + Fieldtypenames[FType] + ' ' +FieldtypeDefinitions[FType]+ ',';
  348. Sql := Sql + 'PRIMARY KEY (ID))';
  349. FConnection.ExecuteDirect(Sql);
  350. FTransaction.CommitRetaining;
  351. for countID := 0 to testValuesCount-1 do
  352. begin
  353. Sql := 'insert into FPDEV_FIELD (ID';
  354. Sql1 := 'values ('+IntToStr(countID);
  355. for FType := low(TFieldType)to high(TFieldType) do
  356. if FieldtypeDefinitions[FType]<>'' then
  357. begin
  358. sql := sql + ',F' + Fieldtypenames[FType];
  359. if testValues[FType,CountID] <> '' then
  360. if FType in [ftCurrency] then
  361. sql1 := sql1 + ',' + testValues[FType,CountID]
  362. else
  363. sql1 := sql1 + ',' + QuotedStr(testValues[FType,CountID])
  364. else
  365. sql1 := sql1 + ',NULL';
  366. end;
  367. Sql := sql + ')';
  368. Sql1 := sql1+ ')';
  369. Fconnection.ExecuteDirect(sql + ' ' + sql1);
  370. end;
  371. Ftransaction.Commit;
  372. except
  373. on E: Exception do begin
  374. //writeln(E.Message);
  375. if Ftransaction.Active then Ftransaction.Rollback;
  376. end;
  377. end;
  378. end;
  379. procedure TSQLDBConnector.DropNDatasets;
  380. begin
  381. if assigned(FTransaction) then
  382. begin
  383. try
  384. if Ftransaction.Active then Ftransaction.Rollback;
  385. Ftransaction.StartTransaction;
  386. Fconnection.ExecuteDirect('DROP TABLE FPDEV');
  387. Ftransaction.Commit;
  388. Except
  389. if Ftransaction.Active then Ftransaction.Rollback
  390. end;
  391. end;
  392. end;
  393. procedure TSQLDBConnector.DropFieldDataset;
  394. begin
  395. if assigned(FTransaction) then
  396. begin
  397. try
  398. if Ftransaction.Active then Ftransaction.Rollback;
  399. Ftransaction.StartTransaction;
  400. Fconnection.ExecuteDirect('DROP TABLE FPDEV_FIELD');
  401. Ftransaction.Commit;
  402. Except
  403. if Ftransaction.Active then Ftransaction.Rollback
  404. end;
  405. end;
  406. end;
  407. function TSQLDBConnector.InternalGetNDataset(n: integer): TDataset;
  408. begin
  409. Result := CreateQuery;
  410. with (Result as TSQLQuery) do
  411. begin
  412. sql.clear;
  413. sql.add('SELECT * FROM FPDEV WHERE ID < '+inttostr(n+1));
  414. UniDirectional:=TestUniDirectional;
  415. end;
  416. end;
  417. function TSQLDBConnector.InternalGetFieldDataset: TDataSet;
  418. begin
  419. Result := CreateQuery;
  420. with (Result as TSQLQuery) do
  421. begin
  422. sql.clear;
  423. sql.add('SELECT * FROM FPDEV_FIELD');
  424. tsqlquery(Result).UniDirectional:=TestUniDirectional;
  425. end;
  426. end;
  427. procedure TSQLDBConnector.TryDropIfExist(ATableName: String);
  428. begin
  429. // This makes life soo much easier, since it avoids the exception if the table already
  430. // exists. And while this exeption is in a try..except statement, the debugger
  431. // always shows the exception, which is pretty annoying.
  432. try
  433. case SQLServerType of
  434. ssFirebird:
  435. begin
  436. // This only works with Firebird 2+
  437. FConnection.ExecuteDirect('execute block as begin if (exists (select 1 from rdb$relations where rdb$relation_name=''' + ATableName + ''')) '+
  438. 'then execute statement ''drop table ' + ATableName + ';'';end');
  439. FTransaction.CommitRetaining;
  440. end;
  441. ssMSSQL:
  442. begin
  443. // Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
  444. // which leads to the rollback not referring to the right transaction=>SQL error
  445. // Use SQL92 ISO standard INFORMATION_SCHEMA:
  446. FConnection.ExecuteDirect(
  447. 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE=''BASE TABLE'' AND TABLE_NAME=''' + ATableName + ''') '+
  448. 'begin '+
  449. 'drop table ' + ATableName + ' '+
  450. 'end');
  451. end;
  452. ssSybase:
  453. begin
  454. // Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
  455. // which leads to the rollback not referring to the right transaction=>SQL error
  456. // Can't use SQL standard information_schema; instead query sysobjects for User tables
  457. FConnection.ExecuteDirect(
  458. 'if exists (select * from sysobjects where type = ''U'' and name=''' + ATableName + ''') '+
  459. 'begin '+
  460. 'drop table ' + ATableName + ' '+
  461. 'end');
  462. end;
  463. end;
  464. except
  465. FTransaction.RollbackRetaining;
  466. end;
  467. end;
  468. procedure TSQLDBConnector.ExecuteDirect(const SQL: string);
  469. begin
  470. Connection.ExecuteDirect(SQL);
  471. end;
  472. procedure TSQLDBConnector.CommitDDL;
  473. begin
  474. // Commits schema definition and manipulation statements;
  475. // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
  476. if SQLServerType in [ssFirebird, ssInterbase] then
  477. Transaction.CommitRetaining;
  478. end;
  479. destructor TSQLDBConnector.Destroy;
  480. begin
  481. if assigned(FTransaction) then
  482. begin
  483. try
  484. if Ftransaction.Active then Ftransaction.Rollback;
  485. Ftransaction.StartTransaction;
  486. Fconnection.ExecuteDirect('DROP TABLE FPDEV2');
  487. Ftransaction.Commit;
  488. Except
  489. if Ftransaction.Active then Ftransaction.Rollback;
  490. end; // try
  491. end;
  492. inherited Destroy;
  493. FreeAndNil(FQuery);
  494. FreeAndNil(FTransaction);
  495. FreeAndNil(FConnection);
  496. end;
  497. constructor TSQLDBConnector.Create;
  498. begin
  499. FConnection := nil;
  500. CreateFConnection;
  501. CreateFTransaction;
  502. FQuery := CreateQuery;
  503. FConnection.Transaction := FTransaction;
  504. Inherited;
  505. end;
  506. initialization
  507. RegisterClass(TSQLDBConnector);
  508. end.