试图将应用程序迁移到Delphi 10.2上的FireDAC使用,并且只坚持使用此功能: 来源于github上
procedure TMainForm.ExecuteScript(script: string; memo: TMemo);
var
Log: TStringList;
FN: string;
begin
ShowHourGlassCursor;
ZSQLProcessor.Script.Text := script;
try
ZSQLProcessor.Connection.StartTransaction;
ZSQLProcessor.Execute;
ZSQLProcessor.Connection.Commit;
except
on E:Exception do
begin
ZSQLProcessor.Connection.Rollback;
memo.Text := E.Message;
Exit;
end;
end;
被困在线路上,无法相处,任何帮助都会很好:
ZSQLProcessor.Script.Text := script;
参考: ZSqlProcessor.pas
没有最后一部分的转换函数看起来是这样的:
procedure TMainForm.ExecuteScript(script: string; memo: TMemo);
var
Log: TStringList;
FN: string;
begin
ShowHourGlassCursor;
//ZSQLProcessor.Script.Text := script;
try
MyTrinityConnection.StartTransaction;
FDScript1.ValidateAll;
FDScript1.ExecuteAll;
MyTrinityConnection.Commit;
except
on E:Exception do
begin
MyTrinityConnection.Rollback;
memo.Text := E.Message;
Exit;
end;
end;
要将单个 SQL 脚本分配给 TFDScript对象,只需将一个 TFDSQLScript 项添加到TFDSQLScripts集合,并将其 SQL 字符串列表集合文本设置为您选择的SQL命令,例如:
FDScript1.SQLScripts.Add.SQL.Text := script; { ← this adds one TFDSQLScript item to the script collection and to this just added item assigns a SQL script }
当然,这假设TFDSQLScripts集合是明确的,如果之前没有调用Clear。