gnomemm r1919 - in libgdamm/trunk: . examples/simple libgda/src



Author: jhs
Date: Thu Dec 25 11:10:18 2008
New Revision: 1919
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1919&view=rev

Log:
2008-12-25  Johannes  <jschmid openismus com>

	* examples/simple/main.cc:
	Added some meta store example though I am not quite sure yet what information
	would be a good example here
	
	* libgda/src/connection.ccg:
	* libgda/src/connection.hg:
	* libgda/src/metastore.ccg:
	* libgda/src/metastore.hg:
	Added several methods to update specific meta store informations and fixed
	a refreturn

Modified:
   libgdamm/trunk/ChangeLog
   libgdamm/trunk/examples/simple/main.cc
   libgdamm/trunk/libgda/src/connection.ccg
   libgdamm/trunk/libgda/src/connection.hg
   libgdamm/trunk/libgda/src/metastore.ccg
   libgdamm/trunk/libgda/src/metastore.hg

Modified: libgdamm/trunk/examples/simple/main.cc
==============================================================================
--- libgdamm/trunk/examples/simple/main.cc	(original)
+++ libgdamm/trunk/examples/simple/main.cc	Thu Dec 25 11:10:18 2008
@@ -77,32 +77,45 @@
  * display the contents of the 'products' table 
  */
 void
-display_products_contents (const Glib::RefPtr<Gda::Connection>& cnc, const Glib::RefPtr<Gda::SqlParser>& parser)
+display_products_contents (const Glib::RefPtr<Gda::Connection>& cnc)
 {
   const Glib::ustring sql = "SELECT ref, name, price FROM products";
-  Glib::RefPtr<Gda::Statement> stmt;
+  Glib::RefPtr<Gda::DataModel> data_model;
   try
   {
-    stmt =  parser->parse_string (sql);
+    data_model = cnc->statement_execute_select (sql);
   }
   catch(const Glib::Error& err)
-  {
-    std::cerr << "Error: " << err.what() << std::endl;
+  { 
+    std::cout << "Could not get the contents of the 'products' table: " 
+      << err.what() << std::endl;
     return;
   }
-  Glib::RefPtr<Gda::DataModel> data_model;
+  std::cout << data_model->dump_as_string() << std::endl;	
+}
+
+void display_meta_store(Glib::RefPtr<Gda::Connection>& cnc)
+{
+  Glib::RefPtr<Gda::DataModel> model;
   try
   {
-    data_model = cnc->statement_execute_select (stmt);
+    // Update the meta store
+    cnc->update_meta_store_table("products");
+    
+    // Receive meta store data
+    Glib::RefPtr<Gda::MetaStore> store = 
+          cnc->get_meta_store();
+    model =
+      store->extract("SELECT * FROM _tables");
+    
   }
-  catch(const Glib::Error& err)
-  { 
-    std::cout << "Could not get the contents of the 'products' table: " 
+  catch (const Glib::Error& err)
+  {
+     std::cout << "display meta store failed: " 
       << err.what() << std::endl;
     return;
   }
-
-  std::cout << data_model->dump_as_string() << std::endl;
+  std::cout << model->dump_as_string() << std::endl;
 }
 
 int main (int argc, char** argv)
@@ -126,7 +139,8 @@
     parser = Gda::SqlParser::create();
   
   create_table(cnc, parser);
-  display_products_contents(cnc, parser);
+  display_products_contents(cnc);
+  display_meta_store(cnc);
   
   return 0;
-}
+}
\ No newline at end of file

Modified: libgdamm/trunk/libgda/src/connection.ccg
==============================================================================
--- libgdamm/trunk/libgda/src/connection.ccg	(original)
+++ libgdamm/trunk/libgda/src/connection.ccg	Thu Dec 25 11:10:18 2008
@@ -325,24 +325,6 @@
 }
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Connection::update_meta_store_tables()
-#else
-bool Connection::update_meta_store_tables(std::auto_ptr<Glib::Error>& err)
-#endif
-{
-  return update_meta_store("_tables");
-}
-
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Connection::update_meta_store_types()
-#else
-bool Connection::update_meta_store_types(std::auto_ptr<Glib::Error>& err)
-#endif
-{
-  return update_meta_store("_all_types");
-}
-
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
 Glib::RefPtr<DataModel> Connection::get_meta_store_data(ConnectionMetaType meta_type)
 #else
 Glib::RefPtr<DataModel> Connection::get_meta_store_data(ConnectionMetaType meta_type, std::auto_ptr<Glib::Error>& error)
@@ -361,6 +343,31 @@
   return retvalue;
 }
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool Connection::update_meta_store_table(const Glib::ustring& table_name)
+#else
+bool Connection::update_meta_store_table(const Glib::ustring& table_name, std::auto_ptr<Glib::Error>& err)
+#endif
+{
+  GdaMetaContext mcontext = {(gchar*)"_tables", 1, NULL, NULL};
+  mcontext.column_names = g_new (gchar *, 1);
+  mcontext.column_names[0] = (gchar*)"table_schema";
+  mcontext.column_values = g_new (GValue *, 1);
+  g_value_set_string ((mcontext.column_values[0] = gda_value_new (G_TYPE_STRING)), table_name.c_str());
+  GError* gerror = 0;
+  bool retval = gda_connection_update_meta_store(gobj(), &mcontext, &gerror);
+
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+  #else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+  
+  return retval;
+}
+
 } //namespace Gda
 
 } //namespace Gnome

Modified: libgdamm/trunk/libgda/src/connection.hg
==============================================================================
--- libgdamm/trunk/libgda/src/connection.hg	(original)
+++ libgdamm/trunk/libgda/src/connection.hg	Thu Dec 25 11:10:18 2008
@@ -189,23 +189,41 @@
 
   _WRAP_METHOD(Glib::ustring get_provider_name() const, gda_connection_get_provider_name)
 
-  _WRAP_METHOD_DOCS_ONLY(gda_connection_update_meta_store)
-
   // This updated the full meta store, we have some more convience methods to
   // only update a portion of the store
+  _IGNORE(gda_connection_update_meta_store)
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  /** Update the full meta store information.
+   * 
+   * Note that this may take some time for big databases
+   * @return <tt>true</tt> if no error occurred.
+   */
   bool update_meta_store();
+  /** Update the meta store information @a id
+   * 
+   * This can speed up the update of the meta store if you only need a 
+   * specific information
+   * @param id An id for the information to update (see http://library.gnome.org/devel/libgda/unstable/information_schema.html)
+   * @return <tt>true</tt> if no error occurred.
+   */
   bool update_meta_store(const Glib::ustring& id);
-  bool update_meta_store_tables();
-  bool update_meta_store_types();
 #else
   bool update_meta_store(std::auto_ptr<Glib::Error>& err);
   bool update_meta_store(const Glib::ustring& id, std::auto_ptr<Glib::Error>& err);
-  bool update_meta_store_tables(std::auto_ptr<Glib::Error>& err);
-  bool update_meta_store_types();
 #endif
 
-  
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  /** Update the meta store information for the table named @a table_name
+   * 
+   * This can speed up the update of the meta store if you only need the information
+   * for a specific table
+   * @param table_name Name of the table where the information is needed
+   * @return <tt>true</tt> if no error occurred.
+   */
+  bool update_meta_store_table(const Glib::ustring& table_name);
+#else
+  bool update_meta_store_table(const Glib::ustring& table_name, std::auto_ptr<Glib::Error>& err);
+#endif
   
   _WRAP_METHOD(bool statement_prepare(const Glib::RefPtr<Statement>& stmt), gda_connection_statement_prepare, errthrow)
 
@@ -220,8 +238,8 @@
   Glib::RefPtr<DataModel> Connection::get_meta_store_data(ConnectionMetaType meta_type, std::auto_ptr<Glib::Error>& error);
   #endif //GLIBMM_EXCEPTIONS_ENABLED
 
-  _WRAP_METHOD(Glib::RefPtr<MetaStore> get_meta_store(), gda_connection_get_meta_store)
-  _WRAP_METHOD(Glib::RefPtr<const MetaStore> get_meta_store() const, gda_connection_get_meta_store, consversion)
+  _WRAP_METHOD(Glib::RefPtr<MetaStore> get_meta_store(), gda_connection_get_meta_store, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const MetaStore> get_meta_store() const, gda_connection_get_meta_store, constversion)
 
   #m4 _CONVERSION(`GSList*',`Glib::SListHandle< Glib::RefPtr<Glib::Object> >',`$2((GSList*)$3, Glib::OWNERSHIP_SHALLOW)')
   _WRAP_METHOD(Glib::SListHandle< Glib::RefPtr<Glib::Object> > batch_execute(const Glib::RefPtr<Batch>& batch, const Glib::RefPtr<Set>& params, StatementModelUsage model_usage), gda_connection_batch_execute, errthrow)

Modified: libgdamm/trunk/libgda/src/metastore.ccg
==============================================================================
--- libgdamm/trunk/libgda/src/metastore.ccg	(original)
+++ libgdamm/trunk/libgda/src/metastore.ccg	Thu Dec 25 11:10:18 2008
@@ -26,6 +26,26 @@
 
 namespace Gda
 {
+  
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<DataModel> MetaStore::extract(const Glib::ustring& sql)
+#else
+Glib::RefPtr<DataModel> MetaStore::extract(const Glib::ustring& sql, std::auto_ptr<Glib::Error>& err)
+#endif
+{
+  GError* gerror = 0;
+  bool retval = gda_meta_store_extract(gobj(), sql.c_str(), &gerror);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retval;
+}
+
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
 bool MetaStore::get_attribute_value(const Glib::ustring& att_name, Glib::ustring& att_value)
 #else

Modified: libgdamm/trunk/libgda/src/metastore.hg
==============================================================================
--- libgdamm/trunk/libgda/src/metastore.hg	(original)
+++ libgdamm/trunk/libgda/src/metastore.hg	Thu Dec 25 11:10:18 2008
@@ -60,8 +60,12 @@
   _WRAP_CREATE(const Glib::ustring& cnc_string)
   
   _WRAP_METHOD(int get_version() const, gda_meta_store_get_version)
-  //TODO: varargs: extract(), modify()
-  
+  _WRAP_METHOD_DOCS_ONLY (gda_meta_store_extract);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  Glib::RefPtr<DataModel> extract(const Glib::ustring& sql);
+#else
+  Glib::RefPtr<DataModel> extract(const Glib::ustring& sql, std::auto_ptr<Glib::Error>& err);
+#endif  
   _IGNORE (gda_meta_store_modify_with_context)
   //_WRAP_METHOD(bool modify_with_context (MetaContext* context, const Glib::RefPtr<DataModel>& new_data), gda_meta_store_modify_with_context, errthrow)
   _WRAP_METHOD(Glib::RefPtr<DataModel> create_modify_data_model(const Glib::ustring& table_name), gda_meta_store_create_modify_data_model)



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