sqldbtoolsunit.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 not built yet on Win64}
  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. 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. end;
  231. ssSQLite:
  232. begin
  233. FieldtypeDefinitions[ftWord] := 'WORD';
  234. FieldtypeDefinitions[ftCurrency] := 'CURRENCY';
  235. FieldtypeDefinitions[ftBytes] := 'BINARY(5)';
  236. FieldtypeDefinitions[ftVarBytes] := 'VARBINARY(10)';
  237. FieldtypeDefinitions[ftMemo] := 'CLOB'; //or TEXT SQLite supports both, but CLOB is sql standard (TEXT not)
  238. FieldtypeDefinitions[ftWideString] := 'NVARCHAR(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. tsqlquery(Result).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.