Firedac: GetFieldNames without quotation marks

Posted on

Question :

I’m retrieving the Firebird and Mysql tables by Firedac Connection through the command line GetFieldNames , however some fields in the list are returned with quotation marks.

I have tried to insert the MetaDefCatalog=MySql directive into the parameters and it did not solve anything.

Below is the code I use to fetch the list of fields from a table:

if Lista.IndexOf('Campo') > 0 then
   //comandos para criar campo na tabela

The problem is that when the field is quoted by Firedac ( DBExpress did not do this) the if clause asks to create the field that already exists and generates an error. / p>

How do I resolve this?

Thank you !!!


Answer :

Fields are returned with quotation marks because of database normalization.
Here’s a little different approach: Documentation.


AList is a TStrings descendant that receives the field names. Any
  existing strings are deleted from the list before GetFieldNames adds
  the names of all the fields in ATableName.


The field names are normalized – enclosed in quotation marks, if that
  is required – otherwise converted to default dictionary case.

There are several functions that remove the unwanted characters, this can help you, after getting the names and before inserting in the list, pass the result by the function:

function RemoveEspeciais(Texto: Ttring): Ttring; stdcall;
{Função que serve para nao aceitar caracteres especiais tipo !@#$%^&*()}
  NaoChar = '~'!@#$%^&*()_-+=|<>,.?/æ';
  i: Integer;
  for i := 1 to Length(Texto) do
    if Pos(Texto[i], NaoChar) <> 0 then
    Result := Result + Texto[i];

If you can not add the single quote, add in the function constant the # 39 that is the same!


Changing the approach, now knowing that the project is great!

Declare in the uses of your project: FireDAC.VCLUI.Wait

procedure TfrmPrincipal.btnTesteClick(Sender: TObject);
  vNomeCampos : TStringList;
  vNomeCampos := TStringList.Create;
  FDConnection.GetFieldNames('','','nome_tabela','',vNomeCampos);//nome_tabela entre Aspas!


Dude I have a data migration system developed and I use getfildName to pick up the fields from a given dump as follows.


And from what I have already used the system he never picked up or FireDac put quotes.
but try the following test
the indexof I searched for is what index to match the string and it returns a value of type int. But the string list starts at 0 and goes to the end, maybe your field is at position 0, and you are validating if it is greater than 0.
If so, put a xyz field to see the return, I think it will be -1.

I hope to have helped


Leave a Reply

Your email address will not be published. Required fields are marked *