i want make a xdata restserver with al table with fieldnames like
E-Mail
With a firedac mysql syntax
{
"error": {
"code": "MySQLNativeException",
"message": "[FireDAC][Phys][MySQL] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-Mail, A.Internet AS A_Internet, A.Erster_Kontakt AS A_Erster_Kontakt, A.Letztes' at line 1"
}
}
E-Mail is not a valid field name, as it contains a hyphen (which is a minus sign). Quickest way to solve this is simply wrap the field name with quotes or the back tick (MySQL specific):
[Column('"E-Mail"', [], 60)]
or
[Column('`E-Mail`', [], 60)]
Alternatively if you want ao more general approach you can use the OnGetIdName event:
Ah right, sorry about that. Then the approach will be using the OnGetIdName event:
(TSQLGeneratorRegister.GetInstance.GetGenerator('MySQL') as TAnsiSQLGenerator)
.OnGetIdName :=
function(AName: string): string
begin
Result := AName;
if Pos('-', Result) then
Result := '"' + Result + '"';
end;
{
"error": {
"code": "MySQLNativeException",
"message": "[FireDAC][Phys][MySQL] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"E-Mail" AS "A_E-Mail", A.Internet AS A_Internet, A.Erster_Kontakt AS A_Erster_K' at line 1"
}
uses ....
Aurelius.Sql.Register,
Aurelius.Sql.AnsiSqlGenerator,
procedure TServerContainer.DataModuleCreate(Sender: TObject);
begin
(TSQLGeneratorRegister.GetInstance.GetGenerator('MySQL') as TAnsiSQLGenerator)
.OnGetIdName :=
function(AName: string): string
begin
Result := AName;
if Pos('-', Result)>0 then
Result := '"' + Result + '"';
end;
end;```
}