Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-11

MySQL auto commit

3 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aradeonas

[Cross posted on forum so if you want answer there : http://forum.lazarus.freepascal.org/index.php/topic,30343.0.html[http://forum.lazarus.freepascal.org/index.php/topic,30097.0.html]]

Is there any support for automatically commit changes for MySQL? I test it and it seems there isnt any and I should commit every time I execute a query.

Here is a test version for you :

SQL code for test db :

Show quoted text 11 lines
DROP TABLE IF EXISTS `testtable`; CREATE TABLE `testtable` (? `ID` int(11) NOT NULL,? `Title` varchar(255) DEFAULT NULL,? PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `testtable` VALUES ('1', null); INSERT INTO `testtable` VALUES ('2', null); INSERT INTO `testtable` VALUES ('3', null); INSERT INTO `testtable` VALUES ('4', null); INSERT INTO `testtable` VALUES ('5', null); INSERT INTO `testtable` VALUES ('6', null); INSERT INTO `testtable` VALUES ('7', null); INSERT INTO `testtable` VALUES ('8', null); INSERT INTO `testtable` VALUES ('9', null);

Code:

Show quoted text 39 lines
unit Unit1; {$mode objfpc}{$H+} interface uses? Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, sqldb, mysql55conn; type { TForm1 } TForm1 = class(TForm)??? procedure FormCreate(Sender: TObject); private??? { private declarations }? public? end; var? Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var? Connector: TSQLConnector;? Transaction: TSQLTransaction;? Query: TSQLQuery; begin Connector := TSQLConnector.Create(nil);? with Connector do? begin ConnectorType := 'MySQL 5.5';??? HostName := 'localhost';??? UserName := 'root';??? Password := '';??? DatabaseName := 'test';??? CharSet := 'utf8';? end;? Transaction := TSQLTransaction.Create(nil); Transaction.DataBase := Connector;? Query := TSQLQuery.Create(nil); Query.DataBase := Connector;? Connector.Connected := True; Query.SQL.Text := 'SELECT * FROM testtable';? Query.Open;? while not Query.EOF do? begin??? Connector.ExecuteDirect(Format('UPDATE testtable SET Title="Test" WHERE ID=%d;',[Query.FieldByName('ID').AsInteger])); Connector.Transaction.Commit;//problem!??? Query.Next;? end; end; end.

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".

Please someone let me know what is the problem.

Regards, Ara

http://www.fastmail.com - A no graphics, no pop-ups email service -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151111/d14458c1/attachment.html>

Reply by email

Aradeonas
to Aradeonas

mirce.vladimirov point me to commitretaining so I test it It?helps to not getting "Operation can't be performed on active transaction" error but still Im searching for a better way for a auto commit way.

Regards,
Ara

http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow

Reply by email

Aradeonas
to Aradeonas

Thanks to I checked project with trunk version and it works if I set Transaction.Options:=[stoUseImplicit];
But there is a problem it just work with MySQLConnection and not with TSQLConnector even if you set ConnectorType to MySQL. So it seems TSQLConnector have a bug.can any one test it confirm it?

Regards,
Ara

http://www.fastmail.com - Or how I learned to stop worrying and love email again

Reply by email