Skip to content

Commit

Permalink
Merge pull request #10 from dstrande/clean-up
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
dstrande authored Aug 21, 2024
2 parents ca3956d + 3739348 commit ea92be0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ class Query : public QObject
};

#endif // PERSON_H

30 changes: 3 additions & 27 deletions src/sqlexplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ sqlExplorer::sqlExplorer(QWidget *parent)
//Initializer the members with values from the ui
queryText = ui->queryEditor->toPlainText();

// //Connect ui components to respective slots
// connect(ui->queryEditor,&QTextEdit::textChanged,
// this,&Widget::weight_changed);
connect(ui->queryButton,&QPushButton::pressed,
this,&sqlExplorer::queryCommand);

Expand All @@ -30,12 +27,7 @@ sqlExplorer::sqlExplorer(QWidget *parent)
queryCommand();
}

// void sqlExplorer::newQuery() // std::string queryText
// {
// queryCommand(queryText);
// }

void sqlExplorer::queryCommand() // std::string queryText
void sqlExplorer::queryCommand()
{
try{
std::string combine = combinedCreds();
Expand All @@ -45,41 +37,25 @@ void sqlExplorer::queryCommand() // std::string queryText
std::cout << "Opened database successfully: " << dbConn.dbname() << std::endl;
pqxx::work txn{dbConn};

// pqxx::result r = txn.exec("SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public';");
// SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public';
queryText = ui->queryEditor->toPlainText();
pqxx::result r = txn.exec(queryText.toStdString());

std::cout << r.columns() << "\n";
std::cout << r.size() << "\n";
// std::cout << typeid(r.columns()).name() << "\n";

model = new QStandardItemModel(r.size(), r.columns());

for (int row = 0; row < model->rowCount(); ++row) {
for (int column = 0; column < model->columnCount(); ++column) {
QStandardItem *item = new QStandardItem(QString(r[row][column].c_str())); // "row %0, column %1").arg(row).arg(column
QStandardItem *item = new QStandardItem(QString(r[row][column].c_str()));
model->setItem(row, column, item);
}
}

ui->resultsView->setModel(model);
ui->resultsView->resizeColumnsToContents();


// std::cout << "Columns:\n";
// for (pqxx::row_size_type col = 0; col < r.columns(); ++col)
// {
// for (int row = 0; row < r.size(); ++row)
// {
// std::cout << col << ", " << row << ": " << r[row][col].c_str() << '\n';
// }
// }

// for (auto row : r[0])
// {
// std::cout << row << "\n";
// }

} else {
std::cout << "Can't open database" << std::endl;
}
Expand Down

0 comments on commit ea92be0

Please sign in to comment.