|
From: Simon W. <si...@gi...> - 2012-04-30 03:09:26
|
Hi Pete,
Thank you very much for the detailed example. I've taken a look at how
you've done it and the only difference I can see is that I was using
odbc::PreparedStatement.
> I'm not sure what you mean by:
>
>> I can use the same odbc::DriverManager that I used with the
>> first query but not odbc::Connection or odbc::PreparedStatement.
Regarding recycling the objects and connection. I could not reuse the
connection. As you say, reusing the statement is pointless. So I'll
forget about doing that.
So I must be doing something incorrectly with PreparedStatment. Perhaps
there is some kind of initialization or cleanup required when using
PreparedStatment? I cannot reuse the connection after using executing a
PreparedStatment. I don't get any results back.
// For example:
odbc::Connection *connection =
odbc::DriverManager::getConnection(dbConnectString);
std::stringstream query;
query << "select ...";
odbc::PreparedStatement *statement =
connection->prepareStatement(query.str());
statement->execute();
query.str("");
query << "select ...";
odbc::PreparedStatement *statement2 =
connection->prepareStatement(query.str());
statement2->execute();
delete connection;
delete statement;
delete statement2;
// end
The statement2 has no results. Though I can see the statement reaching
the DB by using MS SQL Server Profiler. I wonder if I should be
resetting the connection or something similar when using prepared
statements and callable statements.
In any case, at least regular statements work with successive calls. I'm
curious about callable and prepared statements as I use callable for
stored procedures and imagine I'll have use cases for prepared statements.
Many thanks for your help,
Simon
--
simonsmicrophone.com
|