Re: [gnome-db] database xml - database version property



Hi Rodrigo,

I made the modification so that "gda-xml-database" creates a new
database property named "user_version".
I preferred to keep the previous property (version) as it was (libgda
version number) to avoid potential problems with existing applications
testing this value.
Now, the user application may define a "user_version" of the database
using the couple of functions :

"gda-xml-database-set-user-version()" and
"gda-xml-database-get-user-version()".

The function "gda-xml-database-set-version()" is removed and
"gda-xml-database-get-version()" gives the libgda version used to create
the database.

Patches for "gda-xml-database.h" and "gda-xml-database.c" attached to
the mail.

WARNING :

I tested the new version, it works but I am quite new to programmation
(first time I make a patch ;-), so please check if I do not mess
something with the code or with the patch creation.

Philippe

Le jeu 21/08/2003 à 18:08, Rodrigo Moya a écrit :
> On Thu, 2003-08-21 at 15:10 +0200, Philippe CHARLIER wrote:
> > [From thread "database xml"]
> > 
> > Hi,
> > 
> > The change made to line 498 of the file "gda-xml-database.c", in the
> > function "gda_xml_database_to_string()" solves the problem but render
> > the function "gda-database-set-version()" useless.
> > 
> well, in fact, I think set_version should be removed, since the version
> field is an information field, used to know the version used to create
> the file.
> 
> So I think we should probably remove it. Or is there any case where you
> want to set an explicit version number?
> 
> > In fact, the user cannot define the version of the database, with this
> > code, the version is always <database name="name" version="xxxx"> with
> > xxxx being the libgda version number (0.91.0 f.e.).
> > 
> > Is it not possible to have something like below ?
> > 
> > <database name="name" gdaversion="xxxx" version="yyyy"> with xxxx being
> > the libgda version number and yyyy the database version defined by the
> > application.
> > 
> yes, that's possible. If you want, please make the changes yourself and
> send the patch to the list. It would just mean replacing the 'version'
> field with 'gdaversion', and then having the get_version/set_version
> work on the new 'version' field on the XML file.
> 
> Also, a gda_xml_database_get_gda_version would be needed then.
> 
> > This way, if the application modifies its way of saving data, by keeping
> > track of the database version, it will be possible to find out if the
> > actual version of the application is able to read the xml file or if it
> > needs a filter to convert the database to the new format.
> > 
> yes, sounds good.
> 
> > But this, of course, needs other modifications to add the property
> > "gdaversion" (GdaXmlDatabasePrivate, I suppose ... and may be more), so
> > I do not know if this is possible. 
> > 
> yes, it's perfectly possible. Just make the current 'version' be
> replaced by 'gdaversion' and add the 'get_gda_version' function. That's
> all.
> 
> cheers
> 
*** gda-xml-database_0.91.0.c	2003-08-21 20:30:37.000000000 +0200
--- gda-xml-database.c	2003-08-21 20:54:12.000000000 +0200
***************
*** 29,34 ****
--- 29,35 ----
  struct _GdaXmlDatabasePrivate {
  	gchar *uri;
  	gchar *name;
+ 	gchar *user_version;
  	gchar *version;
  	GHashTable *tables;
  	GHashTable *views;
***************
*** 45,62 ****
  #define OBJECT_VIEW         "view"
  #define OBJECT_VIEWS_NODE   "views"
  
! #define PROPERTY_ALLOW_NULL  "isnull"
! #define PROPERTY_AUTO        "auto_increment"
! #define PROPERTY_CAPTION     "caption"
! #define PROPERTY_GDATYPE     "gdatype"
! #define PROPERTY_NAME        "name"
! #define PROPERTY_OWNER       "owner"
! #define PROPERTY_PRIMARY_KEY "pkey"
! #define PROPERTY_REFERENCES  "references"
! #define PROPERTY_SCALE       "scale"
! #define PROPERTY_SIZE        "size"
! #define PROPERTY_UNIQUE_KEY  "unique"
! #define PROPERTY_VERSION     "version"
  
  static void gda_xml_database_class_init (GdaXmlDatabaseClass *klass);
  static void gda_xml_database_init       (GdaXmlDatabase *xmldb, GdaXmlDatabaseClass *klass);
--- 46,64 ----
  #define OBJECT_VIEW         "view"
  #define OBJECT_VIEWS_NODE   "views"
  
! #define PROPERTY_ALLOW_NULL   "isnull"
! #define PROPERTY_AUTO         "auto_increment"
! #define PROPERTY_CAPTION      "caption"
! #define PROPERTY_GDATYPE      "gdatype"
! #define PROPERTY_NAME         "name"
! #define PROPERTY_OWNER        "owner"
! #define PROPERTY_PRIMARY_KEY  "pkey"
! #define PROPERTY_REFERENCES   "references"
! #define PROPERTY_SCALE        "scale"
! #define PROPERTY_SIZE         "size"
! #define PROPERTY_UNIQUE_KEY   "unique"
! #define PROPERTY_VERSION      "version"
! #define PROPERTY_USER_VERSION "user_version"
  
  static void gda_xml_database_class_init (GdaXmlDatabaseClass *klass);
  static void gda_xml_database_init       (GdaXmlDatabase *xmldb, GdaXmlDatabaseClass *klass);
***************
*** 148,153 ****
--- 150,156 ----
  	xmldb->priv = g_new0 (GdaXmlDatabasePrivate, 1);
  	xmldb->priv->uri = NULL;
  	xmldb->priv->name = NULL;
+ 	xmldb->priv->user_version = NULL;
  	xmldb->priv->version = NULL;
  	xmldb->priv->tables = g_hash_table_new (g_str_hash, g_str_equal);
  	xmldb->priv->views = g_hash_table_new (g_str_hash, g_str_equal);
***************
*** 181,186 ****
--- 184,194 ----
  		xmldb->priv->name = NULL;
  	}
  
+ 	if (xmldb->priv->user_version) {
+ 		g_free (xmldb->priv->user_version);
+ 		xmldb->priv->user_version = NULL;
+ 	}
+ 
  	if (xmldb->priv->version) {
  		g_free (xmldb->priv->version);
  		xmldb->priv->version = NULL;
***************
*** 285,290 ****
--- 293,299 ----
  	}
  
  	xmldb->priv->name = g_strdup (xmlGetProp (root, PROPERTY_NAME));
+ 	xmldb->priv->user_version = g_strdup  (xmlGetProp (root, PROPERTY_USER_VERSION));
  	xmldb->priv->version = g_strdup  (xmlGetProp (root, PROPERTY_VERSION));
  	node = root->xmlChildrenNode;
  	while (node) {
***************
*** 348,389 ****
  }
  
  /**
!  * gda_xml_database_get_version
   * @xmldb: XML database.
   *
!  * Get the version of the given #GdaXmlDatabase object. This version is the
!  * one that was used for saving the XML file last time it was saved.
   *
!  * Returns: the database version.
   */
  const gchar *
! gda_xml_database_get_version (GdaXmlDatabase *xmldb)
  {
  	g_return_val_if_fail (GDA_IS_XML_DATABASE (xmldb), NULL);
! 	return (const gchar *) xmldb->priv->version;
  }
  
  /**
!  * gda_xml_database_set_version
   * @xmldb: XML database.
!  * @version: Version string.
   *
!  * Set the version of the given XML database.
   */
  void
! gda_xml_database_set_version (GdaXmlDatabase *xmldb, const gchar *version)
  {
  	g_return_if_fail (GDA_IS_XML_DATABASE (xmldb));
! 	g_return_if_fail (version != NULL);
  
! 	if (xmldb->priv->version)
! 		g_free (xmldb->priv->version);
! 	xmldb->priv->version = g_strdup (version);
  
  	gda_xml_database_changed (xmldb);
  }
  
  /**
   * gda_xml_database_get_uri
   * @xmldb: XML database.
   *
--- 357,417 ----
  }
  
  /**
!  * gda_xml_database_get_user_version
   * @xmldb: XML database.
   *
!  * Get the user defined version of the given #GdaXmlDatabase object.
   *
!  * Returns: the database version defined by the user.
   */
  const gchar *
! gda_xml_database_get_user_version (GdaXmlDatabase *xmldb)
  {
  	g_return_val_if_fail (GDA_IS_XML_DATABASE (xmldb), NULL);
! 	return (const gchar *) xmldb->priv->user_version;
  }
  
  /**
!  * gda_xml_database_set_user_version
   * @xmldb: XML database.
!  * @user_version: User defined Version string.
   *
!  * Set the user defined version of the given XML database.
   */
  void
! gda_xml_database_set_user_version (GdaXmlDatabase *xmldb, const gchar *user_version)
  {
  	g_return_if_fail (GDA_IS_XML_DATABASE (xmldb));
! 	g_return_if_fail (user_version != NULL);
  
! 	if (xmldb->priv->user_version)
! 		g_free (xmldb->priv->user_version);
! 	xmldb->priv->user_version = g_strdup (user_version);
  
  	gda_xml_database_changed (xmldb);
  }
  
  /**
+  * gda_xml_database_get_version
+  * @xmldb: XML database.
+  *
+  * Get the version of libgda used to create the #GdaXmlDatabase object.
+  * This version is the one that was used for saving the XML file last 
+  * time it was saved. This value can only be "get" as it is an internal
+  * information related to the creation of the #GdaXmlDatabase object.
+  * To get the user defined database version, use the function
+  * gda_xml_database_get_user_version instead.
+  *
+  * Returns: the libgda version used to create the database.
+  */
+ const gchar *
+ gda_xml_database_get_version (GdaXmlDatabase *xmldb)
+ {
+ 	g_return_val_if_fail (GDA_IS_XML_DATABASE (xmldb), NULL);
+ 	return (const gchar *) xmldb->priv->version;
+ }
+ 
+ /**
   * gda_xml_database_get_uri
   * @xmldb: XML database.
   *
***************
*** 457,463 ****
  
  	g_return_val_if_fail (GDA_IS_XML_DATABASE (xmldb), FALSE);
  
- 	gda_xml_database_set_version (xmldb, VERSION);
  	xml = gda_xml_database_to_string (xmldb);
  	if (xml) {
  		result = gda_file_save (uri, xml, strlen (xml));
--- 485,490 ----
***************
*** 495,500 ****
--- 522,528 ----
  	doc = xmlNewDoc ("1.0");
  	root = xmlNewDocNode (doc, NULL, OBJECT_DATABASE, NULL);
  	xmlSetProp (root, PROPERTY_NAME, xmldb->priv->name);
+ 	xmlSetProp (root, PROPERTY_USER_VERSION, xmldb->priv->user_version);
  	xmlSetProp (root, PROPERTY_VERSION, VERSION);
  	xmlDocSetRootElement (doc, root);
  
*** gda-xml-database_0.91.0.h	2003-08-21 20:30:07.000000000 +0200
--- gda-xml-database.h	2003-08-21 20:53:39.000000000 +0200
***************
*** 58,65 ****
  
  const gchar    *gda_xml_database_get_name (GdaXmlDatabase *xmldb);
  void            gda_xml_database_set_name (GdaXmlDatabase *xmldb, const gchar *name);
  const gchar    *gda_xml_database_get_version (GdaXmlDatabase *xmldb);
- void            gda_xml_database_set_version (GdaXmlDatabase *xmldb, const gchar *version);
  const gchar    *gda_xml_database_get_uri (GdaXmlDatabase *xmldb);
  void            gda_xml_database_set_uri (GdaXmlDatabase *xmldb, const gchar *uri);
  void            gda_xml_database_changed (GdaXmlDatabase *xmldb);
--- 58,66 ----
  
  const gchar    *gda_xml_database_get_name (GdaXmlDatabase *xmldb);
  void            gda_xml_database_set_name (GdaXmlDatabase *xmldb, const gchar *name);
+ const gchar    *gda_xml_database_get_user_version (GdaXmlDatabase *xmldb);
+ void            gda_xml_database_set_user_version (GdaXmlDatabase *xmldb, const gchar *user_version);
  const gchar    *gda_xml_database_get_version (GdaXmlDatabase *xmldb);
  const gchar    *gda_xml_database_get_uri (GdaXmlDatabase *xmldb);
  void            gda_xml_database_set_uri (GdaXmlDatabase *xmldb, const gchar *uri);
  void            gda_xml_database_changed (GdaXmlDatabase *xmldb);


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