0

I migrated my application from BDE to FIREDac.
A routine that I use to update my database does not work:

SELECT 
  CODIGO , NOME , ENDERECO , ENDERECO1 , COMPLEMENTO , COMPLEMENTO1 ,
  PONTOREFERENCIA , BAIRRO , CIDADE , UF , PAIS , CEP , CX_POSTAL ,
  FONE , FAX , EMAIL , CONTATO , CGC , INSCRICAO , DATA_FICHA , CI ,
  CPF , TIT_ELEITOR , DATA_NASC , SEXO , EST_CIVIL , NATURAL , FILIACAO ,
  PAI , MAE , CONJUGE , NASC_CONJ , ALUGUEL , VAL_ALUGUEL , TEMP_RESID ,
  EMPRESA , FONE_EMPR , ADMISSAO , CEP_EMPR , CIDA_EMPR , UF_EMPR ,
  FUNCAO , TEMP_SERV , REF_COML , REF_BANC , CONS_SPC , OBS , CREDITO ,
  ATRASO , SALARIO , ENDEMPRESA , FOTO , NOMEFANTASIA , CREDITOS ,
  ENDCOBRANCA , RESTRICAO , BAIRRO_EMPR , INATIVO , CONTATO1 , CONTATO2 ,
  CONTATO3 , TAXABOLETO , RESTRICAOANTIGA , NUMERO , IDCIDADE ,
  IDPAISES , CUF
FROM
  Clientes

It gives me an internal error.

Some light ??!

Note: In Time designer, put the direct command in FdQuery and it works normally!bs: In designer Time, input direct comand in FdQuery and

Note2: BD is in Access !!!

As I tried to explain, I would select the data and inserted No target table! The abiaxo routine works for tables with few fields. but in the case of error above it!

The select was only to demonstrate the table where the error occurs! The code:

procedure ConverteTabela(Query: TFDQuery; Alias, Tabela, Campo: string; Tipo: Integer; Senha: string);
var
  Tabela1: TFDTable;
  I: Integer;
  STR:String;
begin
// Tipo = 0 -> Todos os registros da tabela antiga
// Tipo = 1 -> Todos os registros da tabela antiga que não estão na tabela de atualização
// Tipo = 2 -> Todos os registros da tabela antiga que possuem Campo <> 0
// Tipo = 3 -> Apaga os registro da tabela de atualização e coloca os da empresa



  Tabela1 := TFDTable.Create(Application);
  Tabela1.ConnectionName := Query.ConnectionName;
  Tabela1.TableName := Tabela;

  Str:='';

  try
    Tabela1.open;
      for I := 0 to tabela1.Fields.Count-1 do
    begin
    if not (i=tabela1.Fields.Count-1) then
      begin
       Str:= Str + UpperCase(tabela1.Fields[i].FieldName)+ ' , '

      end
    else
       Str:= Str + tabela1.Fields[i].FieldName;
    end;

    Tabela1.Close;
    Tabela1.free;
  except
    exit;
  end;

  Mensagem('Convertendo : ' + Tabela + ' ...');

  if Tipo = 3 then
  begin
    Query.SQL.Clear;
    Query.SQL.Add('DELETE FROM "'+ Alias + '".'+Tabela);
    Query.ExecSQL;
    Tipo := 0;
  end;

  //test Select -
  Query.SQL.Clear;
  Query.SQL.Text := 'Select ' + str + 'from '+Tabela;
  Query.open;

  Query.SQL.Clear;
  Query.SQL.Text:='INSERT INTO "'+ Alias + '".'+tabela+' ('+str+')'+    '  SELECT '+str+' FROM ' + Tabela;

  if (Tipo = 1) then
  begin
    Query.SQL.Add('WHERE ' + Campo + ' NOT IN');
    Query.SQL.Add('(SELECT ' + Campo + ' FROM  "'+ Alias + '".'+tabela+')');
  end
  else if (Tipo = 2) then
  begin
    Query.SQL.Add('WHERE ' + Campo + ' <> 0');
    Query.SQL.Add('AND ' + Campo + ' <> -1');
  end;

 // Query.Prepare;
  try
    Query.ExecSQL;
  except
    showmessage('Erro ao executar comando : ' + Query.Sql.CommaText);
    exit;
  end;
end;
  • 2
    Re-design your schema and you'll be fine. But anyway, I don't think that FireDAC would have a limit for 67 columns (!!!). The problem will be something else, I guess. But without (at least) a detailed desrciption of the error we cannot help. – TLama Mar 24 '15 at 14:31
  • I would guess it is caused by the field name `function` or `natural` – Sir Rufo Mar 24 '15 at 14:34
  • 2
    After a second look I would say `zip code` causes the problem because of the blank inside the field name – Sir Rufo Mar 24 '15 at 15:32
  • Sorry, this original select is this, google translate alter my select – Alisson Marcel Mar 25 '15 at 15:53
  • 2
    There's no UPDATE in your question, only a SELECT. There's also no Delphi code showing how you're using this SELECT (or UPDATE). How do you think we can help? – Ken White Mar 25 '15 at 17:30
  • You are aware of http://community.embarcadero.com/index.php/blogs/entry/firedac-skill-sprint-bde-to-interbase-migration-using-firedac and http://docwiki.embarcadero.com/RADStudio/XE7/en/Migrating_BDE_Applications_to_FireDAC ? – Jan Doggen Mar 26 '15 at 09:34
  • Sorry my questions! i'm new to stack . and I'm learning how to use! And there's the indioma the problem! – Alisson Marcel Mar 26 '15 at 13:34

0 Answers0