我试图在FireDAC中使用宏来预处理我的SQL查询.我在数据模块上有一个TADQuery对象,其sql设置如下:
Select * from MyTable join OtherTable on MyTable.Key = OtherTable.Key &Where
然后在我的代码中我这样做:
WhereClause = 'stuff based on my form'; Query.MacroByName('Where').AsRaw := WhereClause; Query.Open;
这对于复杂的查询非常有用,因为它允许我使用sql属性编辑器确保我的字段和连接条件是正确的.
我的问题是由于我的where子句导致sql语句失效.有没有办法在预处理之后看到要执行的sql?现在我正在捕获FireDac错误并显示EADDBEngineException对象上的sql.但是仍然显示我的原始sql与宏.如果我在错误发生后无法访问它,那么无论如何都要强制进行宏替换,这样我就可以查看调试器中的sql来帮助我查看错误.
解决方法
(只是从未回答的问题列表中删除此问题)
来自评论:
Well,I’ve roughly checked what’s happening there and I’m still not
sure if calling Prepare (which is useless for you as I get) is the
minimal requirement to trigger that preprocessing. Though,the
preprocessed sql,the one which is sent to the DBMS you can access
through the Text property (quite uncommon name for such property). – TLama Feb 21 ’14 at 8:18