Problem is in fact that batch SQL statements parsing is not supported. So if you set SQL.Text to something like:
'declare @id int; select @id=f.ident_field from pokus1 f; select @id;'
(multiple SQL statements)
Then SQLParse does not describe this statement type as stSelect and when you try open such statement you will get above mentioned exception.
I did not do (still) an internal investigation in SQLdb to know how it works, but I understand if we call q.Open the statement type should be stSelect... but I think this isn't not so easy.
Marcos you can also modify sqldb.pp ... look there at procedure TCustomSQLQuery.InternalOpen;
There is :
1396 if FCursor.FStatementType in [stSelect,stExecProcedure] then
Try alter it to:
1396 if FCursor.FStatementType in [stSelect,stExecProcedure,stUnknown] then
(it is not good as general solution, but if you use ONLY TMSSQLConnection then you can work-around it by this way)
or another solution is use hack like this:
as a first line in your batch use something like (comment):
--proc
and then in mssqlconn.pp in function TMSSQLConnection.StrToStatementType(s: string): TStatementType;
add something like:
else if s = '--proc' then
Result:=stExecProcedure
All these solutions are not ideal but can help you to avoid rewriting all queries