Commit 24350bba authored by Murray Cumming's avatar Murray Cumming
Browse files

Fix the build with -Wshadow.

This seems useful. It can catch real errors.
parent bf982f53
......@@ -1068,16 +1068,16 @@ bool AppWindow::on_document_load()
//connection_request_password_and_choose_new_database_name() has already change the database name to a new unused one:
bool user_cancelled = false;
bool test = false;
bool recreated = false;
if(is_example)
test = recreate_database_from_example(user_cancelled);
recreated = recreate_database_from_example(user_cancelled);
else
{
test = recreate_database_from_backup(m_backup_data_filepath, user_cancelled);
recreated = recreate_database_from_backup(m_backup_data_filepath, user_cancelled);
m_backup_data_filepath.clear();
}
if(!test)
if(!recreated)
{
// TODO: Do we need to call connection_pool->cleanup() here, for
// stopping self-hosted databases? armin.
......@@ -1372,8 +1372,6 @@ void AppWindow::existing_or_new_new()
//Each document must have a location, so ask the user for one.
//This will use an extended save dialog that also asks for the database title and some hosting details:
Glib::ustring db_title;
m_ui_save_extra_showextras = true; //Offer self-hosting or central hosting, and offer the database title.
m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT; /* Default to self-hosting */
m_ui_save_extra_newdb_title.clear();
......@@ -2026,13 +2024,13 @@ void AppWindow::fill_menu_print_layouts(const Glib::ustring& table_name)
#ifndef GLOM_ENABLE_CLIENT_ONLY
for(const auto& item : tables)
{
std::shared_ptr<PrintLayout> print_layout = document->get_print_layout(table_name, item);
if(print_layout)
std::shared_ptr<PrintLayout> layout = document->get_print_layout(table_name, item);
if(layout)
{
const auto name = print_layout->get_name();
const auto name = layout->get_name();
if(!name.empty())
{
const auto title = Utils::string_escape_underscores(item_get_title(print_layout));
const auto title = Utils::string_escape_underscores(item_get_title(layout));
const Glib::ustring action_name = name;
menu->append(title, ACTION_GROUP_NAME_PRINT_LAYOUTS + "." + action_name);
......
......@@ -832,15 +832,15 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
iterFind = m_FieldsCalculationInProgress.find(field_name); //Always succeeds.
}
CalcInProgress& refCalcProgress = iterFind->second;
CalcInProgress& calc_progress = iterFind->second;
//Use the previously-calculated value if possible:
if(refCalcProgress.m_calc_in_progress)
if(calc_progress.m_calc_in_progress)
{
//std::cerr << G_STRFUNC << ": Circular calculation detected. field_name=" << field_name << std::endl;
//refCalcProgress.m_value = Conversions::get_empty_value(field->get_glom_type()); //Give up.
}
else if(refCalcProgress.m_calc_finished)
else if(calc_progress.m_calc_finished)
{
//std::cerr << G_STRFUNC << ": Already calculated." << std::endl;
......@@ -850,10 +850,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
{
//std::cerr << G_STRFUNC << ": setting calc_in_progress: field_name=" << field_name << std::endl;
refCalcProgress.m_calc_in_progress = true; //Let the recursive calls to calculate_field() check this.
std::shared_ptr<LayoutItem_Field> layout_item = std::make_shared<LayoutItem_Field>();
layout_item->set_full_field_details(refCalcProgress.m_field);
calc_progress.m_calc_in_progress = true; //Let the recursive calls to calculate_field() check this.
//Calculate dependencies first:
//TODO: Prevent unncessary recalculations?
......@@ -888,10 +885,10 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
//m_FieldsCalculationInProgress has changed, probably invalidating our iter, so get it again:
iterFind = m_FieldsCalculationInProgress.find(field_name); //Always succeeds.
CalcInProgress& refCalcProgress = iterFind->second;
CalcInProgress& calc_progress_refreshed = iterFind->second;
//Check again, because the value miight have been calculated during the dependencies.
if(refCalcProgress.m_calc_finished)
//Check again, because the value might have been calculated during the dependencies.
if(calc_progress_refreshed.m_calc_finished)
{
//We recently calculated this value, and set it in the database and layout, so don't waste time doing it again:
}
......@@ -902,7 +899,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
const auto field_values = get_record_field_values_for_calculation(field_in_record.m_table_name, field_in_record.m_key, field_in_record.m_key_value);
if(!field_values.empty())
{
std::shared_ptr<const Field> field = refCalcProgress.m_field;
std::shared_ptr<const Field> field = calc_progress_refreshed.m_field;
if(field)
{
//We need the connection when we run the script, so that the script may use it.
......@@ -911,7 +908,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
g_assert(sharedconnection);
Glib::ustring error_message; //TODO: Check this.
refCalcProgress.m_value =
calc_progress_refreshed.m_value =
glom_evaluate_python_function_implementation(field->get_glom_type(),
field->get_calculation(),
field_values,
......@@ -921,14 +918,14 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
sharedconnection->get_gda_connection(),
error_message);
refCalcProgress.m_calc_finished = true;
refCalcProgress.m_calc_in_progress = false;
calc_progress_refreshed.m_calc_finished = true;
calc_progress_refreshed.m_calc_in_progress = false;
std::shared_ptr<LayoutItem_Field> layout_item = std::make_shared<LayoutItem_Field>();
layout_item->set_full_field_details(field);
//show it:
set_entered_field_data(layout_item, refCalcProgress.m_value ); //TODO: If this record is shown.
set_entered_field_data(layout_item, calc_progress_refreshed.m_value ); //TODO: If this record is shown.
//Add it to the database (even if it is not shown in the view)
//Using true for the last parameter means we use existing calculations where possible,
......@@ -938,7 +935,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
{
LayoutFieldInRecord field_in_record_layout(layout_item, field_in_record.m_table_name /* parent */, field_in_record.m_key, field_in_record.m_key_value);
set_field_value_in_database(field_in_record_layout, refCalcProgress.m_value, true); //This triggers other recalculations/lookups.
set_field_value_in_database(field_in_record_layout, calc_progress_refreshed.m_value, true); //This triggers other recalculations/lookups.
}
}
}
......
......@@ -153,11 +153,11 @@ protected:
{
if(layout_item->get_has_related_relationship_name()) //For doubly-related fields
{
std::shared_ptr<const Relationship> rel = layout_item->get_related_relationship();
if(rel)
std::shared_ptr<const Relationship> related_rel = layout_item->get_related_relationship();
if(related_rel)
{
//Actually a foreign key in a doubly-related table:
m_key = document.get_field(m_table_name, rel->get_to_field());
m_key = document.get_field(m_table_name, related_rel->get_to_field());
}
}
else
......
......@@ -295,11 +295,10 @@ bool Base_DB_Table_Data::add_related_record_for_field(const std::shared_ptr<cons
//Generate the new key value;
}
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_INSERT);
builder->set_table(relationship->get_to_table());
builder->add_field_value(primary_key_field->get_name(), primary_key_value);
const auto test = DbUtils::query_execute(builder);
if(!test)
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder_insert = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_INSERT);
builder_insert->set_table(relationship->get_to_table());
builder_insert->add_field_value(primary_key_field->get_name(), primary_key_value);
if(!DbUtils::query_execute(builder_insert))
{
std::cerr << G_STRFUNC << ": INSERT failed." << std::endl;
return false;
......@@ -341,17 +340,16 @@ bool Base_DB_Table_Data::add_related_record_for_field(const std::shared_ptr<cons
else
{
const auto target_table = relationship->get_from_table();
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder_update =
Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builder->set_table(target_table);
builder->add_field_value_as_value(relationship->get_from_field(), primary_key_value);
builder->set_where(
builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id(parent_primary_key_field->get_name(), target_table),
builder->add_expr(parent_primary_key_value)) );
const auto test = DbUtils::query_execute(builder);
if(!test)
builder_update->set_table(target_table);
builder_update->add_field_value_as_value(relationship->get_from_field(), primary_key_value);
builder_update->set_where(
builder_update->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder_update->add_field_id(parent_primary_key_field->get_name(), target_table),
builder_update->add_expr(parent_primary_key_value)) );
if(!DbUtils::query_execute(builder_update))
{
std::cerr << G_STRFUNC << ": UPDATE failed." << std::endl;
return false;
......
......@@ -1202,7 +1202,6 @@ void Frame_Glom::on_dialog_add_related_table_response(int response)
on_dialog_tables_hide(); //Update the menu.
Gtk::Window* parent = get_app_window();
if(parent)
show_ok_dialog(_("Related Table Created"), _("The new related table has been created."), *parent, Gtk::MESSAGE_INFO);
}
......@@ -2567,6 +2566,20 @@ void Frame_Glom::on_notebook_data_record_selection_changed()
pApp->enable_menu_print_layouts_details(something_selected);
}
namespace {
static Glib::ustring ulong_as_string(gulong value)
{
Glib::ustring result;
std::stringstream the_stream;
//the_stream.imbue( current_locale );
the_stream << value;
the_stream >> result;
return result;
}
} //anonymous namespace
gulong Frame_Glom::update_records_count()
{
//Get the number of records available and the number found,
......@@ -2578,11 +2591,7 @@ gulong Frame_Glom::update_records_count()
//std::cout << G_STRFUNC << ": count_all=" << count_all << ", count_found=" << count_found << std::endl;
std::string str_count_all, str_count_found;
std::stringstream the_stream;
//the_stream.imbue( current_locale );
the_stream << count_all;
the_stream >> str_count_all;
str_count_all = ulong_as_string(count_all);
if(count_found == count_all)
{
......@@ -2595,9 +2604,7 @@ gulong Frame_Glom::update_records_count()
}
else
{
std::stringstream the_stream; //Reusing the existing stream seems to produce an empty string.
the_stream << count_found;
the_stream >> str_count_found;
str_count_found = ulong_as_string(count_found);
m_Button_FindAll.show();
}
......
......@@ -196,8 +196,8 @@ void Dialog_Import_CSV::import(const Glib::ustring& uri, const Glib::ustring& in
m_target_table->set_markup("<b>" + Glib::Markup::escape_text(into_table) + "</b>");
m_field_model = Gtk::ListStore::create(m_field_columns);
auto tree_iter = m_field_model->append();
(*tree_iter)[m_field_columns.m_col_field_name] = _("<None>");
auto tree_iter_none = m_field_model->append();
(*tree_iter_none)[m_field_columns.m_col_field_name] = _("<None>");
const Document::type_vec_fields fields(document->get_table_fields(into_table));
for (const auto& field : fields)
......@@ -659,14 +659,14 @@ void Dialog_Import_CSV::on_field_edited(const Glib::ustring& path, const Glib::u
// Update the rows, so they are redrawn, doing a conversion to the new type.
const auto sample_children = m_sample_model->children();
// Create a TreeModel::Path with initial index 0. We need a TreeModel::Path for the row_changed() call
Gtk::TreeModel::Path path("0");
Gtk::TreeModel::Path path_changed("0");
for(auto sample_iter = sample_children.begin(); sample_iter != sample_children.end(); ++ sample_iter)
{
if(sample_iter != iter)
m_sample_model->row_changed(path, sample_iter);
m_sample_model->row_changed(path_changed, sample_iter);
path.next();
path_changed.next();
}
validate_primary_key();
......
......@@ -87,7 +87,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQL::attempt_connect(const Glib::ustring&
const Glib::ustring cnc_string_main = "HOST=" + DbUtils::gda_cnc_string_encode(m_host)
+ ";PORT=" + DbUtils::gda_cnc_string_encode(port)
+ ";PROTOCOL=TCP"; //PROTOCOL is in libgda >= 5.1.2.
const auto cnc_string = cnc_string_main +";DB_NAME=" + DbUtils::gda_cnc_string_encode(database);
const auto cnc_string_with_db = cnc_string_main +";DB_NAME=" + DbUtils::gda_cnc_string_encode(database);
Glib::RefPtr<Gnome::Gda::Connection> connection;
Glib::RefPtr<Gnome::Gda::DataModel> data_model;
......@@ -96,7 +96,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQL::attempt_connect(const Glib::ustring&
#ifdef GLOM_CONNECTION_DEBUG
std::cout << std::endl << "DEBUG: Glom: trying to connect on port=" << port << std::endl;
std::cout << "debug: " << G_STRFUNC << ": cnc_string=" << cnc_string << std::endl;
std::cout << "debug: " << G_STRFUNC << ": cnc_string=" << cnc_string_with_db << std::endl;
std::cout << " DEBUG: auth_string=" << auth_string << std::endl;
#endif
......@@ -105,13 +105,13 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQL::attempt_connect(const Glib::ustring&
if(fake_connection)
{
connection = Gnome::Gda::Connection::create_from_string("MySQL",
cnc_string, auth_string,
cnc_string_with_db, auth_string,
Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
}
else
{
connection = Gnome::Gda::Connection::open_from_string("MySQL",
cnc_string, auth_string,
cnc_string_with_db, auth_string,
Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
//connection->statement_execute_non_select("SET DATESTYLE = 'ISO'");
......@@ -125,13 +125,13 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQL::attempt_connect(const Glib::ustring&
std::cout << "debug: " << G_STRFUNC << ": Attempting to connect without specifying the database." << std::endl;
#endif
const auto cnc_string = cnc_string_main + ";DB_NAME=" + DbUtils::gda_cnc_string_encode(default_database);
const auto cnc_string_without_db = cnc_string_main + ";DB_NAME=" + DbUtils::gda_cnc_string_encode(default_database);
Glib::RefPtr<Gnome::Gda::Connection> temp_conn;
auto auth_string = create_auth_string(username, password);
//auto auth_string = create_auth_string(username, password);
try
{
temp_conn = Gnome::Gda::Connection::open_from_string("MySQL",
cnc_string, auth_string,
cnc_string_without_db, auth_string,
Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
}
catch(const Glib::Error& /* ex */)
......@@ -394,9 +394,9 @@ bool MySQL::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connectio
{
connection->rollback_transaction(TRANSACTION_NAME);
}
catch(const Glib::Error& ex)
catch(const Glib::Error& ex_rollback)
{
std::cerr << G_STRFUNC << "Could not rollback the transaction: Exception: " << ex.what() << std::endl;
std::cerr << G_STRFUNC << "Could not rollback the transaction: Exception: " << ex_rollback.what() << std::endl;
}
}
......
......@@ -362,9 +362,7 @@ Backend::StartupErrors MySQLSelfHosted::startup(const SlotProgress& slot_progres
const std::string second_command_success_text = "mysqld is alive"; //TODO: This is not a stable API. Also, watch out for localisation.
//std::cout << G_STRFUNC << ": debug: command_check_mysql_has_started=" << command_check_mysql_has_started << std::endl;
const auto result = Glom::Spawn::execute_command_line_and_wait_until_second_command_returns_success(command_mysql_start, command_check_mysql_has_started, slot_progress, second_command_success_text);
if(!result)
if(!Glom::Spawn::execute_command_line_and_wait_until_second_command_returns_success(command_mysql_start, command_check_mysql_has_started, slot_progress, second_command_success_text))
{
m_port = 0;
......@@ -388,9 +386,7 @@ Backend::StartupErrors MySQLSelfHosted::startup(const SlotProgress& slot_progres
+ " password " + Glib::shell_quote(m_initial_password_to_set);
//std::cout << "debug: command_initdb_set_initial_password=" << command_initdb_set_initial_password << std::endl;
const auto result = Glom::Spawn::execute_command_line_and_wait(command_initdb_set_initial_password, slot_progress);
if(!result)
if(!Glom::Spawn::execute_command_line_and_wait(command_initdb_set_initial_password, slot_progress))
{
std::cerr << G_STRFUNC << ": Error while attempting to start self-hosting MySQL database, when setting the initial password." << std::endl;
return STARTUPERROR_FAILED_UNKNOWN_REASON;
......@@ -550,8 +546,7 @@ bool MySQLSelfHosted::cleanup(const SlotProgress& slot_progress)
//I've seen it fail when running under valgrind, and there are reports of failures in bug #420962.
//Maybe it will help to try again:
const auto result = Glom::Spawn::execute_command_line_and_wait(command_mysql_stop, slot_progress);
if(!result)
if(!Glom::Spawn::execute_command_line_and_wait(command_mysql_stop, slot_progress))
{
std::cerr << G_STRFUNC << ": Error while attempting (for a second time) to stop self-hosting of the database." << std::endl;
return false;
......
......@@ -112,13 +112,13 @@ Glib::RefPtr<Gnome::Gda::Connection> Postgres::attempt_connect(const Glib::ustri
std::cout << "debug: " << G_STRFUNC << ": Attempting to connect without specifying the database." << std::endl;
#endif
const auto cnc_string = cnc_string_main + ";DB_NAME=" + DbUtils::gda_cnc_string_encode(default_database);
const auto cnc_string_with_db = cnc_string_main + ";DB_NAME=" + DbUtils::gda_cnc_string_encode(default_database);
Glib::RefPtr<Gnome::Gda::Connection> temp_conn;
auto auth_string = create_auth_string(username, password);
//auto auth_string = create_auth_string(username, password);
try
{
temp_conn = Gnome::Gda::Connection::open_from_string("PostgreSQL",
cnc_string, auth_string,
cnc_string_with_db, auth_string,
Gnome::Gda::CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
}
catch(const Glib::Error& /* ex */)
......@@ -379,9 +379,9 @@ bool Postgres::change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connec
{
connection->rollback_transaction(TRANSACTION_NAME);
}
catch(const Glib::Error& ex)
catch(const Glib::Error& ex_rollback)
{
std::cerr << G_STRFUNC << ": Could not rollback the transaction: Exception: " << ex.what() << std::endl;
std::cerr << G_STRFUNC << ": Could not rollback the transaction: Exception: " << ex_rollback.what() << std::endl;
}
}
......
......@@ -493,8 +493,7 @@ bool PostgresSelfHosted::cleanup(const SlotProgress& slot_progress)
// Make sure to use double quotes for the executable path, because the
// CreateProcess() API used on Windows does not support single quotes.
const auto command_postgres_stop = get_path_to_postgres_executable("pg_ctl") + " -D " + Glib::shell_quote(dbdir_data) + " stop -m fast";
const auto result = Glom::Spawn::execute_command_line_and_wait(command_postgres_stop, slot_progress);
if(!result)
if(!Glom::Spawn::execute_command_line_and_wait(command_postgres_stop, slot_progress))
{
std::cerr << G_STRFUNC << ": Error while attempting to stop self-hosting of the database. Trying again." << std::endl;
......@@ -510,8 +509,7 @@ bool PostgresSelfHosted::cleanup(const SlotProgress& slot_progress)
//I've seen it fail when running under valgrind, and there are reports of failures in bug #420962.
//Maybe it will help to try again:
const auto result = Glom::Spawn::execute_command_line_and_wait(command_postgres_stop, slot_progress);
if(!result)
if(!Glom::Spawn::execute_command_line_and_wait(command_postgres_stop, slot_progress))
{
std::cerr << G_STRFUNC << ": Error while attempting (for a second time) to stop self-hosting of the database." << std::endl;
return false;
......
......@@ -369,9 +369,9 @@ bool Sqlite::recreate_table(const Glib::RefPtr<Gnome::Gda::Connection>& connecti
{
connection->rollback_transaction(TRANSACTION_NAME);
}
catch(const Glib::Error& ex)
catch(const Glib::Error& ex_rollback)
{
std::cerr << G_STRFUNC << ": Could not revert the transaction. exception=" << ex.what() << std::endl;
std::cerr << G_STRFUNC << ": Could not revert the transaction. exception=" << ex_rollback.what() << std::endl;
}
}
......
......@@ -483,25 +483,23 @@ bool add_standard_tables(const Document* document)
if(test)
{
//Add the single record:
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_INSERT);
builder->set_table(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME);
builder->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, 1);
const auto test = query_execute(builder);
if(!test)
Glib::RefPtr<Gnome::Gda::SqlBuilder> builderAdd = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_INSERT);
builderAdd->set_table(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME);
builderAdd->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, 1);
if(!query_execute(builderAdd))
std::cerr << G_STRFUNC << ": INSERT failed." << std::endl;
//Use the database title from the document, if there is one:
const auto system_name = document->get_database_title_original();
if(!system_name.empty())
{
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builder->set_table(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME);
builder->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_NAME, system_name);
builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, GLOM_STANDARD_TABLE_PREFS_TABLE_NAME),
builder->add_expr(1)));
const auto test = query_execute(builder);
if(!test)
Glib::RefPtr<Gnome::Gda::SqlBuilder> builderUpdate = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builderUpdate->set_table(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME);
builderUpdate->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_NAME, system_name);
builderUpdate->set_where(builderAdd->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builderAdd->add_field_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, GLOM_STANDARD_TABLE_PREFS_TABLE_NAME),
builderAdd->add_expr(1)));
if(!query_execute(builderUpdate))
std::cerr << G_STRFUNC << ": UPDATE failed." << std::endl;
}
}
......@@ -2156,8 +2154,7 @@ bool add_user(const Document* document, const Glib::ustring& user, const Glib::u
{
const auto table_name = table->get_name();
const Glib::ustring strQuery = "REVOKE ALL PRIVILEGES ON " + DbUtils::escape_sql_id(table_name) + " FROM " + DbUtils::escape_sql_id(user);
const auto test = DbUtils::query_execute_string(strQuery);
if(!test)
if(!DbUtils::query_execute_string(strQuery))
std::cerr << G_STRFUNC << ": REVOKE failed." << std::endl;
}
......
This diff is collapsed.
......@@ -134,47 +134,47 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
}
else
{
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
Glib::RefPtr<Gnome::Gda::SqlBuilder> builderGroup =
Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
builder->select_add_field("groname", "pg_group");
builder->select_add_field("grolist", "pg_group");
builder->select_add_target("pg_group");
builder->set_where(
builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id("groname", "pg_group"),
builder->add_expr(group_name)));
builderGroup->select_add_field("groname", "pg_group");
builderGroup->select_add_field("grolist", "pg_group");
builderGroup->select_add_target("pg_group");
builderGroup->set_where(
builderGroup->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builderGroup->add_field_id("groname", "pg_group"),
builderGroup->add_expr(group_name)));
//TODO: Show SQL.
Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
if(data_model && data_model->get_n_rows())
Glib::RefPtr<Gnome::Gda::DataModel> data_model_group = DbUtils::query_execute_select(builderGroup);
if(data_model_group && data_model_group->get_n_rows())
{
const auto rows_count = data_model->get_n_rows();
const auto rows_count = data_model_group->get_n_rows();
for(int row = 0; row < rows_count; ++row)
{
const auto value = data_model->get_value_at(1, row); //Column 1 is the /* the user list.
const auto value_group = data_model_group->get_value_at(1, row); //Column 1 is the /* the user list.
//pg_group is a string, formatted, bizarrely, like so: "{100, 101}".
Glib::ustring group_list;
if(!value.is_null())
group_list = value.get_string();
if(!value_group.is_null())
group_list = value_group.get_string();
type_vec_strings vecUserIds = pg_list_separate(group_list);
for(const auto& userId: vecUserIds)
{
//TODO_Performance: Can we do this in one SQL SELECT?
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
Glib::RefPtr<Gnome::Gda::SqlBuilder> builderUser =
Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
builder->select_add_field("usename", "pg_user");
builder->select_add_target("pg_user");
builder->set_where(
builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id("usesysid", "pg_user"),
builder->add_expr(userId)));
Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
if(data_model && data_model->get_n_rows() && data_model->get_n_columns())
builderUser->select_add_field("usename", "pg_user");
builderUser->select_add_target("pg_user");
builderUser->set_where(
builderUser->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builderUser->add_field_id("usesysid", "pg_user"),
builderUser->add_expr(userId)));
Glib::RefPtr<Gnome::Gda::DataModel> data_model_user = DbUtils::query_execute_select(builderUser);
if(data_model_user && data_model_user->get_n_rows() && data_model_user->get_n_columns())
{
const auto value = data_model->get_value_at(0, 0);
const auto value_user = data_model_user->get_value_at(0, 0);
//std::cout << G_STRFUNC << "DEBUG: username=" << value.get_string() << std::endl;
result.push_back(value.get_string());
result.push_back(value_user.get_string());
}
else
{
......
......@@ -46,10 +46,10 @@ PyGlomRelated::type_map_relationships::size_type PyGlomRelated::len() const
boost::python::object PyGlomRelated::getitem(const boost::python::object& cppitem)
{
boost::python::extract<std::string> extractor(cppitem);
if(extractor.check())
boost::python::extract<std::string> extractor_item(cppitem);
if(extractor_item.check())
{
const std::string key = extractor;
const std::string key = extractor_item;
if(!key.empty())
{
//Return a cached item if possible:
......@@ -70,10 +70,10 @@ boost::python::object PyGlomRelated::getitem(const boost::python::object& cppite
std::shared_ptr<Relationship> relationship = iterFind->second;
const auto from_key = relationship->get_from_field();
boost::python::extract<PyGlomRecord*> extractor(m_record);
if(extractor.check())
boost::python::extract<PyGlomRecord*> extractor_record(m_record);
if(extractor_record.check())
{
PyGlomRecord* record = extractor;
PyGlomRecord* record = extractor_record;
PyGlomRecord::type_map_field_values::const_iterator iterFromKey = record->m_map_field_values.find(from_key);
if(iterFromKey != record->m_map_field_values.end())
{<