sqldbtoolsunit.pas 19 KB

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