2017-04-27 31 views
0
source:= tabledemap.FieldByName('table source').AsString + '('+ tabledemap.FieldByName('colonne source').AsString+')'; 
    showmessage(source) ; 

源值列:a.name(firsatname) 我想在此列中插入字符串「T」 但我想這個問題使用源變量的值,在這樣如何使用可變的部分到SQL德爾福

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

    FDQuery6.Execute; 

     showmessage('row inserted'); 

一個SQL請求,但該程序無法使用源變量的值的文本,認爲源是一個表,顯示的名稱對我

--------------------------- 
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'. 

我嘗試過「source」,+ source +,但它也不起作用。 如果任何人都可以幫助我在SQL查詢中使用源變量的文本,我將不勝感激。

回答

1

在FireDAC中,您可以使用預處理器宏來表格和字段名稱進行匹配。例如:

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

有關這種宏的信息,請參閱substitution variables話題。