Improved connection error handling.
Just returning a boolean is too limiting. Using expection instead to easily pass on error message.
This commit is contained in:
parent
646b18ebeb
commit
a88af1ac11
5 changed files with 41 additions and 41 deletions
|
|
@ -435,26 +435,23 @@ std::tuple<bool, CrudModel::ModifiedRow> CrudModel::updateRow(const PendingRow &
|
|||
int row_number = pending_row.row();
|
||||
Pgsql::Connection db_update_conn;
|
||||
auto dbconfig = m_database->config();
|
||||
bool res = db_update_conn.connect(dbconfig.getKeywords(), dbconfig.getValues(), false);
|
||||
if (res) {
|
||||
auto result = db_update_conn.queryParam(buffer, params);
|
||||
if (result && result.rows() == 1) {
|
||||
db_update_conn.connect(dbconfig.getKeywords(), dbconfig.getValues(), false);
|
||||
auto result = db_update_conn.queryParam(buffer, params);
|
||||
if (result && result.rows() == 1) {
|
||||
|
||||
std::vector<Value> values;
|
||||
auto row = *result.begin();
|
||||
for (auto v : row) {
|
||||
if (v.null())
|
||||
values.push_back(Value());
|
||||
else
|
||||
values.push_back(std::string(v.c_str()));
|
||||
}
|
||||
|
||||
ModifiedRow modified_row(row_number, values);
|
||||
|
||||
return { true, modified_row };
|
||||
std::vector<Value> values;
|
||||
auto row = *result.begin();
|
||||
for (auto v : row) {
|
||||
if (v.null())
|
||||
values.push_back(Value());
|
||||
else
|
||||
values.push_back(std::string(v.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
ModifiedRow modified_row(row_number, values);
|
||||
|
||||
return { true, modified_row };
|
||||
}
|
||||
}
|
||||
return { false, {} };
|
||||
}
|
||||
|
|
@ -527,10 +524,7 @@ std::tuple<bool, QString> CrudModel::removeRows(const std::set<IntegerRange<int>
|
|||
try {
|
||||
Pgsql::Connection db_update_conn;
|
||||
auto dbconfig = m_database->config();
|
||||
bool res = db_update_conn.connect(dbconfig.getKeywords(), dbconfig.getValues(), false);
|
||||
if (!res) {
|
||||
return { false, "Cannot connect to the database" };
|
||||
}
|
||||
db_update_conn.connect(dbconfig.getKeywords(), dbconfig.getValues(), false);
|
||||
|
||||
// First delete rows in table
|
||||
QString delete_statement = createDeleteStatement();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue