#include "KM3NeTDBResultSet.h" #include #define FIELD_SEPARATOR '\t' _StreamDSResultSet::_StreamDSResultSet(_Client *client) { _client = client; _scanbuf = 0; _bytes = _client->_GetBytes(_scanbuf); if (_ReadLine() == false) throw DBException("Cannot get resultset columns.", __LINE__); _BreakLineIntoStrings(_Fields); } void _StreamDSResultSet::_BreakLineIntoStrings(std::vector &outvect) { outvect.clear(); std::string line = _oss.str(); int len = line.length(); std::ostringstream fss; for (int i = 0; i < len; i++) { char ch = line[i]; if (ch == FIELD_SEPARATOR) { outvect.push_back(fss.str()); fss.clear(); fss.str(""); } else if (ch >= ' ') { fss << ch; } } outvect.push_back(fss.str()); } void _StreamDSResultSet::Close() { _client->_ResultSetClose(); } bool _StreamDSResultSet::_ReadLine() { char ch; _oss.clear(); _oss.str(""); do { while (_bytes > 0) { ch = *_scanbuf++; _bytes--; if (ch != '\r' && ch != '\n') _oss << ch; else { if (ch == '\n') return true; } } _bytes = _client->_GetBytes(_scanbuf); } while (_bytes > 0); if (_oss.str().length() > 0) return true; return false; } bool _StreamDSResultSet::Next() { _oss.clear(); _oss.str(""); if (_ReadLine() == false) return false; _BreakLineIntoStrings(_Values); return true; }