Acron
Acron

Reputation: 1398

Delphi ADO SQL Syntax Error

I am getting an Syntax Error when processing the following lines of code. Especially on the AQ_Query.Open;

procedure THauptfenster.Button1Click(Sender: TObject);
var
    option: TZahlerArray;
begin
    option := werZahlte;
    AQ_Query.Close;
  AQ_Query.SQL.Clear;
  AQ_Query.SQL.Add('USE wgwgwg;');
  AQ_Query.SQL.Add('INSERT INTO abrechnung ');
  AQ_Query.SQL.Add('(`datum`, `titel`, `betrag`, `waldemar`, `jonas`, `ali`, `ben`)');
  AQ_Query.SQL.Add(' VALUES ');
  AQ_Query.SQL.Add('(:datum, :essen, :betrag, :waldemar, :jonas, :ali, :ben);');
  AQ_Query.Parameters.ParamByName('datum').Value := DateToStr(mcDatum.Date);
  AQ_Query.Parameters.ParamByName('essen').Value := ledTitel.Text;
  AQ_Query.Parameters.ParamByName('betrag').Value := ledPreis.Text;
  AQ_Query.Parameters.ParamByName('waldemar').Value := option[0];
  AQ_Query.Parameters.ParamByName('jonas').Value := option[1];
  AQ_Query.Parameters.ParamByName('ali').Value := option[2];
  AQ_Query.Parameters.ParamByName('ben').Value := option[3];
  AQ_Query.Open;
end;

The error:

SQL Error

I am using MySQL Delphi 2010.

Upvotes: 0

Views: 1817

Answers (3)

Ravaut123
Ravaut123

Reputation: 2798

Use the database in the sql script.

AQ_Query.SQL.Add('INSERT INTO wgwgwg.dbo.abrechnung ');
  AQ_Query.SQL.Add('(`wgwgwg.dbo.abrechnung.datum`, `wgwgwg.dbo.abrechnungtitel`, `wgwgwg.dbo.abrechnungbetrag`, `wgwgwg.dbo.abrechnungwaldemar`, `wgwgwg.dbo.abrechnungjonas`, `wgwgwg.dbo.abrechnungali`, `wgwgwg.dbo.abrechnungben`)');

  AQ_Query.SQL.Add(' VALUES ');

  AQ_Query.SQL.Add('(:datum, :essen, :betrag, :waldemar, :jonas, :ali, :ben);');
  AQ_Query.Parameters.ParamByName('datum').Value := DateToStr(mcDatum.Date);
  AQ_Query.Parameters.ParamByName('essen').Value := ledTitel.Text;
  AQ_Query.Parameters.ParamByName('betrag').Value := ledPreis.Text;
  AQ_Query.Parameters.ParamByName('waldemar').Value := option[0];
  AQ_Query.Parameters.ParamByName('jonas').Value := option[1];
  AQ_Query.Parameters.ParamByName('ali').Value := option[2];
  AQ_Query.Parameters.ParamByName('ben').Value := option[3];

You can also make a new connection to wgwgwg and refer your AQ_Query to the new connection

Upvotes: 0

da-soft
da-soft

Reputation: 7750

  1. USE and INSERT are two different SQL commands.
  2. MySQL does not support so called "Batches".

=> you have to call these commands one-by-one

Upvotes: 5

Mason Wheeler
Mason Wheeler

Reputation: 84540

Looks to me like you're using backticks on the third AQ_Query.SQL.Add line, when you need to use normal single quotes.

Upvotes: 1

Related Questions