Hi there!
I got troubles with Query objects I posted before.
Now I think I found the solution that fixes problem and allowed single
Query object processes more than one query (with clearing stream buffer
after each):
file sql_query.h:
typedef enum {
DONT_RESET = 0,
RESET_QUERY
} query_reset;
class SQLQuery
{
...
protected:
void reset();
string str(query_reset r=DONT_RESET);
...
}
file sql_query.cc:
void SQLQuery::reset()
{
seekg(0L, ios::beg);
seekp(0L, ios::beg);
clear();
}
string SQLQuery::str(query_reset r)
{
SQLQuery *ptr = const_cast<SQLQuery *>(this);
*ptr << std::ends;
string str;
switch(r)
{
case RESET_QUERY : {
uint length = (ptr->rdbuf())->pcount() + 1;
char *s = new char[length];
get(s, length, '\0');
str = s;
delete s;
reset();
}
default:
str = ptr->rdbuf()->str();
}
return str;
}
file Query.cc:
Result_NoData Query::execute()
{
query_reset r = RESET_QUERY;
return m_pConnection->execute(str(r));
}
inline Result_Use Query::use()
{
query_reset r = RESET_QUERY;
return m_pConnection->use(str(r));
}
Result_Store Query::store()
{
query_reset r = RESET_QUERY;
return m_pConnection->store(str(r));
}
|