glom r1816 - in trunk: . glom glom/mode_data glom/mode_design/fields glom/mode_design/print_layouts glom/mode_design/users glom/navigation glom/reports glom/utility_widgets/db_adddel



Author: murrayc
Date: Fri Dec 19 13:57:50 2008
New Revision: 1816
URL: http://svn.gnome.org/viewvc/glom?rev=1816&view=rev

Log:
2008-12-19  Murray Cumming  <murrayc murrayc com>

* glom/base_db.[h|cc]: Split query_execute() into query_execute() and 
query_execute_select(), returning just a bool for query_execute(), 
as suggested by a TODO because of the changed API in libgda 4.0.
* Many files: Call the correct method.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/base_db.h
   trunk/glom/base_db_table_data.cc
   trunk/glom/base_db_table_data.h
   trunk/glom/dialog_database_preferences.cc
   trunk/glom/frame_glom.cc
   trunk/glom/glom_postgres.cc
   trunk/glom/glom_privs.cc
   trunk/glom/mode_data/box_data.cc
   trunk/glom/mode_data/box_data_calendar_related.cc
   trunk/glom/mode_data/box_data_details.cc
   trunk/glom/mode_data/box_data_portal.cc
   trunk/glom/mode_design/fields/box_db_table_definition.cc
   trunk/glom/mode_design/print_layouts/canvas_print_layout.cc
   trunk/glom/mode_design/users/dialog_groups_list.cc
   trunk/glom/mode_design/users/dialog_users_list.cc
   trunk/glom/navigation/box_tables.cc
   trunk/glom/reports/report_builder.cc
   trunk/glom/utility_widgets/db_adddel/db_adddel.cc

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Fri Dec 19 13:57:50 2008
@@ -158,7 +158,7 @@
 }
 
 //static:
-Glib::RefPtr<Gnome::Gda::DataModel> Base_DB::query_execute(const Glib::ustring& strQuery, Gtk::Window* /* parent_window */)
+Glib::RefPtr<Gnome::Gda::DataModel> Base_DB::query_execute_select(const Glib::ustring& strQuery, Gtk::Window* /* parent_window */)
 {
   Glib::RefPtr<Gnome::Gda::DataModel> result;
 
@@ -171,97 +171,137 @@
   sharedptr<SharedConnection> sharedconnection = connect_to_server(0, error);
   if(error.get())
   {
-    g_warning("Base_DB::query_execute failed (query was: %s): %s", strQuery.c_str(), error->what());
+    g_warning("Base_DB::query_execute_select() failed (query was: %s): %s", strQuery.c_str(), error->what());
     // TODO: Rethrow? 
   }
 #endif
-  if(sharedconnection)
+  if(!sharedconnection)
   {
-    Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
+    std::cerr << "Base_DB::query_execute_select(): No connection yet." << std::endl;
+    return result;
+  }
 
-   const App_Glom* app = App_Glom::get_application();
-   if(app && app->get_show_sql_debug())
-   {
+  Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
+
+  const App_Glom* app = App_Glom::get_application();
+  if(app && app->get_show_sql_debug())
+  {
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-      try
-      {
+    try
+    {
 #endif
-        std::cout << "Debug: Base_DB::query_execute():  " << strQuery << std::endl;
+      std::cout << "Debug: Base_DB::query_execute_select():  " << strQuery << std::endl;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-      }
-      catch(const Glib::Exception& ex)
-      {
-        std::cout << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
-      }
-#endif
     }
-        
-    // TODO: Several functions call query_execute with non-select queries.
-    // Before libgda-3.0, execute_single_command returned always a datamodel
-    // on success. In case of a successful non-select command, we therefore
-    // create an empty datamodel to return, to make clear that the function
-    // succeeded. Probably, we should introduce another
-    // query_execute_non_select in the long term. 
-    if(strQuery.compare(0, 6, "SELECT") == 0)
+    catch(const Glib::Exception& ex)
     {
+      std::cout << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
+    }
+#endif
+  }
+        
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-      try
-      {
-        result = gda_connection->statement_execute_select(strQuery);
-      }
-      catch(const Gnome::Gda::ConnectionError& ex)
-      {
-        std::cout << "debug: Base_DB::query_execute(): ConnectionError: exception from statement_execute_select(): " << ex.what() << std::endl;
-      }
-      catch(const Gnome::Gda::ServerProviderError& ex)
-      {
-        std::cout << "debug: Base_DB::query_execute(): ServerProviderError: exception from statement_execute_select(): " << ex.what() << std::endl;
-      }
+  try
+  {
+    result = gda_connection->statement_execute_select(strQuery);
+  }
+  catch(const Gnome::Gda::ConnectionError& ex)
+  {
+    std::cout << "debug: Base_DB::query_execute_select(): ConnectionError: exception from statement_execute_select(): " << ex.what() << std::endl;
+  }
+  catch(const Gnome::Gda::ServerProviderError& ex)
+  {
+    std::cout << "debug: Base_DB::query_execute_select(): ServerProviderError: exception from statement_execute_select(): " << ex.what() << std::endl;
+  }
 #else
-      std::auto_ptr<Glib::Error> error;
-      result = gda_connection->statement_execute_select(strQuery, error);
-      // Ignore error, empty datamodel is handled below
+  std::auto_ptr<Glib::Error> error;
+  result = gda_connection->statement_execute_select(strQuery, error);
+  if(error)
+    std::cout << "debug: Base_DB::query_execute_select(): Glib::Error from statement_execute_select(): " << error->what() << std::endl;
 #endif //GLIBMM_EXCEPTIONS_ENABLED
-    }
-    else
-    {
+
+  if(!result)
+  {
+    std::cerr << "Glom  Base_DB::query_execute_select(): Error while executing SQL" << std::endl <<
+      "  " <<  strQuery << std::endl;
+    handle_error();
+  }
+
+  return result;
+}
+
+
+//static:
+bool Base_DB::query_execute(const Glib::ustring& strQuery, Gtk::Window* /* parent_window */)
+{
+  //TODO: Bakery::BusyCursor busy_cursor(get_app_window());
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-      int execute_result = -1;
-      try
-      {
-        execute_result = gda_connection->statement_execute_non_select(strQuery);
-      }
-      catch(const Gnome::Gda::ConnectionError& ex)
-      {
-        std::cout << "debug: Base_DB::query_execute(): ConnectionError: exception from execute_non_select_command(): " << ex.what() << std::endl;
-      }
-      catch(const Gnome::Gda::ServerProviderError& ex)
-      {
-        std::cout << "debug: Base_DB::query_execute(): ServerProviderError: exception from execute_non_select_command(): " << ex.what() << std::endl;
-      }
+  sharedptr<SharedConnection> sharedconnection = connect_to_server();
 #else
-      std::auto_ptr<Glib::Error> error;
-      execute_result = gda_connection->gda_connection->statement_execute_non_select(strQuery, error);
-#endif //GLIBMM_EXCEPTIONS_ENABLED
-      
-      if(execute_result != -1)
-        result = Gnome::Gda::DataModelArray::create(1);
-    }
+  std::auto_ptr<ExceptionConnection> error;
+  sharedptr<SharedConnection> sharedconnection = connect_to_server(0, error);
+  if(error.get())
+  {
+    g_warning("Base_DB::query_execute() failed (query was: %s): %s", strQuery.c_str(), error->what());
+    // TODO: Rethrow? 
+  }
+#endif
+  if(!sharedconnection)
+  {
+    std::cerr << "Base_DB::query_execute(): No connection yet." << std::endl;
+    return false;
+  }
+
+  Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
 
-    if(!result)
+  const App_Glom* app = App_Glom::get_application();
+  if(app && app->get_show_sql_debug())
+  {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
     {
-      std::cerr << "Glom  Base_DB::query_execute(): Error while executing SQL" << std::endl <<
-                   "  " <<  strQuery << std::endl;
-      handle_error();
+#endif
+      std::cout << "Debug: Base_DB::query_execute():  " << strQuery << std::endl;
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
     }
+    catch(const Glib::Exception& ex)
+    {
+      std::cout << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
+    }
+#endif
   }
-  else
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  int execute_result = -1;
+  try
   {
-    g_warning("Base_DB::query_execute(): No connection yet.");
+    execute_result = gda_connection->statement_execute_non_select(strQuery);
   }
-
-  return result;
+  catch(const Gnome::Gda::ConnectionError& ex)
+  {
+    std::cout << "debug: Base_DB::query_execute(): ConnectionError: exception from execute_non_select_command(): " << ex.what() << std::endl;
+  }
+  catch(const Gnome::Gda::ServerProviderError& ex)
+  {
+    std::cout << "debug: Base_DB::query_execute(): ServerProviderError: exception from execute_non_select_command(): " << ex.what() << std::endl;
+  }
+#else
+  std::auto_ptr<Glib::Error> error;
+  execute_result = gda_connection->gda_connection->statement_execute_non_select(strQuery, error);
+  if(error)
+    std::cout << "debug: Base_DB::query_execute(): Glib::Error from statement_execute_non_select(): " << error->what() << std::endl;
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+      
+  if(execute_result == -1) //-1 from statement_execute_non_select() means an error.
+  {
+    std::cerr << "Glom  Base_DB::query_execute(): Error while executing SQL" << std::endl <<
+      "  " <<  strQuery << std::endl;
+    handle_error();
+    return false;
+  }
+  
+  return true;
 }
 
 void Base_DB::load_from_document()
@@ -658,13 +698,17 @@
       if(test)
       {
         //Add the single record:
-        query_execute("INSERT INTO \"" GLOM_STANDARD_TABLE_PREFS_TABLE_NAME "\" (\"" GLOM_STANDARD_TABLE_PREFS_FIELD_ID "\") VALUES (1)");
+        const bool test = query_execute("INSERT INTO \"" GLOM_STANDARD_TABLE_PREFS_TABLE_NAME "\" (\"" GLOM_STANDARD_TABLE_PREFS_FIELD_ID "\") VALUES (1)");
+        if(!test)
+          std::cerr << "Base_DB::add_standard_tables(): INSERT failed." << std::endl;
 
         //Use the database title from the document, if there is one:
         const Glib::ustring system_name = get_document()->get_database_title();
         if(!system_name.empty())
         {
-          query_execute("UPDATE \"" GLOM_STANDARD_TABLE_PREFS_TABLE_NAME "\" SET  " "\"" GLOM_STANDARD_TABLE_PREFS_FIELD_NAME "\" = '" + system_name + "' WHERE \"" GLOM_STANDARD_TABLE_PREFS_FIELD_ID "\" = 1");
+          const bool test = query_execute("UPDATE \"" GLOM_STANDARD_TABLE_PREFS_TABLE_NAME "\" SET  " "\"" GLOM_STANDARD_TABLE_PREFS_FIELD_NAME "\" = '" + system_name + "' WHERE \"" GLOM_STANDARD_TABLE_PREFS_FIELD_ID "\" = 1");
+          if(!test)
+            std::cerr << "Base_DB::add_standard_tables(): UPDATE failed." << std::endl;
         }
       }
       else
@@ -833,7 +877,7 @@
    " WHERE \"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME "\" = '" + table_name + "' AND "
           "\"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME "\" = '" + field_name + "'";
 
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
   if(!datamodel || (datamodel->get_n_rows() == 0))
   {
     //Start with zero:
@@ -843,11 +887,9 @@
       GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME ", " GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME ", " GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_NEXT_VALUE
       ") VALUES ('" + table_name + "', '" + field_name + "', 0)";
 
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
-    if(!datamodel)
-    {
-      g_warning("Base_DB::auto_increment_insert_first_if_necessary(): INSERT of new row failed.");
-    }
+    const bool test = query_execute(sql_query);
+    if(!test)
+      std::cerr << "Base_DB::auto_increment_insert_first_if_necessary(): INSERT of new row failed." << std::endl;
 
     //GdaNumeric is a pain, so we take a short-cut:
     bool success = false;
@@ -876,7 +918,7 @@
 
   //Get the max key value in the database:
   const Glib::ustring sql_query = "SELECT MAX(\"" + table_name + "\".\"" + field_name + "\") FROM \"" + table_name + "\"";
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
   if(datamodel && datamodel->get_n_rows() && datamodel->get_n_columns())
   {
     //Increment it:
@@ -891,16 +933,12 @@
       " WHERE \"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME "\" = '" + table_name + "' AND "
              "\"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME "\" = '" + field_name + "'";
 
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
-    if(!datamodel)
-    {
-      g_warning("Base_DB::recalculate_next_auto_increment_value(): UPDATE failed.");
-    }
+    const bool test = query_execute(sql_query);
+    if(!test)
+      std::cerr << "Base_DB::recalculate_next_auto_increment_value(): UPDATE failed." << std::endl;
   }
   else
-  {
-    g_warning("Base_DB::recalculate_next_auto_increment_value(): SELECT MAX() failed.");
-  }
+    std::cerr << "Base_DB::recalculate_next_auto_increment_value(): SELECT MAX() failed." << std::endl;
 }
 
 Gnome::Gda::Value Base_DB::get_next_auto_increment_value(const Glib::ustring& table_name, const Glib::ustring& field_name) const
@@ -918,11 +956,9 @@
       " WHERE \"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME "\" = '" + table_name + "' AND "
             "\""  GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME "\" = '" + field_name + "'";
 
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
-  if(!datamodel)
-  {
-    g_warning("Base_DB::get_next_auto_increment_value(): Increment failed.");
-  }
+  const bool test = query_execute(sql_query);
+  if(!test)
+    std::cerr << "Base_DB::get_next_auto_increment_value(): Increment failed." << std::endl;
 
   return result;
 }
@@ -961,7 +997,7 @@
     try
     #endif
     {
-      Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+      Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
       if(datamodel && (datamodel->get_n_rows() != 0))
       {
         result.m_name = Conversions::get_text_for_gda_value(Field::TYPE_TEXT, datamodel->get_value_at(0, 0));
@@ -1033,11 +1069,12 @@
       "\"" GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_ADDRESS_POSTCODE "\" = '" + prefs.m_org_address_postcode + "'"
       " WHERE \"" GLOM_STANDARD_TABLE_PREFS_FIELD_ID "\" = 1";
 
+    bool test = false;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-    try
+    try //TODO: query_execute() probably handles these already.
 #endif // GLIBMM_EXCEPTIONS_ENABLED
     {
-      Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+      test = query_execute(sql_query);
     }
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
     catch(const Glib::Exception& ex)
@@ -1050,6 +1087,9 @@
     }
 #endif // GLIBMM_EXCEPTIONS_ENABLED
 
+    if(!test)
+      std::cerr << "Base_DB::set_database_preferences(): UPDATE failed." << std::endl;
+
     //Set some information in the document too, so we can use it to recreate the database:
     get_document()->set_database_title(prefs.m_name);
 }
@@ -1211,11 +1251,9 @@
   //Actually create the table
   try
   {
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute( "CREATE TABLE \"" + table_info->get_name() + "\" (" + sql_fields + ");" );
-    if(!data_model)
-      table_creation_succeeded = false;
-    else
-      table_creation_succeeded = true;
+    table_creation_succeeded = query_execute( "CREATE TABLE \"" + table_info->get_name() + "\" (" + sql_fields + ");" );
+    if(!table_creation_succeeded)
+      std::cerr << "Base_DB::create_table(): CREATE TABLE failed." << std::endl;
   }
   catch(const ExceptionConnection& ex)
   {
@@ -1913,7 +1951,7 @@
 
   //Get primary key values for every record:
   const Glib::ustring query = "SELECT \"" + table_name + "\".\"" + primary_key->get_name() + "\" FROM \"" + table_name + "\"";
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(query);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(query);
   if(!data_model || !data_model->get_n_rows() || !data_model->get_n_columns())
   {
     //HandleError();
@@ -2103,7 +2141,7 @@
       Glib::RefPtr<Gnome::Gda::DataModel> data_model;
       try
       {
-        data_model = query_execute(query);
+        data_model = query_execute_select(query);
       }
       catch(const Glib::Exception& ex)
       {
@@ -2200,13 +2238,13 @@
     //std::cout << "debug: set_field_value_in_database(): " << std::endl << "  " << strQuery << std::endl;
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-    try
+    try //TODO: The exceptions are probably already handled by query_execute(0.
 #endif
     {
-      Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(strQuery, parent_window);  //TODO: Handle errors
-      if(!datamodel)
+      const bool test = query_execute(strQuery, parent_window); //TODO: Respond to failure.
+      if(!test)
       {
-        g_warning("Box_Data::set_field_value_in_database(): UPDATE failed.");
+        std::cerr << "Box_Data::set_field_value_in_database(): UPDATE failed." << std::endl;
         return false; //failed.
       }
     }
@@ -2269,7 +2307,7 @@
   if(!sql_query.empty())
     sql_query += " LIMIT 1";
 
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(sql_query);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(sql_query);
   if(data_model)
   {
     if(data_model->get_n_rows())
@@ -2313,7 +2351,7 @@
   if(!sql_query.empty())
     sql_query += " LIMIT 1";
 
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(sql_query);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(sql_query);
   if(data_model)
   {
     if(data_model->get_n_rows())
@@ -2582,7 +2620,7 @@
     Glib::ustring strQuery = "SELECT \"" + relationship->get_to_table() + "\".\"" + source_field->get_name() + "\" FROM \"" +  relationship->get_to_table() + "\"";
     strQuery += " WHERE \"" + to_key_field->get_name() + "\" = " + to_key_field->sql(value_to_key_field);
 
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
     if(data_model && data_model->get_n_rows())
     {
       //There should be only 1 row. Well, there could be more but we will ignore them.
@@ -2605,7 +2643,7 @@
   Glib::ustring strQuery = "SELECT \"" + table_name_used + "\".\"" + field->get_name() + "\" FROM \"" + table_name_used + "\"";
   strQuery += " WHERE \"" + field->get_name() + "\" = " + field->get_full_field_details()->sql(value);
 
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
   if(data_model)
   {
     //std::cout << "debug: Base_DB::get_field_value_is_unique(): table_name=" << table_name << ", field name=" << field->get_name() << ", value=" << value.to_string() << ", rows count=" << data_model->get_n_rows() << std::endl;
@@ -2801,7 +2839,7 @@
   where_clause += "(\"" + primary_key->get_name() + "\"=" + primary_key->sql(primary_key_value) + ")";
 
   const Glib::ustring query = Utils::build_sql_select_with_where_clause(found_set.m_table_name, fieldsToGet, where_clause);
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(query);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(query);
 
   if(data_model && data_model->get_n_rows())
   {

Modified: trunk/glom/base_db.h
==============================================================================
--- trunk/glom/base_db.h	(original)
+++ trunk/glom/base_db.h	Fri Dec 19 13:57:50 2008
@@ -77,7 +77,17 @@
   static bool get_field_exists_in_database(const Glib::ustring& table_name, const Glib::ustring& field_name);
 
 
-  static Glib::RefPtr<Gnome::Gda::DataModel> query_execute(const Glib::ustring& strQuery, Gtk::Window* parent_window = 0);
+  /** Execute a SQL Select command, returning the result.
+   * This method handles any Gda exceptions caused by executing the command.
+   */
+  static Glib::RefPtr<Gnome::Gda::DataModel> query_execute_select(const Glib::ustring& strQuery, Gtk::Window* parent_window = 0);
+
+
+  /** Execute a SQL non-select command, returning true if it succeeded.
+   * This method handles any Gda exceptions caused by executing the command.
+   */
+  static bool query_execute(const Glib::ustring& strQuery, Gtk::Window* parent_window = 0);
+
   static int count_rows_returned_by(const Glib::ustring& sql_query);
 
 

Modified: trunk/glom/base_db_table_data.cc
==============================================================================
--- trunk/glom/base_db_table_data.cc	(original)
+++ trunk/glom/base_db_table_data.cc	Fri Dec 19 13:57:50 2008
@@ -60,7 +60,7 @@
 }
 
 
-Glib::RefPtr<Gnome::Gda::DataModel> Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Value& primary_key_value)
+bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Value& primary_key_value)
 {
   sharedptr<const Field> fieldPrimaryKey = get_field_primary_key();
 
@@ -204,12 +204,13 @@
   }
 
   //Put it all together to create the record with these field values:
-  Glib::RefPtr<Gnome::Gda::DataModel> result;
   if(!strNames.empty() && !strValues.empty())
   {
     const Glib::ustring strQuery = "INSERT INTO \"" + m_table_name + "\" (" + strNames + ") VALUES (" + strValues + ")";
-    result = query_execute(strQuery, App_Glom::get_application());
-    if(result)
+    const bool test = query_execute(strQuery, App_Glom::get_application());
+    if(!test)
+      std::cerr << "Box_Data::record_new(): INSERT failed." << std::endl;
+    else
     {
       Gtk::TreeModel::iterator row; // TODO: remove this parameter.
       set_primary_key_value(row, primary_key_value); //Needed by Box_Data_List::on_adddel_user_changed().
@@ -217,27 +218,29 @@
       //Update any lookups, related fields, or calculations:
       for(type_vecLayoutFields::const_iterator iter = fieldsToAdd.begin(); iter != fieldsToAdd.end(); ++iter)
       {
-         sharedptr<const LayoutItem_Field> layout_item = *iter;
+        sharedptr<const LayoutItem_Field> layout_item = *iter;
          
-         //TODO_Performance: We just set this with set_entered_field_data() above. Maybe we could just remember it.
-         const Gnome::Gda::Value field_value = get_entered_field_data(layout_item);
+        //TODO_Performance: We just set this with set_entered_field_data() above. Maybe we could just remember it.
+        const Gnome::Gda::Value field_value = get_entered_field_data(layout_item);
+
+        LayoutFieldInRecord field_in_record(layout_item, m_table_name, fieldPrimaryKey, primary_key_value);
+
+        //Get-and-set values for lookup fields, if this field triggers those relationships:
+        do_lookups(field_in_record, row, field_value);
 
-         LayoutFieldInRecord field_in_record(layout_item, m_table_name, fieldPrimaryKey, primary_key_value);
+        //Update related fields, if this field is used in the relationship:
+        refresh_related_fields(field_in_record, row, field_value);
 
-         //Get-and-set values for lookup fields, if this field triggers those relationships:
-         do_lookups(field_in_record, row, field_value);
+        //TODO: Put the inserted row into result, somehow? murrayc
 
-         //Update related fields, if this field is used in the relationship:
-         refresh_related_fields(field_in_record, row, field_value);
+        return true; //success
       }
     }
-    else
-    {
-      std::cerr << "Box_Data::record_new(): INSERT returned null DataModel." << std::endl; 
-    }
   }
+  else
+    std::cerr << "Base_DB_Table_Data::record_new(): Empty field names or values." << std::endl;
 
-  return result; //Failed.
+  return false; //Failed.
 }
 
 
@@ -258,7 +261,7 @@
 
   //TODO_Performance: Is this the best way to just find out whether there is one record that meets this criteria?
   const Glib::ustring query = "SELECT \"" + to_field + "\" FROM \"" + relationship->get_to_table() + "\" WHERE \"" + related_table + "\".\"" + to_field + "\" = " + key_field->sql(key_value);
-  Glib::RefPtr<Gnome::Gda::DataModel> records = query_execute(query, App_Glom::get_application());
+  Glib::RefPtr<Gnome::Gda::DataModel> records = query_execute_select(query, App_Glom::get_application());
   if(!records)
     handle_error();
   else
@@ -349,7 +352,10 @@
       const Glib::ustring strQuery = "INSERT INTO \"" + relationship->get_to_table() + "\" (\"" + primary_key_field->get_name() + "\") VALUES (" + primary_key_field->sql(primary_key_value) + ")";
       const bool test = query_execute(strQuery, App_Glom::get_application());
       if(!test)
+      {
+        std::cerr << "Base_DB_Table_Data::add_related_record_for_field(): INSERT failed." << std::endl;
         return false;
+      }
 
       if(key_is_auto_increment)
       {
@@ -388,7 +394,10 @@
               " WHERE \"" + relationship->get_from_table() + "\".\"" + parent_primary_key_field->get_name() + "\" = " + parent_primary_key_field->sql(parent_primary_key_value);
             const bool test = query_execute(strQuery, App_Glom::get_application());
             if(!test)
+            {
+              std::cerr << "Base_DB_Table_Data::add_related_record_for_field(): UPDATE failed." << std::endl;
               return false;
+            }
           }
         }
       }

Modified: trunk/glom/base_db_table_data.h
==============================================================================
--- trunk/glom/base_db_table_data.h	(original)
+++ trunk/glom/base_db_table_data.h	Fri Dec 19 13:57:50 2008
@@ -52,8 +52,9 @@
 protected:
 
   /** Create a new record with all the entered field values from the currently-active details/row.
+   * @result true if the record was added to the database.
    */
-  Glib::RefPtr<Gnome::Gda::DataModel> record_new(bool use_entered_data = true, const Gnome::Gda::Value& primary_key_value = Gnome::Gda::Value()); 
+  bool record_new(bool use_entered_data = true, const Gnome::Gda::Value& primary_key_value = Gnome::Gda::Value()); 
 
   Gnome::Gda::Value get_entered_field_data_field_only(const sharedptr<const Field>& field) const;
   virtual Gnome::Gda::Value get_entered_field_data(const sharedptr<const LayoutItem_Field>& field) const;

Modified: trunk/glom/dialog_database_preferences.cc
==============================================================================
--- trunk/glom/dialog_database_preferences.cc	(original)
+++ trunk/glom/dialog_database_preferences.cc	Fri Dec 19 13:57:50 2008
@@ -101,12 +101,9 @@
         " WHERE \"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME "\" = '" + table_name + "' AND "
                "\"" GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME "\" = '" + field_name +"'";
 
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query, this);
-    if(!datamodel)
-    {
-      g_warning("Dialog_Database_Preferences::on_treeview_cell_edited_next_value(): UPDATE failed.");
-    }
-
+    const bool test = query_execute(sql_query, this);
+    if(!test)
+      std::cerr << "Dialog_Database_Preferences::on_treeview_cell_edited_next_value(): UPDATE failed." << std::endl;
   }
 }
 
@@ -144,7 +141,7 @@
 
   NumericFormat numeric_format; //ignored
 
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query, this);
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query, this);
   if(!datamodel)
   {
     std::cerr << "Dialog_Database_Preferences::load_from_document(): Gda::DataModel is NULL." << std::endl;

Modified: trunk/glom/frame_glom.cc
==============================================================================
--- trunk/glom/frame_glom.cc	(original)
+++ trunk/glom/frame_glom.cc	Fri Dec 19 13:57:50 2008
@@ -593,7 +593,7 @@
   const Glib::ustring query = Utils::build_sql_select_with_where_clause(found_set.m_table_name, fieldsSequence, found_set.m_where_clause, found_set.m_extra_join, found_set.m_sort_clause, found_set.m_extra_group_by);
 
   //TODO: Lock the database (prevent changes) during export.
-  Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute(query, get_app_window());
+  Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query, get_app_window());
 
   guint rows_count = 0;
   if(result)
@@ -645,7 +645,7 @@
   const Glib::ustring query = Utils::build_sql_select_with_where_clause(found_set.m_table_name, fieldsSequence, found_set.m_where_clause, found_set.m_extra_join, found_set.m_sort_clause, found_set.m_extra_group_by);
  
   //TODO: Lock the database (prevent changes) during export.
-  Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute(query, get_app_window());
+  Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query, get_app_window());
 
   guint rows_count = 0;
   if(result)

Modified: trunk/glom/glom_postgres.cc
==============================================================================
--- trunk/glom/glom_postgres.cc	(original)
+++ trunk/glom/glom_postgres.cc	Fri Dec 19 13:57:50 2008
@@ -35,7 +35,9 @@
   }
 
   const bool bTest = query_execute(  "ALTER TABLE \"" + table_name + "\" ADD \"" + field_to_add->get_name() + "\" " +  field_to_add->get_sql_type() );
-  if(bTest)
+  if(!bTest)
+    std::cerr << "GlomPostgres::postgres_add_column(): ALTER TABLE failed." << std::endl;
+  else
   {
     if(not_extras)
     {
@@ -56,9 +58,11 @@
 
   if(field->get_name() != field_old->get_name())
   {
-     Glib::RefPtr<Gnome::Gda::DataModel>  datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" RENAME COLUMN \"" + field_old->get_name() + "\" TO \"" + field->get_name() + "\"" );
-     if(!datamodel)
+     const bool test = query_execute( "ALTER TABLE \"" + table_name + "\" RENAME COLUMN \"" + field_old->get_name() + "\" TO \"" + field->get_name() + "\"" );
+     if(!test)
      {
+       std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE failed." << std::endl;
+
        handle_error();
        return result;
      }
@@ -71,14 +75,17 @@
      //TODO: Check that there is only one primary key.
      //When unsetting a primary key, ask which one should replace it.
 
-     Glib::RefPtr<Gnome::Gda::DataModel> datamodel;
+     bool test = false;
        
      //TODO: Somehow discover whether these constraint names really exists, so we can be more robust in strange situations. This needs libgda 2, which has GDA_CONNECTION_SCHEMA_CONSTRAINTS.
      //Postgres needs us to add/drop constraints explicitly when changing existing fields, though it can create them implicitly when creating the field:
      if(field->get_primary_key())
      {
        //Set field as primary key :
-       datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" ADD PRIMARY KEY (\"" + field->get_name() + "\")");
+       test = query_execute( "ALTER TABLE \"" + table_name + "\" ADD PRIMARY KEY (\"" + field->get_name() + "\")");
+       if(!test)
+         std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with ADD PRIMARY KEY failed." << std::endl;
+
        primary_key_was_set = true;
 
        //Tell the caller about a constraint:
@@ -87,7 +94,10 @@
      else
      {
        //Unset field as primary key:
-       datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + table_name + "_pkey\"" );
+       test = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + table_name + "_pkey\"" );
+       if(!test)
+         std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with DROP CONSTRAINT failed." << std::endl;
+
        primary_key_was_unset = true;
 
        //Make sure that the caller knows that a field stops being unique when it stops being a primary key, 
@@ -95,7 +105,7 @@
        result->set_unique_key(false); //All primary keys are unique.
      }
 
-     if(!datamodel)
+     if(!test)
      {
        handle_error();
        return result;
@@ -104,12 +114,14 @@
      if(primary_key_was_set && field_old->get_unique_key())
      {
        //If the key already had a uniqueness constraint, without also being a primary key, remove that now, because it is superfluous and we will not expect it later:
-       Glib::RefPtr<Gnome::Gda::DataModel>  datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + field->get_name() + "_key\"" );
-      if(!datamodel)
-      {
-        handle_error();
-        return result;
-      }
+       const bool test = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + field->get_name() + "_key\"" );
+       if(!test)
+       {
+         std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with DROP CONSTRAINT (2) failed." << std::endl;
+
+         handle_error();
+         return result;
+       }
     }
   }
 
@@ -121,9 +133,11 @@
     if(!primary_key_was_set && field->get_unique_key()) //Postgres automatically makes primary keys unique, so we do not need to do that separately if we have already made it a primary key
     {
       //Add uniqueness:
-      Glib::RefPtr<Gnome::Gda::DataModel>  datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" ADD CONSTRAINT \"" + field->get_name() + "_key\" UNIQUE (\"" + field->get_name() + "\")" );
-      if(!datamodel)
+      const bool test = query_execute( "ALTER TABLE \"" + table_name + "\" ADD CONSTRAINT \"" + field->get_name() + "_key\" UNIQUE (\"" + field->get_name() + "\")" );
+      if(!test)
       {
+        std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with ADD CONSTRAINT failed." << std::endl;
+
         handle_error();
         return result;
       }
@@ -138,9 +152,11 @@
       else
       {
         //Remove uniqueness:
-        Glib::RefPtr<Gnome::Gda::DataModel>  datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + field->get_name() + "_key\"" );
-        if(!datamodel)
+        const bool test = query_execute( "ALTER TABLE \"" + table_name + "\" DROP CONSTRAINT \"" + field->get_name() + "_key\"" );
+        if(!test)
         {
+          std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with DROP CONSTRAINT (3) failed." << std::endl;
+
           handle_error();
           return result;
         }
@@ -155,9 +171,11 @@
     {
       if(set_anyway || (default_value != default_value_old))
       {
-        Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute( "ALTER TABLE \"" + table_name + "\" ALTER COLUMN \""+ field->get_name() + "\" SET DEFAULT " + field->sql(field->get_default_value()) );
-        if(!datamodel)
+        const bool test = query_execute( "ALTER TABLE \"" + table_name + "\" ALTER COLUMN \""+ field->get_name() + "\" SET DEFAULT " + field->sql(field->get_default_value()) );
+        if(!test)
         {
+          std::cerr << "GlomPostgres::postgres_change_column_extras(): ALTER TABLE with ALTER COLUMN failed." << std::endl;
+
           handle_error();
           return result;
         }
@@ -176,7 +194,7 @@
     //If the not-nullness has changed:
     if( set_anyway ||  (field->get_field_info().get_allow_null() != field_old->get_field_info().get_allow_null()) )
     {
-      Glib::ustring nullness = (field->get_field_info().get_allow_null() ? "NULL" : "NOT NULL");
+      const Glib::ustring nullness = (field->get_field_info().get_allow_null() ? "NULL" : "NOT NULL");
       query_execute(  "ALTER TABLE \"" + m_table_name + "\" ALTER COLUMN \"" + field->get_name() + "\"  SET " + nullness);
     }
   */ 

Modified: trunk/glom/glom_privs.cc
==============================================================================
--- trunk/glom/glom_privs.cc	(original)
+++ trunk/glom/glom_privs.cc	Fri Dec 19 13:57:50 2008
@@ -30,7 +30,7 @@
   type_vecStrings result;
 
   Glib::ustring strQuery = "SELECT \"pg_group\".\"groname\" FROM \"pg_group\"";
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
   if(data_model)
   {
     const int rows_count = data_model->get_n_rows();
@@ -55,7 +55,7 @@
   {
     //pg_shadow contains the users. pg_users is a view of pg_shadow without the password.
     Glib::ustring strQuery = "SELECT \"pg_shadow\".\"usename\" FROM \"pg_shadow\"";
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
     if(data_model)
     {
       const int rows_count = data_model->get_n_rows();
@@ -70,7 +70,7 @@
   else
   {
     Glib::ustring strQuery = "SELECT \"pg_group\".\"groname\", \"pg_group\".\"grolist\" FROM \"pg_group\" WHERE \"pg_group\".\"groname\" = '" + group_name + "'";
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
     if(data_model && data_model->get_n_rows())
     {
       const int rows_count = data_model->get_n_rows();
@@ -88,7 +88,7 @@
         {
           //TODO_Performance: Can we do this in one SQL SELECT?
           Glib::ustring strQuery = "SELECT \"pg_user\".\"usename\" FROM \"pg_user\" WHERE \"pg_user\".\"usesysid\" = '" + *iter + "'";
-          Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+          Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
           if(data_model)
           {
             const Gnome::Gda::Value value = data_model->get_value_at(0, 0); 
@@ -159,8 +159,9 @@
   strQuery += " GROUP \"" + group_name + "\"";
 
   const bool test = query_execute(strQuery);
-
-  if(test)
+  if(!test)
+    std::cerr << "Privs::set_table_privileges(): GRANT failed." << std::endl;
+  else
   {
     if( (table_name != GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME) && privs.m_create )
     {
@@ -190,7 +191,7 @@
 
   //Get the permissions:
   Glib::ustring strQuery = "SELECT \"pg_class\".\"relacl\" FROM \"pg_class\" WHERE \"pg_class\".\"relname\" = '" + table_name + "'";
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery);
   if(data_model && data_model->get_n_rows())
   {
     const Gnome::Gda::Value value = data_model->get_value_at(0, 0);

Modified: trunk/glom/mode_data/box_data.cc
==============================================================================
--- trunk/glom/mode_data/box_data.cc	(original)
+++ trunk/glom/mode_data/box_data.cc	Fri Dec 19 13:57:50 2008
@@ -294,7 +294,7 @@
   {
     const Glib::ustring query = Utils::build_sql_select_with_key(field_in_record_changed.m_table_name, fieldsToGet, field_in_record_changed.m_key, field_in_record_changed.m_key_value);
 
-    Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute(query, get_app_window());
+    Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query, get_app_window());
     if(!result)
     {
       g_warning("Box_Data_List::refresh_related_fields(): no result.");

Modified: trunk/glom/mode_data/box_data_calendar_related.cc
==============================================================================
--- trunk/glom/mode_data/box_data_calendar_related.cc	(original)
+++ trunk/glom/mode_data/box_data_calendar_related.cc	Fri Dec 19 13:57:50 2008
@@ -185,7 +185,7 @@
     
     const Glib::ustring sql_query = Utils::build_sql_select_with_where_clause(m_found_set.m_table_name, m_FieldsShown, where_clause, m_found_set.m_extra_join, m_found_set.m_sort_clause, m_found_set.m_extra_group_by);
     //std::cout << "DEBUG: sql_query=" << sql_query << std::endl;
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query, get_app_window());
+    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query, get_app_window());
     if(!(datamodel))
       return true;
     

Modified: trunk/glom/mode_data/box_data_details.cc
==============================================================================
--- trunk/glom/mode_data/box_data_details.cc	(original)
+++ trunk/glom/mode_data/box_data_details.cc	Fri Dec 19 13:57:50 2008
@@ -333,7 +333,7 @@
         Glib::RefPtr<Gnome::Gda::DataModel> result;
 
         if(!primary_key_is_empty)
-          result = query_execute(query, get_app_window());
+          result = query_execute_select(query, get_app_window());
 
         if((result && result->get_n_rows()) || primary_key_is_empty) //either a working result or no result needed.
         {

Modified: trunk/glom/mode_data/box_data_portal.cc
==============================================================================
--- trunk/glom/mode_data/box_data_portal.cc	(original)
+++ trunk/glom/mode_data/box_data_portal.cc	Fri Dec 19 13:57:50 2008
@@ -298,7 +298,7 @@
   fieldsToGet.push_back(layout_item);
 
   const Glib::ustring query = Utils::build_sql_select_with_key(m_portal->get_table_used(Glib::ustring() /* not relevant */), fieldsToGet, get_key_field(), primary_key_value);
-  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(query);
+  Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(query);
 
 
   bool value_found = true;

Modified: trunk/glom/mode_design/fields/box_db_table_definition.cc
==============================================================================
--- trunk/glom/mode_design/fields/box_db_table_definition.cc	(original)
+++ trunk/glom/mode_design/fields/box_db_table_definition.cc	Fri Dec 19 13:57:50 2008
@@ -165,7 +165,7 @@
   Glib::ustring name = m_AddDel.get_value(row, m_colName);
   if(!name.empty())
   {
-    bool bTest = query_execute( "ALTER TABLE \"" + m_table_name + "\" ADD \"" + name + "\" NUMERIC", get_app_window()); //TODO: Get schema type for Field::TYPE_NUMERIC
+    const bool bTest = query_execute( "ALTER TABLE \"" + m_table_name + "\" ADD \"" + name + "\" NUMERIC", get_app_window()); //TODO: Get schema type for Field::TYPE_NUMERIC
     if(bTest)
     {
       //Show the new field (fill in the other cells):
@@ -205,10 +205,14 @@
     Glib::ustring name = m_AddDel.get_value_key(iter);
     if(!name.empty())
     {
-      query_execute( "ALTER TABLE \"" + m_table_name + "\" DROP COLUMN \"" + name + "\"", get_app_window());
-
-      //Remove it from all layouts, reports, etc:
-      get_document()->remove_field(m_table_name, name);
+      const bool test = query_execute( "ALTER TABLE \"" + m_table_name + "\" DROP COLUMN \"" + name + "\"", get_app_window());
+      if(test)
+      {
+        //Remove it from all layouts, reports, etc:
+        get_document()->remove_field(m_table_name, name);
+      }
+      else
+        std::cerr << "Box_DB_Table_Definition::on_adddel_delete(): field deletion failed." << std::endl;
     }
   }
 
@@ -726,8 +730,8 @@
           const Glib::ustring sql = "UPDATE \"" + m_table_name + "\" SET \"" + fieldTemp->get_name() + "\" = " + conversion_command;
           try
           {
-            Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql, get_app_window());  //TODO: Not full type details.
-            if(!datamodel)
+            const bool test = query_execute(sql, get_app_window());  //TODO: Not full type details. What does that comment mean? murrayc
+            if(!test)
               conversion_failed = true;
           }
           catch(const Glib::Error& ex)
@@ -746,14 +750,14 @@
 
         if(!conversion_failed)
         {
-          Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute( "ALTER TABLE \"" + m_table_name + "\" DROP COLUMN \"" +  field_old->get_name() + "\"", get_app_window());
-          if(datamodel)
+          const bool test = query_execute( "ALTER TABLE \"" + m_table_name + "\" DROP COLUMN \"" +  field_old->get_name() + "\"", get_app_window());
+          if(test)
           {
             const Glib::ustring sql =  "ALTER TABLE \"" + m_table_name + "\" RENAME COLUMN \"" + fieldTemp->get_name() + "\" TO \"" + field->get_name() + "\"";
             try
             {
-              datamodel = query_execute(sql, get_app_window());
-              if(datamodel)
+              const bool test = query_execute(sql, get_app_window());
+              if(test)
               {
                 const bool test = gda_connection->commit_transaction(transaction_name);
                 if(!test)
@@ -793,7 +797,7 @@
   //std::cout << "sql_query: " << sql_query << std::endl;
 
   long null_count = 0;
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query, get_app_window());
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query, get_app_window());
   if(datamodel && datamodel->get_n_rows() && datamodel->get_n_columns())
   {
     null_count = datamodel->get_n_rows();
@@ -815,7 +819,7 @@
   //Count the distint rows:
   const Glib::ustring sql_query_distinct = "SELECT DISTINCT \"" + field->get_name() + "\" FROM \"" + m_table_name + "\"";
   
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query_distinct, get_app_window());
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query_distinct, get_app_window());
   if(datamodel)
   {
     count_distinct = datamodel->get_n_rows();
@@ -829,7 +833,7 @@
   //Count all rows, to compare. TODO_performance: Is there a more efficient way to do this? Maybe count(*), which apparently doesn't ignore NULL rows like count(somefield) would.
   const Glib::ustring sql_query_all = "SELECT \"" + field->get_name() + "\" FROM \"" + m_table_name + "\"";
   
-  datamodel = query_execute(sql_query_all, get_app_window());
+  datamodel = query_execute_select(sql_query_all, get_app_window());
   if(datamodel)
   {
     count_all = datamodel->get_n_rows();

Modified: trunk/glom/mode_design/print_layouts/canvas_print_layout.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/canvas_print_layout.cc	(original)
+++ trunk/glom/mode_design/print_layouts/canvas_print_layout.cc	Fri Dec 19 13:57:50 2008
@@ -598,7 +598,7 @@
   Glib::RefPtr<Gnome::Gda::DataModel> datamodel;
   try
   {
-    datamodel = query_execute(sql_query);
+    datamodel = query_execute_select(sql_query);
   }
   catch(const Glib::Exception& ex)
   {
@@ -686,7 +686,7 @@
 
   const Glib::ustring sql_query = Utils::build_sql_select_with_where_clause(found_set.m_table_name, fields_shown, found_set.m_where_clause, found_set.m_extra_join, found_set.m_sort_clause, found_set.m_extra_group_by);
   //std::cout << "DEBUG: sql_query=" << sql_query << std::endl;
-  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query, 0 /* TODO: get_app_window() */);
+  Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query, 0 /* TODO: get_app_window() */);
   if(!(datamodel))
     return;
     

Modified: trunk/glom/mode_design/users/dialog_groups_list.cc
==============================================================================
--- trunk/glom/mode_design/users/dialog_groups_list.cc	(original)
+++ trunk/glom/mode_design/users/dialog_groups_list.cc	Fri Dec 19 13:57:50 2008
@@ -219,7 +219,9 @@
         if(response == Gtk::RESPONSE_OK)
         {
           Glib::ustring strQuery = "DROP GROUP " + user;
-          query_execute(strQuery, this);
+          const bool test = query_execute(strQuery, this);
+          if(!test)
+            std::cerr << "Box_DB_Table_Definition::on_adddel_delete(): DROP GROUP failed." << std::endl;
 
           fill_group_list();
         }
@@ -257,7 +259,9 @@
   if(!group_name.empty())
   {
     const Glib::ustring strQuery = "CREATE GROUP \"" + group_name + "\"";
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery, this);
+    const bool test = query_execute(strQuery, this);
+    if(!test)
+      std::cout << "Dialog_GroupsList::on_button_group_new(): CREATE GROUP failed." << std::endl;
 
     //Give the new group some sensible default privileges:
     Privileges priv;
@@ -492,9 +496,11 @@
 
   strQuery += " GROUP \"" + group_name + "\"";
 
-  query_execute(strQuery, this); //TODO: Handle errors.
+  const bool test = query_execute(strQuery, this); //TODO: Handle errors.
+  if(!test)
+    std::cerr << "Dialog_GroupsList::set_table_privilege(): GRANT/REVOKE failed." << std::endl;
 
-  return true;
+  return test;
 }
 
 void Dialog_GroupsList::on_treeview_tables_toggled_view(const Glib::ustring& path_string)

Modified: trunk/glom/mode_design/users/dialog_users_list.cc
==============================================================================
--- trunk/glom/mode_design/users/dialog_users_list.cc	(original)
+++ trunk/glom/mode_design/users/dialog_users_list.cc	Fri Dec 19 13:57:50 2008
@@ -130,7 +130,9 @@
         if(!user.empty())
         {
           Glib::ustring strQuery = "ALTER GROUP \"" + m_combo_group->get_active_text() + "\" DROP USER \"" + user + "\"";
-          query_execute(strQuery, this);
+          const bool test = query_execute(strQuery, this);
+          if(!test)
+            std::cerr << "Dialog_UsersList::on_button_user_remove(): ALTER GROUP failed." << std::endl;
 
           fill_list();
         }
@@ -161,13 +163,15 @@
           dialog.set_secondary_text(_("Are your sure that you wish to delete this user?"));
           dialog.set_transient_for(*this);
 
-          int response = dialog.run();
+          const int response = dialog.run();
           dialog.hide();
 
           if(response == Gtk::RESPONSE_OK)
           {
-            Glib::ustring strQuery = "DROP USER " + user;
-            query_execute(strQuery, this);
+            const Glib::ustring strQuery = "DROP USER " + user;
+            const bool test = query_execute(strQuery, this);
+            if(!test)
+              std::cerr << "Dialog_UsersList::on_button_user_delete(): DROP USER failed" << std::endl;
 
             fill_list();
           }
@@ -210,16 +214,20 @@
   if(!user.empty())
   {
     //Add it to the group:
-    Glib::ustring strQuery = "ALTER GROUP \"" + m_combo_group->get_active_text() + "\" ADD USER " + user;
-    query_execute(strQuery, this);
+    const Glib::ustring strQuery = "ALTER GROUP \"" + m_combo_group->get_active_text() + "\" ADD USER " + user;
+    const bool test = query_execute(strQuery, this);
+    if(!test)
+      std::cerr << "Dialog_UsersList::on_button_user_add(): ALTER GROUP failed." << std::endl;
 
     //Remove any user rights, so that all rights come from the user's presence in the group:
     Document_Glom::type_listTableInfo table_list = get_document()->get_tables();
 
     for(Document_Glom::type_listTableInfo::const_iterator iter = table_list.begin(); iter != table_list.end(); ++iter)
     {
-      Glib::ustring strQuery = "REVOKE ALL PRIVILEGES ON \"" + (*iter)->get_name() + "\" FROM \"" + user + "\"";
-      query_execute(strQuery, this);
+      const Glib::ustring strQuery = "REVOKE ALL PRIVILEGES ON \"" + (*iter)->get_name() + "\" FROM \"" + user + "\"";
+      const bool test = query_execute(strQuery, this);
+      if(!test)
+        std::cerr << "Dialog_UsersList::on_button_user_add(): REVOKE failed." << std::endl;
     }
 
     fill_list();
@@ -273,11 +281,15 @@
   {
     //Create the user:
     Glib::ustring strQuery = "CREATE USER \"" + user + "\" PASSWORD '" + password + "'" ;
-    Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery, this);
+    bool test = query_execute(strQuery, this);
+    if(!test)
+       std::cerr << "Dialog_UsersList::on_button_user_new(): CREATE USER failed." << std::endl;
 
     //Add it to the group:
     strQuery = "ALTER GROUP \"" + m_combo_group->get_active_text() + "\" ADD USER \"" + user + "\"";
-    data_model = query_execute(strQuery, this);
+    test = query_execute(strQuery, this);
+    if(!test)
+       std::cerr << "Dialog_UsersList::on_button_user_new(): ALTER GROUP failed." << std::endl;
 
     fill_list();
   }
@@ -352,13 +364,15 @@
 
       if(!user.empty() && !password.empty())
       {
-        Glib::ustring strQuery = "ALTER USER \"" + user + "\" PASSWORD '" + password + "'" ;
-        Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute(strQuery, this);
+        const Glib::ustring strQuery = "ALTER USER \"" + user + "\" PASSWORD '" + password + "'" ;
+        const bool test = query_execute(strQuery, this);
+        if(!test)
+          std::cerr << "Dialog_UsersList::on_button_user_edit(): ALTER USER failed." << std::endl;
 
         //Change the password in the current connection, if this is the current user.
-         ConnectionPool* connection_pool = ConnectionPool::get_instance();
-         if(connection_pool->get_user() == user)
-           connection_pool->set_password(password);
+        ConnectionPool* connection_pool = ConnectionPool::get_instance();
+        if(connection_pool->get_user() == user)
+          connection_pool->set_password(password);
 
         fill_list();
       }

Modified: trunk/glom/navigation/box_tables.cc
==============================================================================
--- trunk/glom/navigation/box_tables.cc	(original)
+++ trunk/glom/navigation/box_tables.cc	Fri Dec 19 13:57:50 2008
@@ -301,9 +301,14 @@
           //Delete the table:
           if(iButtonClicked == Gtk::RESPONSE_OK)
           {
-            query_execute( "DROP TABLE \"" + table_name + "\"", App_Glom::get_application());
-            get_document()->remove_table(table_name); //Forget about it in the document too.
-            something_changed = true;
+            const bool test = query_execute( "DROP TABLE \"" + table_name + "\"", App_Glom::get_application());
+            if(!test)
+              std::cerr << "Box_Tables::on_adddel_Delete(): DROP TABLE failed." << std::endl;
+            else
+            {
+              get_document()->remove_table(table_name); //Forget about it in the document too.
+              something_changed = true;
+            }
           }
         }
       }

Modified: trunk/glom/reports/report_builder.cc
==============================================================================
--- trunk/glom/reports/report_builder.cc	(original)
+++ trunk/glom/reports/report_builder.cc	Fri Dec 19 13:57:50 2008
@@ -184,7 +184,7 @@
 
     sql_query += " GROUP BY " + field_group_by->get_name(); //rTODO: And restrict to the current found set.
 
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
     if(datamodel)
     {
       guint rows_count = datamodel->get_n_rows();
@@ -307,7 +307,7 @@
       sql_query += " LIMIT 1";
 
     bool records_found = false;
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(sql_query);
+    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
     if(datamodel)
     {
       const guint rows_count = datamodel->get_n_rows();
@@ -379,7 +379,7 @@
     //So let's get that data here:
     const Glib::ustring table_used = field->get_table_used(found_set.m_table_name);
     const Glib::ustring query = "SELECT \"" + table_used + "\".\"" + field->get_name() + "\" FROM \""+ table_used + "\" LIMIT 1";
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute(query);
+    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(query);
 
     if(!datamodel)
       return;

Modified: trunk/glom/utility_widgets/db_adddel/db_adddel.cc
==============================================================================
--- trunk/glom/utility_widgets/db_adddel/db_adddel.cc	(original)
+++ trunk/glom/utility_widgets/db_adddel/db_adddel.cc	Fri Dec 19 13:57:50 2008
@@ -2339,8 +2339,8 @@
         return;
       }
 
-      Glib::RefPtr<Gnome::Gda::DataModel> data_model = record_new(true /* use entered field data*/, primary_key_value);
-      if(data_model)
+      const bool added = record_new(true /* use entered field data*/, primary_key_value);
+      if(added)
       {
         //Save the primary key value for later use:
         set_value_key(row, primary_key_value);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]