void GLECSVData::print(ostream& os) { vector<unsigned int> columnWidth; for (unsigned int row = 0; row < getNbLines(); row++) { unsigned int nbColumns = getNbColumns(row); for (unsigned int col = 0; col < nbColumns; col++) { unsigned int size; const char* cell = getCell(row, col, &size); unsigned int chars = getUTF8NumberOfChars(cell, size); while (columnWidth.size() <= col) { columnWidth.push_back(0); } columnWidth[col] = std::max<unsigned int>(columnWidth[col], chars + 1); } } for (unsigned int row = 0; row < getNbLines(); row++) { unsigned int nbColumns = getNbColumns(row); for (unsigned int col = 0; col < nbColumns; col++) { unsigned int size; const char* cell = getCell(row, col, &size); unsigned int chars = getUTF8NumberOfChars(cell, size); for (unsigned int idx = 0; idx < size; idx++) { os << cell[idx]; } if (col != nbColumns - 1) { os << ","; for (unsigned int idx = chars; idx < columnWidth[col]; idx++) { os << (char)' '; } } } os << endl; } }
int DBResult::getColumnIndex (const std::string& columnName) const { for (int i=0; i<getNbColumns (); ++i) { if (getColumnName (i) == columnName) return i; } return -1; }
Record::FieldNames DBResult::getFieldNames() const { FieldNames result; size_t nbcol(getNbColumns()); for(size_t icol(0); icol<nbcol; ++icol) { result.push_back(getColumnName(icol)); } return result; }
unsigned int GLECSVData::validateIdenticalNumberOfColumns() { bool found = false; unsigned int dataColumns = 0; for (unsigned int row = 0; row < getNbLines(); ++row) { if (!found) { found = true; dataColumns = getNbColumns(row); } else { if (m_error.errorCode == GLECSVErrorNone && getNbColumns(row) != dataColumns) { m_error.errorCode = GLECSVErrorInconsistentNrColumns; m_error.errorLine = row; m_error.errorColumn = 0; ostringstream err; err << "inconsistent number of columns " << getNbColumns(row) << " <> " << dataColumns; createErrorString(err.str()); return dataColumns; } } } return dataColumns; }
std::vector<int> DBResult::computeMaxColWidths () const { std::vector<int> widths; for (int c=0; c<getNbColumns (); ++c) { size_t max = 0; std::string name (getColumnName (c)); if (name.length () > max) max = name.length (); while (next()) { std::string value (getText (c)); if (value.length () > max) max = value.length (); } reset(); widths.push_back (max); } return widths; }