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
  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,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];
  23. SQLConnTypesNames : Array [TSQLConnType] of String[19] =
  24. ('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','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,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 = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil);
  138. if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil);
  139. if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil);
  140. if SQLConnType = ODBC then Fconnection := TODBCConnection.Create(nil);
  141. {$IFNDEF Win64}
  142. if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil);
  143. {$ENDIF Win64}
  144. if SQLConnType = MSSQL then Fconnection := TMSSQLConnection.Create(nil);
  145. if SQLConnType = SYBASE then Fconnection := TSybaseConnection.Create(nil);
  146. 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''');
  147. with Fconnection do
  148. begin
  149. DatabaseName := dbname;
  150. UserName := dbuser;
  151. Password := dbpassword;
  152. HostName := dbhostname;
  153. if (dbhostname='') and (SQLConnType=interbase) then
  154. begin
  155. // Firebird embedded: create database file if it doesn't yet exist
  156. // Note: pagesize parameter has influence on behavior. We're using
  157. // Firebird default here.
  158. if not(fileexists(dbname)) then
  159. CreateDB; //Create testdb
  160. end;
  161. if length(dbQuoteChars)>1 then
  162. FieldNameQuoteChars:=dbQuoteChars;
  163. Open;
  164. end;
  165. // determine remote SQL Server to which we are connected
  166. s := Fconnection.GetConnectionInfo(citServerType);
  167. if s = '' then
  168. SQLServerType := SQLConnTypeToServerTypeMap[SQLConnType] // if citServerType isn't implemented
  169. else
  170. for i := low(SQLServerTypesMap) to high(SQLServerTypesMap) do
  171. if SQLServerTypesMap[i].s = s then
  172. SQLServerType := SQLServerTypesMap[i].t;
  173. FieldtypeDefinitions := FieldtypeDefinitionsConst;
  174. case SQLServerType of
  175. ssFirebird:
  176. begin
  177. FieldtypeDefinitions[ftBoolean] := '';
  178. FieldtypeDefinitions[ftMemo] := 'BLOB SUB_TYPE TEXT';
  179. end;
  180. ssInterbase:
  181. begin
  182. FieldtypeDefinitions[ftMemo] := 'BLOB SUB_TYPE TEXT';
  183. FieldtypeDefinitions[ftLargeInt] := 'NUMERIC(18,0)';
  184. end;
  185. ssMSSQL, ssSybase:
  186. // todo: Sybase: copied over MSSQL; verify correctness
  187. begin
  188. FieldtypeDefinitions[ftBoolean] := 'BIT';
  189. FieldtypeDefinitions[ftFloat] := 'FLOAT';
  190. FieldtypeDefinitions[ftCurrency]:= 'MONEY';
  191. FieldtypeDefinitions[ftDate] := 'DATETIME';
  192. FieldtypeDefinitions[ftTime] := '';
  193. FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
  194. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  195. FieldtypeDefinitions[ftVarBytes]:= 'VARBINARY(10)';
  196. FieldtypeDefinitions[ftBlob] := 'IMAGE';
  197. FieldtypeDefinitions[ftMemo] := 'TEXT';
  198. FieldtypeDefinitions[ftGraphic] := '';
  199. FieldtypeDefinitions[ftWideString] := 'NVARCHAR(10)';
  200. FieldtypeDefinitions[ftFixedWideChar] := 'NCHAR(10)';
  201. //FieldtypeDefinitions[ftWideMemo] := 'NTEXT'; // Sybase has UNITEXT?
  202. end;
  203. ssMySQL:
  204. begin
  205. FieldtypeDefinitions[ftWord] := 'SMALLINT UNSIGNED';
  206. //MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
  207. FieldtypeDefinitions[ftBoolean] := '';
  208. // Use 'DATETIME' for datetime-fields instead of timestamp, because
  209. // mysql's timestamps are only valid in the range 1970-2038.
  210. // Downside is that fields defined as 'TIMESTAMP' aren't tested
  211. FieldtypeDefinitions[ftDateTime] := 'DATETIME';
  212. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  213. FieldtypeDefinitions[ftVarBytes] := 'VARBINARY(10)';
  214. FieldtypeDefinitions[ftMemo] := 'TEXT';
  215. end;
  216. ssOracle:
  217. begin
  218. FieldtypeDefinitions[ftBoolean] := '';
  219. FieldtypeDefinitions[ftTime] := 'TIMESTAMP';
  220. FieldtypeDefinitions[ftMemo] := 'CLOB';
  221. end;
  222. ssPostgreSQL:
  223. begin
  224. FieldtypeDefinitions[ftCurrency] := 'MONEY'; // ODBC?!
  225. FieldtypeDefinitions[ftBlob] := 'BYTEA';
  226. FieldtypeDefinitions[ftMemo] := 'TEXT';
  227. FieldtypeDefinitions[ftGraphic] := '';
  228. FieldtypeDefinitions[ftGuid] := 'UUID';
  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[ftFixedWideChar] := 'NCHAR(10)';
  239. FieldtypeDefinitions[ftWideMemo] := 'NCLOB';
  240. end;
  241. end;
  242. if SQLConnType in [mysql40,mysql41] then
  243. begin
  244. // Mysql versions prior to 5.0.3 removes the trailing spaces on varchar
  245. // fields on insertion. So to test properly, we have to do the same
  246. for i := 0 to testValuesCount-1 do
  247. testStringValues[i] := TrimRight(testStringValues[i]);
  248. end;
  249. if SQLServerType in [ssMySQL] then
  250. begin
  251. // Some DB's do not support milliseconds in datetime and time fields.
  252. for i := 0 to testValuesCount-1 do
  253. begin
  254. testTimeValues[i] := copy(testTimeValues[i],1,8)+'.000';
  255. testValues[ftTime,i] := copy(testTimeValues[i],1,8)+'.000';
  256. if length(testValues[ftDateTime,i]) > 19 then
  257. testValues[ftDateTime,i] := copy(testValues[ftDateTime,i],1,19)+'.000';
  258. end;
  259. end;
  260. if SQLServerType in [ssFirebird, ssInterbase, ssMSSQL, ssPostgreSQL, ssSybase] then
  261. begin
  262. // Some db's do not support times > 24:00:00
  263. testTimeValues[3]:='13:25:15.000';
  264. testValues[ftTime,3]:='13:25:15.000';
  265. if SQLServerType in [ssFirebird, ssInterbase] then
  266. begin
  267. // Firebird does not support time = 24:00:00
  268. testTimeValues[2]:='23:00:00.000';
  269. testValues[ftTime,2]:='23:00:00.000';
  270. end;
  271. end;
  272. if SQLServerType in [ssMSSQL, ssSybase] then
  273. // Some DB's do not support datetime values before 1753-01-01
  274. for i := 18 to testValuesCount-1 do
  275. begin
  276. testValues[ftDate,i] := testValues[ftDate,0];
  277. testValues[ftDateTime,i] := testValues[ftDateTime,0];
  278. end;
  279. // DecimalSeparator must correspond to monetary locale (lc_monetary) set on PostgreSQL server
  280. // Here we assume, that locale on client side is same as locale on server
  281. if SQLServerType in [ssPostgreSQL] then
  282. for i := 0 to testValuesCount-1 do
  283. testValues[ftCurrency,i] := QuotedStr(CurrToStr(testCurrencyValues[i]));
  284. // SQLite does not support fixed length CHAR datatype
  285. // MySQL by default trimms trailing spaces on retrieval; so set sql-mode="PAD_CHAR_TO_FULL_LENGTH" - supported from MySQL 5.1.20
  286. // MSSQL set SET ANSI_PADDING ON
  287. // todo: verify Sybase behaviour
  288. if SQLServerType in [ssSQLite] then
  289. for i := 0 to testValuesCount-1 do
  290. testValues[ftFixedChar,i] := PadRight(testValues[ftFixedChar,i], 10);
  291. end;
  292. procedure TSQLDBConnector.CreateFTransaction;
  293. begin
  294. Ftransaction := tsqltransaction.create(nil);
  295. with Ftransaction do
  296. database := Fconnection;
  297. end;
  298. function TSQLDBConnector.CreateQuery: TSQLQuery;
  299. begin
  300. Result := TSQLQuery.create(nil);
  301. with Result do
  302. begin
  303. database := Fconnection;
  304. transaction := Ftransaction;
  305. PacketRecords := -1; // To avoid: "Connection is busy with results for another hstmt" (ODBC,MSSQL)
  306. end;
  307. end;
  308. procedure TSQLDBConnector.SetTestUniDirectional(const AValue: boolean);
  309. begin
  310. FUniDirectional:=avalue;
  311. FQuery.UniDirectional:=AValue;
  312. end;
  313. function TSQLDBConnector.GetTestUniDirectional: boolean;
  314. begin
  315. result := FUniDirectional;
  316. end;
  317. procedure TSQLDBConnector.CreateNDatasets;
  318. var CountID : Integer;
  319. begin
  320. try
  321. Ftransaction.StartTransaction;
  322. TryDropIfExist('FPDEV');
  323. Fconnection.ExecuteDirect('create table FPDEV (' +
  324. ' ID INT NOT NULL, ' +
  325. ' NAME VARCHAR(50), ' +
  326. ' PRIMARY KEY (ID) ' +
  327. ')');
  328. FTransaction.CommitRetaining;
  329. for countID := 1 to MaxDataSet do
  330. Fconnection.ExecuteDirect('insert into FPDEV (ID,NAME)' +
  331. 'values ('+inttostr(countID)+',''TestName'+inttostr(countID)+''')');
  332. Ftransaction.Commit;
  333. except
  334. if Ftransaction.Active then Ftransaction.Rollback
  335. end;
  336. end;
  337. procedure TSQLDBConnector.CreateFieldDataset;
  338. var CountID : Integer;
  339. FType : TFieldType;
  340. Sql,sql1: String;
  341. begin
  342. try
  343. Ftransaction.StartTransaction;
  344. TryDropIfExist('FPDEV_FIELD');
  345. Sql := 'create table FPDEV_FIELD (ID INT NOT NULL,';
  346. for FType := low(TFieldType)to high(TFieldType) do
  347. if FieldtypeDefinitions[FType]<>'' then
  348. sql := sql + 'F' + Fieldtypenames[FType] + ' ' +FieldtypeDefinitions[FType]+ ',';
  349. Sql := Sql + 'PRIMARY KEY (ID))';
  350. FConnection.ExecuteDirect(Sql);
  351. FTransaction.CommitRetaining;
  352. for countID := 0 to testValuesCount-1 do
  353. begin
  354. Sql := 'insert into FPDEV_FIELD (ID';
  355. Sql1 := 'values ('+IntToStr(countID);
  356. for FType := low(TFieldType)to high(TFieldType) do
  357. if FieldtypeDefinitions[FType]<>'' then
  358. begin
  359. sql := sql + ',F' + Fieldtypenames[FType];
  360. if testValues[FType,CountID] <> '' then
  361. if FType in [ftCurrency] then
  362. sql1 := sql1 + ',' + testValues[FType,CountID]
  363. else
  364. sql1 := sql1 + ',' + QuotedStr(testValues[FType,CountID])
  365. else
  366. sql1 := sql1 + ',NULL';
  367. end;
  368. Sql := sql + ')';
  369. Sql1 := sql1+ ')';
  370. Fconnection.ExecuteDirect(sql + ' ' + sql1);
  371. end;
  372. Ftransaction.Commit;
  373. except
  374. on E: Exception do begin
  375. //writeln(E.Message);
  376. if Ftransaction.Active then Ftransaction.Rollback;
  377. end;
  378. end;
  379. end;
  380. procedure TSQLDBConnector.DropNDatasets;
  381. begin
  382. if assigned(FTransaction) then
  383. begin
  384. try
  385. if Ftransaction.Active then Ftransaction.Rollback;
  386. Ftransaction.StartTransaction;
  387. Fconnection.ExecuteDirect('DROP TABLE FPDEV');
  388. Ftransaction.Commit;
  389. Except
  390. if Ftransaction.Active then Ftransaction.Rollback
  391. end;
  392. end;
  393. end;
  394. procedure TSQLDBConnector.DropFieldDataset;
  395. begin
  396. if assigned(FTransaction) then
  397. begin
  398. try
  399. if Ftransaction.Active then Ftransaction.Rollback;
  400. Ftransaction.StartTransaction;
  401. Fconnection.ExecuteDirect('DROP TABLE FPDEV_FIELD');
  402. Ftransaction.Commit;
  403. Except
  404. if Ftransaction.Active then Ftransaction.Rollback
  405. end;
  406. end;
  407. end;
  408. function TSQLDBConnector.InternalGetNDataset(n: integer): TDataset;
  409. begin
  410. Result := CreateQuery;
  411. with (Result as TSQLQuery) do
  412. begin
  413. sql.clear;
  414. sql.add('SELECT * FROM FPDEV WHERE ID < '+inttostr(n+1));
  415. UniDirectional:=TestUniDirectional;
  416. end;
  417. end;
  418. function TSQLDBConnector.InternalGetFieldDataset: TDataSet;
  419. begin
  420. Result := CreateQuery;
  421. with (Result as TSQLQuery) do
  422. begin
  423. sql.clear;
  424. sql.add('SELECT * FROM FPDEV_FIELD');
  425. UniDirectional:=TestUniDirectional;
  426. end;
  427. end;
  428. procedure TSQLDBConnector.TryDropIfExist(ATableName: String);
  429. begin
  430. // This makes life soo much easier, since it avoids the exception if the table already
  431. // exists. And while this exeption is in a try..except statement, the debugger
  432. // always shows the exception, which is pretty annoying.
  433. try
  434. case SQLServerType of
  435. ssFirebird:
  436. begin
  437. // This only works with Firebird 2+
  438. FConnection.ExecuteDirect('execute block as begin if (exists (select 1 from rdb$relations where rdb$relation_name=''' + ATableName + ''')) '+
  439. 'then execute statement ''drop table ' + ATableName + ';'';end');
  440. FTransaction.CommitRetaining;
  441. end;
  442. ssMSSQL:
  443. begin
  444. // Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
  445. // which leads to the rollback not referring to the right transaction=>SQL error
  446. // Use SQL92 ISO standard INFORMATION_SCHEMA:
  447. FConnection.ExecuteDirect(
  448. 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE=''BASE TABLE'' AND TABLE_NAME=''' + ATableName + ''') '+
  449. 'begin '+
  450. 'drop table ' + ATableName + ' '+
  451. 'end');
  452. end;
  453. ssSybase:
  454. begin
  455. // Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
  456. // which leads to the rollback not referring to the right transaction=>SQL error
  457. // Can't use SQL standard information_schema; instead query sysobjects for User tables
  458. FConnection.ExecuteDirect(
  459. 'if exists (select * from sysobjects where type = ''U'' and name=''' + ATableName + ''') '+
  460. 'begin '+
  461. 'drop table ' + ATableName + ' '+
  462. 'end');
  463. end;
  464. end;
  465. except
  466. FTransaction.RollbackRetaining;
  467. end;
  468. end;
  469. procedure TSQLDBConnector.ExecuteDirect(const SQL: string);
  470. begin
  471. Connection.ExecuteDirect(SQL);
  472. end;
  473. procedure TSQLDBConnector.CommitDDL;
  474. begin
  475. // Commits schema definition and manipulation statements;
  476. // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
  477. if SQLServerType in [ssFirebird, ssInterbase] then
  478. Transaction.CommitRetaining;
  479. end;
  480. destructor TSQLDBConnector.Destroy;
  481. begin
  482. if assigned(FTransaction) then
  483. begin
  484. try
  485. if Ftransaction.Active then Ftransaction.Rollback;
  486. Ftransaction.StartTransaction;
  487. Fconnection.ExecuteDirect('DROP TABLE FPDEV2');
  488. Ftransaction.Commit;
  489. Except
  490. if Ftransaction.Active then Ftransaction.Rollback;
  491. end; // try
  492. end;
  493. inherited Destroy;
  494. FreeAndNil(FQuery);
  495. FreeAndNil(FTransaction);
  496. FreeAndNil(FConnection);
  497. end;
  498. constructor TSQLDBConnector.Create;
  499. begin
  500. FConnection := nil;
  501. CreateFConnection;
  502. CreateFTransaction;
  503. FQuery := CreateQuery;
  504. FConnection.Transaction := FTransaction;
  505. Inherited;
  506. end;
  507. initialization
  508. RegisterClass(TSQLDBConnector);
  509. end.