sqldbtoolsunit.pas 18 KB

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