1
source:= tabledemap.FieldByName('table source').AsString + '('+ tabledemap.FieldByName('colonne source').AsString+')';
  showmessage(source)  ;

The source value is the column: a.name (firsatname) I want to insert in this column the string 't' But the problem I want to use the value of the source variable in a sql request like this

 FDQuery6.SQL.Add ('INSERT INTO  source  Values ( "t" ) ');

     FDQuery6.Execute;

      showmessage('row inserted');

But the program fails to use the text of the value of the source variable and think that source is a name of a table and displays to me

---------------------------
Notification des exceptions du débogueur
---------------------------
Le projet x a déclenché la classe d'exception EMySQLNativeException avec le message '[FireDAC][Phys][MySQL] Table 'a.source' doesn't exist'.

I have tried "source" , +source+ but it won't work also . If anyone can help me to use the text of the source variable in the SQL query I will be grateful.

1 Answer 1

3

In FireDAC you can paremetrize table and field names by using preprocessor macros. For example:

FDQuery.SQL.Text := 'INSERT INTO &TableName (&FieldName) VALUES "ConstValue"';
FDQuery.MacroByName('TableName').AsIdentifier := 'MyTable';
FDQuery.MacroByName('FieldName').AsIdentifier := 'MyField';
FDQuery.ExecSQL;

For details about this kind of macros, see the substitution variables topic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.