<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>[Cross posted on forum so if you want answer there :<br></div>
<div>http://forum.lazarus.freepascal.org/index.php/topic,30343.0.html[http://forum.lazarus.freepascal.org/index.php/topic,30097.0.html]]<br></div>
<div> </div>
<div>Is there any support for automatically commit changes for MySQL?<br></div>
<div>I test it and it seems there isnt any and I should commit every time I execute a query.<br></div>
<div> </div>
<div>Here is a test version for you :<br></div>
<div> </div>
<div>SQL code for test db :<br></div>
<div> </div>
<blockquote><div>DROP TABLE IF EXISTS `testtable`;<br></div>
<div>CREATE TABLE `testtable` (<br></div>
<div> `ID` int(11) NOT NULL,<br></div>
<div> `Title` varchar(255) DEFAULT NULL,<br></div>
<div> PRIMARY KEY (`ID`)<br></div>
<div>) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br></div>
<div> </div>
<div> </div>
<div>INSERT INTO `testtable` VALUES ('1', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('2', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('3', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('4', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('5', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('6', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('7', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('8', null);<br></div>
<div>INSERT INTO `testtable` VALUES ('9', null);<br></div>
</blockquote><div> </div>
<div>Code:<br></div>
<div> </div>
<blockquote><div>unit Unit1;<br></div>
<div> </div>
<div>{$mode objfpc}{$H+}<br></div>
<div> </div>
<div>interface<br></div>
<div> </div>
<div>uses<br></div>
<div> Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, sqldb, mysql55conn;<br></div>
<div> </div>
<div>type<br></div>
<div> </div>
<div> { TForm1 }<br></div>
<div> </div>
<div> TForm1 = class(TForm)<br></div>
<div> procedure FormCreate(Sender: TObject);<br></div>
<div> private<br></div>
<div> { private declarations }<br></div>
<div> public<br></div>
<div> end;<br></div>
<div> </div>
<div>var<br></div>
<div> Form1: TForm1;<br></div>
<div> </div>
<div>implementation<br></div>
<div> </div>
<div>{$R *.lfm}<br></div>
<div> </div>
<div>{ TForm1 }<br></div>
<div> </div>
<div>procedure TForm1.FormCreate(Sender: TObject);<br></div>
<div>var<br></div>
<div> Connector: TSQLConnector;<br></div>
<div> Transaction: TSQLTransaction;<br></div>
<div> Query: TSQLQuery;<br></div>
<div>begin<br></div>
<div> Connector := TSQLConnector.Create(nil);<br></div>
<div> with Connector do<br></div>
<div> begin<br></div>
<div> ConnectorType := 'MySQL 5.5';<br></div>
<div> HostName := 'localhost';<br></div>
<div> UserName := 'root';<br></div>
<div> Password := '';<br></div>
<div> DatabaseName := 'test';<br></div>
<div> CharSet := 'utf8';<br></div>
<div> end;<br></div>
<div> Transaction := TSQLTransaction.Create(nil);<br></div>
<div> Transaction.DataBase := Connector;<br></div>
<div> Query := TSQLQuery.Create(nil);<br></div>
<div> Query.DataBase := Connector;<br></div>
<div> Connector.Connected := True;<br></div>
<div> Query.SQL.Text := 'SELECT * FROM testtable';<br></div>
<div> Query.Open;<br></div>
<div> while not Query.EOF do<br></div>
<div> begin<br></div>
<div> Connector.ExecuteDirect(Format('UPDATE testtable SET Title="Test" WHERE ID=%d;',[Query.FieldByName('ID').AsInteger]));<br></div>
<div> Connector.Transaction.Commit;//problem!<br></div>
<div> Query.Next;<br></div>
<div> end;<br></div>
<div>end;<br></div>
<div> </div>
<div>end.<br></div>
</blockquote><div> </div>
<div> </div>
<div>If I dont do "Connector.Transaction.Commit;" changes will not save (and I want to every changes save excatly when thay post not after all changes done) and if I do "Connector.Transaction.Commit;" then Next line will give error "Operation can't be performed on active transaction".<br></div>
<div> </div>
<div>Please someone let me know what is the problem.<br></div>
<div> </div>
<div>Regards,<br></div>
<div>Ara<br></div>
<pre>
--
http://www.fastmail.com - A no graphics, no pop-ups email service
</pre>
</body>
</html>