Poco ODBC and while SQL loop

我们两清 提交于 2019-12-11 13:11:25

问题


i'm working with mssql odbc C++ code :

Session session("ODBC", connectionString);

Statement select(session);  

select << sql;  
select.execute();    
Poco::Data::RecordSet rs(select);   
bool more = rs.moveFirst();    
std::size_t cols = rs.columnCount();    
std::stringstream ss;
ss << "<table>";
while (more)
{
    ss << "<row>";
    for (std::size_t col = 0; col < cols; ++col)
    {
        std::string cn = rs.columnName (col);
        ss << "<" << cn << ">";
        ss << rs[col].convert<std::string>();
        ss << "</" << cn << ">";
    }
    ss << "</row>";
    more = rs.moveNext();
}
ss << "</table>";

all working fine, but if i trying sql loop, for example :

DECLARE @database_name sysname ;
SET @database_name = NULL; 
WHILE @database_name IS NOT NULL 
BEGIN
SET @database_name = NULL; 
END;
SELECT '0'

then i have error in line : bool more = rs.moveFirst();
Assertion violation: extractions().size() in file "C:\External\poco\include\Poco/Data/RecordSet.h", line 241 without while loop in sql all working, in MSSQL server management studio all working, and in ODBC query tool it not problem, but it not working with poco. any suggestions ?


回答1:


You are executing an anonymous block of code; if you have to do it like that, you'll have to turn it into a named stored procedure.

See ODBCSQLServerTest::testCursorStoredProcedure() for an example on how to do it for SQL Server ODBC.

Note: you will need a POCO version higher than 1.5.0.



来源:https://stackoverflow.com/questions/17315908/poco-odbc-and-while-sql-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!