summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/sql/sqlRows.cpp18
-rw-r--r--project2/sql/sqlRows.h2
2 files changed, 9 insertions, 11 deletions
diff --git a/project2/sql/sqlRows.cpp b/project2/sql/sqlRows.cpp
index f723269..6570a60 100644
--- a/project2/sql/sqlRows.cpp
+++ b/project2/sql/sqlRows.cpp
@@ -34,16 +34,16 @@ SqlRows::loadComplete(const CommonObjects * co)
SqlRows::SqlState::SqlState(SelectPtr s) :
query(s)
{
+ query->execute();
+ fields.resize(query->columnCount());
+ for (unsigned int c = 0; c < query->columnCount(); c++) {
+ columns.insert(new Column(c, (*query)[c].name));
+ }
}
const Columns &
SqlRows::SqlState::getColumns() const
{
- if (columns.empty()) {
- for (unsigned int c = 0; c < query->columnCount(); c++) {
- columns.insert(new Column(c, (*query)[c].name));
- }
- }
return columns;
}
@@ -51,13 +51,11 @@ void
SqlRows::execute(const Glib::ustring & filter, const RowProcessorCallback & rp, ExecContext * ec) const
{
unsigned int offset = 0;
- SqlState ss(SelectPtr(db->getReadonly().newSelectCommand(sqlCommand.getSqlFor(filter))));
- sqlCommand.bindParams(ec, ss.query.get(), offset);
+ auto select = SelectPtr(db->getReadonly().newSelectCommand(sqlCommand.getSqlFor(filter)));
+ sqlCommand.bindParams(ec, select.get(), offset);
+ SqlState ss(select);
while (ss.query->fetch()) {
HandleAsVariableType h;
- if (ss.fields.empty()) {
- ss.fields.resize(ss.query->columnCount());
- }
for (unsigned int c = 0; c < ss.query->columnCount(); c++) {
const DB::Column & col = (*ss.query)[c];
col.apply(h);
diff --git a/project2/sql/sqlRows.h b/project2/sql/sqlRows.h
index 6f78dcd..46f3972 100644
--- a/project2/sql/sqlRows.h
+++ b/project2/sql/sqlRows.h
@@ -29,7 +29,7 @@ class SqlRows : public RowSet {
SqlState(SelectPtr query);
const Columns & getColumns() const;
SelectPtr query;
- mutable Columns columns;
+ Columns columns;
friend class SqlRows;
};
const RdbmsDataSource * db;