Menu

#642 [MariaDB] Commands out of sync error after ExecSQL exception

Unknown
open
nobody
Bug Report
2025-11-01
2025-11-01
Hendi
No

This ticket is basically the same as #442. The fix there was incomplete, unfortunately.

The following program should be able to insert id 1113000 just fine at the end, but it fails with "SQL Error: Commands out of sync; you can't run this command now".

program zeosbug;

uses SysUtils, ZConnection, ZDataset;

const
  INS_DATA: array[0..2] of array[0..1] of string = (
    ('1112690','Label1'),
    ('1112656','Label2'),
    ('1112657','Label3')
  );

procedure Bug;
var
  Con: TZConnection;
  Q: TZQuery;
  i: Integer;
begin
  Con := TZConnection.Create(nil);
  Con.Protocol := 'mysql';
  Con.HostName := '127.0.0.1';
  Con.Port := 3306;
  Con.User := 'root';
  Con.Password := 'root';

  Con.Catalog := 'testschema';
  Con.Database := 'testschema';

  Con.Connected := True;

  Q := TZQuery.Create(nil);
  Q.Connection := Con;

  Q.SQL.Text := 'DROP TABLE IF EXISTS strings';
  Q.ExecSQL;

  Q.SQL.Text := 'CREATE TABLE `strings` (' +
  '`objectid` int(11) NOT NULL, ' +
  '`label` varchar(255) NOT NULL, ' +
  'PRIMARY KEY (`objectid`)' +
  ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
  Q.ExecSQL;

  Q.SQL.Text := 'INSERT INTO strings VALUES (:id, :label)';

  try
    for i := 0 to High(INS_DATA) do
    begin
      Q.ParamByName('id').AsString := INS_DATA[i][0];
      Q.ParamByName('label').AsString := INS_DATA[i][1];
      Q.ExecSQL;
    end;
  except
    on E: Exception do
      Writeln('UNEXPECTED: ', E.Message);
  end;

  try
    Q.ParamByName('id').AsInteger := 1112690;
    Q.ParamByName('label').AsString := 'bar';
    Q.ExecSQL;
    Writeln('(?) 1112690 not in INS_DATA');
  except
    on E: Exception do
      Writeln('Good: ', E.Message);
  end;

  try
    Q.ParamByName('id').AsInteger := 1113000;
    Q.ParamByName('label').AsString := 'asd';
    Q.ExecSQL;
    Writeln('No bug');
  except
    on E: Exception do
      Writeln('BUG: ', E.Message);
  end;
end;

begin
  Bug;
end.

Using trunk r8457 with FPC 3.3.1 and libmariadb 12.0.2.

Discussion


Log in to post a comment.