glom r1885 - in trunk: . glom glom/libglom/data_structure



Author: jhs
Date: Sun Feb  8 14:12:46 2009
New Revision: 1885
URL: http://svn.gnome.org/viewvc/glom?rev=1885&view=rev

Log:
2009-02-08  Johannes Schmid  <jschmid openismus com>
	
	* glom/libglom/data_structure/Makefile.am:
	* glom/libglom/data_structure/parameternamegenerator.cc:
	* glom/libglom/data_structure/parameternamegenerator.h:
	New class to generate simple unique holder names
	
	* glom/base_db.cc (insert_example_data):
	Use the new ParameterNameGenerator class

Added:
   trunk/glom/libglom/data_structure/parameternamegenerator.cc
   trunk/glom/libglom/data_structure/parameternamegenerator.h
Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/libglom/data_structure/Makefile.am

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Sun Feb  8 14:12:46 2009
@@ -39,6 +39,7 @@
 #include <glom/libglom/utils.h>
 #include <glom/libglom/glade_utils.h>
 #include <glom/libglom/data_structure/glomconversions.h>
+#include <glom/libglom/data_structure/parameternamegenerator.h>
 #include <glom/libglom/data_structure/layout/report_parts/layoutitem_summary.h>
 #include <glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h>
 #include <glom/libglom/data_structure/layout/report_parts/layoutitem_verticalgroup.h>
@@ -1557,6 +1558,7 @@
       if(row_data.find("\n") == Glib::ustring::npos)
       {
         Glib::RefPtr<Gnome::Gda::Set> params = Gnome::Gda::Set::create();
+        ParameterNameGenerator generator;
         for(unsigned int i = 0; i < vec_values.size(); ++i)
         {
           if(i > 0)
@@ -1576,15 +1578,15 @@
           }
           
           //Add a SQL parameter for the value:
-          Glib::ustring param_name = Glib::ustring::compose("param%1", i);
+          unsigned int id;
           Glib::RefPtr<Gnome::Gda::Holder> holder = Gnome::Gda::Holder::create(vec_fields[i]->get_gda_g_type(),
-                                                                               param_name);
+                                                                               generator.get_next_name(id));
 
           holder->set_not_null(false);
           holder->set_value_as_value(value);
           params->add_holder(holder);
           
-          strVals += "##" + param_name + "::" + vec_fields[i]->get_gda_type();
+          strVals += "##" + generator.get_name_from_id(id) + "::" + vec_fields[i]->get_gda_type();
         }
 
         //Create and parse the SQL query:

Modified: trunk/glom/libglom/data_structure/Makefile.am
==============================================================================
--- trunk/glom/libglom/data_structure/Makefile.am	(original)
+++ trunk/glom/libglom/data_structure/Makefile.am	Sun Feb  8 14:12:46 2009
@@ -16,7 +16,9 @@
                               system_prefs.h system_prefs.cc \
                               print_layout.h print_layout.cc \
                               report.h report.cc \
-                              translatable_item.h translatable_item.cc
+                              translatable_item.h translatable_item.cc \
+                              parameternamegenerator.h \
+                              parameternamegenerator.cc
 
 
 

Added: trunk/glom/libglom/data_structure/parameternamegenerator.cc
==============================================================================
--- (empty file)
+++ trunk/glom/libglom/data_structure/parameternamegenerator.cc	Sun Feb  8 14:12:46 2009
@@ -0,0 +1,47 @@
+/*
+ * glom
+ * Copyright (C) Johannes Schmid 2009 <jhs gnome org>
+ * 
+ * glom is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * glom is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "parameternamegenerator.h"
+
+namespace Glom
+{
+
+ParameterNameGenerator::ParameterNameGenerator() :
+    m_id(0)
+{
+    
+}
+
+ParameterNameGenerator::~ParameterNameGenerator()
+{
+    
+}
+    
+Glib::ustring ParameterNameGenerator::get_next_name(unsigned int& id)
+{
+    m_id_table[m_id] = Glib::ustring::compose("glom_param%1", m_id);
+    id = m_id++;
+    return m_id_table[id];
+}
+
+Glib::ustring ParameterNameGenerator::get_name_from_id(unsigned int id)
+{
+    return m_id_table[id];
+}
+
+} // namespace Glom

Added: trunk/glom/libglom/data_structure/parameternamegenerator.h
==============================================================================
--- (empty file)
+++ trunk/glom/libglom/data_structure/parameternamegenerator.h	Sun Feb  8 14:12:46 2009
@@ -0,0 +1,44 @@
+/*
+ * glom
+ * Copyright (C) Johannes Schmid 2009 <jhs gnome org>
+ * 
+ * glom is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * glom is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PARAMETERNAMEGENERATOR_H_
+#define _PARAMETERNAMEGENERATOR_H_
+
+#include <map>
+#include <glibmm/ustring.h>
+
+namespace Glom
+{
+
+class ParameterNameGenerator
+{
+public:
+    ParameterNameGenerator();
+    ~ParameterNameGenerator();
+    
+    Glib::ustring get_next_name(unsigned int& id);
+    Glib::ustring get_name_from_id(unsigned int id);
+    
+private:
+    std::map<unsigned int, Glib::ustring> m_id_table;
+    unsigned int m_id;
+};
+
+#endif // _PARAMETERNAMEGENERATOR_H_
+
+}
\ No newline at end of file



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