用FDQuery执行创建临时表,查不到临时表,用ADOQuery和BDEQuery均正常,比较发现用ADOQuery执行的时候只有SQL没有调用sql的系统存储过程sp_prepexec.
是fdquery哪里设置的问题吗,用FDConnection->ExecSQL("sql");是可以查到临时表不调用系统存储过程sp_prepexec但是不能获得影响的行数,
set @p1=NULL 改为NULL创建的临时表可以查到,但是如何才能设置到NULL。
declare @p1 int set @p1=1 exec sp_prepexec @p1 output,NULL,N'select top 50 * into #ls from myTable' select @p1 go
-------------------- exec sp_unprepare 1 go exec [adb].[sys].sp_pkeys N'#ls',N'dbo',N'adb' go declare @p1 int set @p1=NULL exec sp_prepexec @p1 output,NULL,N'select top 50 * from #ls ' select @p1 go
FDConnection.ResourceOptions.DirectExecute := True;
或者
dm->FDConnection1->ExecSQL(sql);
这样就解决了!!
qry->ResourceOptions->DirectExecute=true;
http://docs.embarcadero.com/products/rad_studio/firedac/frames.html?frmname=topic&frmfile=uADCompClient_TADRdbmsDataSet_ResourceOptions.html
对sql server有啥执行效果的区别,没有说明
Use DirectExecute property to specify should FireDAC prepare SQL statement before execution (False) or execute it directly (True). The default value is False.
This property was introduced at first for MS SQL Server support. Where prepared and direct execution may have different effects. Or even prepared execution may fail. If you will get "strange" errors, then try to set DirectExecute to True.
还有一个办法,
exec sp_executesql N'select * into #ls from mytable'
select * from #ls
这样是访问不到临时表的,可以在命令前先create talbe #ls(a int)...
这个就是先创建临时表,得知道有哪些字段。