glom r1872 - in trunk: . glom glom/mode_data



Author: murrayc
Date: Mon Feb  2 11:17:52 2009
New Revision: 1872
URL: http://svn.gnome.org/viewvc/glom?rev=1872&view=rev

Log:
2009-02-02  Murray Cumming  <murrayc murrayc com>

* glom/base_db.cc: query_execute_select(), query_execute(): 
When using --debug_sql, use Statement::to_sql() to show the actual 
SQL with actual values, though this does not seem to work for 
non-SELECT queries.
* glom/mode_data/box_data.cc: refresh_related_fields(): Some extra 
error checking.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/mode_data/box_data.cc

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Mon Feb  2 11:17:52 2009
@@ -184,23 +184,7 @@
 
   Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
   Glib::RefPtr<Gnome::Gda::SqlParser> parser = gda_connection->create_parser();
-  
-  const App_Glom* app = App_Glom::get_application();
-  if(app && app->get_show_sql_debug())
-  {
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    try
-    {
-#endif
-      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
-  }
+
   Glib::RefPtr<Gnome::Gda::Statement> stmt;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
@@ -217,6 +201,28 @@
   if(error)
      std::cout << "debug: Base_DB::query_execute_select(): SqlParserError: exception from parse_string(): " << error.what() << std::endl;
 #endif //GLIBMM_EXCEPTIONS_ENABLED
+
+
+  //Debug output:
+  const App_Glom* app = App_Glom::get_application();
+  if(stmt && app && app->get_show_sql_debug())
+  {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
+    {
+#endif
+      const Glib::ustring full_query = stmt->to_sql(params);
+      std::cout << "Debug: Base_DB::query_execute_select():  " << full_query << 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
+  }
+
   
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
@@ -274,23 +280,6 @@
     return false;
   }
   
-  const App_Glom* app = App_Glom::get_application();
-  if(app && app->get_show_sql_debug())
-  {
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    try
-    {
-#endif
-      std::cerr << "Debug: Base_DB::query_execute():  " << strQuery << std::endl;
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-    }
-    catch(const Glib::Exception& ex)
-    {
-      std::cerr << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
-    }
-#endif
-  }
-  
   Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
   Glib::RefPtr<Gnome::Gda::SqlParser> parser = gda_connection->create_parser();
   Glib::RefPtr<Gnome::Gda::Statement> stmt;
@@ -313,11 +302,35 @@
     return false;
   }
 #endif
+
+
+  //Debug output:
+  const App_Glom* app = App_Glom::get_application();
+  if(stmt && app && app->get_show_sql_debug())
+  {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
+    {
+#endif
+      //TODO: full_query still seems to contain ## parameter names, 
+      //though it works for our SELECT queries in query_execute_select(): 
+      const Glib::ustring full_query = stmt->to_sql(params);
+      std::cerr << "Debug: Base_DB::query_execute(): " << full_query << std::endl;
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    }
+    catch(const Glib::Exception& ex)
+    {
+      std::cerr << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
+    }
+#endif
+  }
+
+
   int exec_retval = -1;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
-    exec_retval = gda_connection->statement_execute_non_select (stmt, params);
+    exec_retval = gda_connection->statement_execute_non_select(stmt, params);
   }
   catch(const Glib::Error& error)
   {

Modified: trunk/glom/mode_data/box_data.cc
==============================================================================
--- trunk/glom/mode_data/box_data.cc	(original)
+++ trunk/glom/mode_data/box_data.cc	Mon Feb  2 11:17:52 2009
@@ -294,11 +294,12 @@
   if(!fieldsToGet.empty())
   {
     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);
+    std::cout << "DEBUG: Box_Data::refresh_related_fields(): query=" << query << std::endl;
 
     Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query);
     if(!result)
     {
-      g_warning("Box_Data_List::refresh_related_fields(): no result.");
+      std::cerr << "Box_Data_List::refresh_related_fields(): no result." << std::endl;
       handle_error();
     }
     else
@@ -308,24 +309,33 @@
       {
         type_vecLayoutFields::const_iterator iterFields = fieldsToGet.begin();
 
-        guint cols_count = result->get_n_columns();
+        const guint cols_count = result->get_n_columns();
+        if(cols_count <= 0)
+        {
+          std::cerr << "Box_Data_List::refresh_related_fields(): The result had 0 columns" << std::endl;
+        }
+
         for(guint uiCol = 0; uiCol < cols_count; uiCol++)
         {
           const Gnome::Gda::Value value = result->get_value_at(uiCol, 0 /* row */);
           sharedptr<LayoutItem_Field> layout_item = *iterFields;
+          if(!layout_item)
+            std::cerr << "Box_Data_List::refresh_related_fields(): The layout_item was null." << std::endl;
+          else
+          {
+            //std::cout << "DEBUG: Box_Data_List::refresh_related_fields(): field_name=" << layout_item->get_name() << std::endl;
+            //std::cout << "  DEBUG: Box_Data_List::refresh_related_fields(): value_as_string=" << value.to_string()  << std::endl;
 
-          //g_warning("list fill: field_name=%s", iterFields->get_name().c_str());
-          //g_warning("  value_as_string=%s", value.to_string().c_str());
-
-          //m_AddDel.set_value(row, layout_item, value);
-          set_entered_field_data(row, layout_item, value);
-          //g_warning("addedel size=%d", m_AddDel.get_count());
+            //m_AddDel.set_value(row, layout_item, value);
+            set_entered_field_data(row, layout_item, value);
+            //g_warning("addedel size=%d", m_AddDel.get_count());
+          }
 
           ++iterFields;
         }
       }
       else
-       g_warning("Box_Data_List::refresh_related_fields(): no records found.");
+        std::cerr << "Box_Data_List::refresh_related_fields(): no records found." << std::endl;
     }
   }
 }



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