问题
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