libgda r3325 - in trunk: . doc/C/tmpl libgda libgda/handlers libgda/sqlite providers/mysql providers/postgres



Author: vivien
Date: Wed Feb 18 16:02:40 2009
New Revision: 3325
URL: http://svn.gnome.org/viewvc/libgda?rev=3325&view=rev

Log:
2009-02-18  Vivien Malerba <malerba gnome-db org>

	* doc/C: doc. improvements regarding GdaDataHandler
	* providers/mysql/gda-mysql-ddl.c:
	* providers/postgres/gda-postgres-ddl.c:
	* providers/postgres/gda-postgres-handler-bin.c:
	* libgda/sqlite/gda-sqlite-handler-bin.c:
	* libgda/handlers/gda-handler-type.c:
	* libgda/handlers/gda-handler-bin.c:
	* libgda/gda-data-handler.c;
	* libgda/gda-server-provider.c: make sure the
	gda_data_handler_get_sql_from_value() function is implemented in a
	coherent way, fixed bug #572220


Modified:
   trunk/ChangeLog
   trunk/doc/C/tmpl/gda-data-handler.sgml
   trunk/libgda/gda-data-handler.c
   trunk/libgda/gda-server-provider.c
   trunk/libgda/handlers/gda-handler-bin.c
   trunk/libgda/handlers/gda-handler-type.c
   trunk/libgda/sqlite/gda-sqlite-handler-bin.c
   trunk/providers/mysql/gda-mysql-ddl.c
   trunk/providers/postgres/gda-postgres-ddl.c
   trunk/providers/postgres/gda-postgres-handler-bin.c

Modified: trunk/doc/C/tmpl/gda-data-handler.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-data-handler.sgml	(original)
+++ trunk/doc/C/tmpl/gda-data-handler.sgml	Wed Feb 18 16:02:40 2009
@@ -2,38 +2,30 @@
 GdaDataHandler
 
 <!-- ##### SECTION Short_Description ##### -->
-Interface which provides data handling capabilities
+Interface which provides data handling (conversions) capabilities
 
 <!-- ##### SECTION Long_Description ##### -->
 <para>
   Because data types vary a lot from a DBMS to another, the #GdaDataHandler interface helps
-  designing modules which can handle very specific pieces of data through plugins.
-  Each object which imlements the #GdaDataHandler interface is expected to handle a subset of
-  the possible libgda defined data types.
+  managing data in its various representations, and converting from one to another:
+  <itemizedlist>
+    <listitem><para>as a #GValue which is a generic value container for the C language</para></listitem>
+    <listitem><para>as a human readable string</para></listitem>
+    <listitem><para>as an SQL string (a string which can be used in SQL statements)</para></listitem>
+  </itemizedlist>
 </para>
 <para>
-  The #GdaDataHandler object can convert a #GValue to and from both SQL and 'STR'. The SQL representation of a value is 
-  the actual string which would be used in an SQL statement (for example a string's SQL representation is surrounded by 
-  quotes such as 'that\'s a string'). The 'STR' representation is a human-readable representation of a value appropriate 
-  for the user's current locale. The 'STR' respresentation of a string is simply the original string without quotes but 
-  a numerical value or date, for instance, will be formatted according to the user's current locale.
-</para>
-<para>
-  Only one object which implements this interface is needed for any given data type, and it mainly contains some
-  methods to manage values (as #GValue structures). The #GnomeDbDataEntry interface is complementary to this one since
-  it it implemented by widgets where the user can enter or modify some data.
-</para>
-<para>
-  #GdaDataHandler objects specific for each database provider and for each data type can be obtained using 
+  For each data type, a corresponding #GdaDataHandler object can be requested using the
+  <link linkend="gda-get-default-handler">gda_get_default_handler()</link> function. However, when working
+  with a specific database provider, it's better to use a #GdaDataHandler which may be specific to the
+  database provider which will correctly handle each database specificities using
   <link linkend="gda-server-provider-get-data-handler-g-type">gda_server_provider_get_data_handler_g_type()</link> or
-  <link linkend="gda-server-provider-get-data-handler-dbms">gda_server_provider_get_data_handler_dbms()</link>, and
-  generic data handlers (for each type) can be obtained using
-  <link linkend="gda-get-default-handler">gda_get_default_handler()</link>.
+  <link linkend="gda-server-provider-get-data-handler-dbms">gda_server_provider_get_data_handler_dbms()</link>.
 </para>
 
 <!-- ##### SECTION See_Also ##### -->
 <para>
-The #GdaDictType class an the #GnomeDbDataEntry interface.
+
 </para>
 
 <!-- ##### SECTION Stability_Level ##### -->

Modified: trunk/libgda/gda-data-handler.c
==============================================================================
--- trunk/libgda/gda-data-handler.c	(original)
+++ trunk/libgda/gda-data-handler.c	Wed Feb 18 16:02:40 2009
@@ -69,10 +69,15 @@
  * @dh: an object which implements the #GdaDataHandler interface
  * @value: the value to be converted to a string
  *
- * Creates a new string which is an SQL representation of the given value. If the value is NULL or
- * is of type GDA_TYPE_NULL, the returned string is NULL.
+ * Creates a new string which is an SQL representation of the given value, the returned string
+ * can be used directly in an SQL statement. For example if @value is a G_TYPE_STRING, then
+ * the returned string will be correctly quoted. Note however that it is a better practice
+ * to use variables in statements instead of value literals, see
+ * the <link linkend="GdaSqlParser.description">GdaSqlParser</link> for more information.
  *
- * Returns: the new string.
+ * If the value is NULL or is of type GDA_TYPE_NULL, the returned string is "NULL".
+ *
+ * Returns: the new string, or %NULL if an error occurred
  */
 gchar *
 gda_data_handler_get_sql_from_value (GdaDataHandler *dh, const GValue *value)
@@ -80,7 +85,7 @@
 	g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
 	
 	if (! value || gda_value_is_null (value))
-		return NULL;
+		return g_strdup ("NULL");
 
 	/* Calling the real function with value != NULL and not of type GDA_TYPE_NULL */
 	if (GDA_DATA_HANDLER_GET_IFACE (dh)->get_sql_from_value)
@@ -98,7 +103,7 @@
  * (in the users's locale, specially for the dates). If the value is 
  * NULL or is of type GDA_TYPE_NULL, the returned string is a copy of "" (empty string).
  *
- * Returns: the new string.
+ * Returns: the new string, or %NULL if an error occurred
  */
 gchar *
 gda_data_handler_get_str_from_value (GdaDataHandler *dh, const GValue *value)
@@ -127,7 +132,7 @@
  *
  * If the sql string is NULL, then the returned GValue is of type GDA_TYPE_NULL;
  * if the sql string does not correspond to a valid SQL string for the requested type, then
- * NULL is returned.
+ * the "NULL" string is returned.
  *
  * Returns: the new GValue or NULL on error
  */

Modified: trunk/libgda/gda-server-provider.c
==============================================================================
--- trunk/libgda/gda-server-provider.c	(original)
+++ trunk/libgda/gda-server-provider.c	Wed Feb 18 16:02:40 2009
@@ -785,7 +785,7 @@
 				gchar *tmp;
 				
 				tmp = gda_data_handler_get_sql_from_value (dh, retval);
-				if (strcmp (tmp, string)) {
+				if (!tmp || strcmp (tmp, string)) {
 					gda_value_free (retval);
 					retval = NULL;
 				}
@@ -831,7 +831,7 @@
 					gchar *tmp;
 					
 					tmp = gda_data_handler_get_sql_from_value (dh, retval);
-					if (strcmp (tmp, string)) {
+					if (!tmp || strcmp (tmp, string)) {
 						gda_value_free (retval);
 						retval = NULL;
 					}

Modified: trunk/libgda/handlers/gda-handler-bin.c
==============================================================================
--- trunk/libgda/handlers/gda-handler-bin.c	(original)
+++ trunk/libgda/handlers/gda-handler-bin.c	Wed Feb 18 16:02:40 2009
@@ -198,7 +198,7 @@
 		}
 	}
 	else
-		retval = g_strdup (NULL);
+		retval = g_strdup ("NULL");
 
 	return retval;
 }

Modified: trunk/libgda/handlers/gda-handler-type.c
==============================================================================
--- trunk/libgda/handlers/gda-handler-type.c	(original)
+++ trunk/libgda/handlers/gda-handler-type.c	Wed Feb 18 16:02:40 2009
@@ -179,10 +179,10 @@
 			retval = g_strdup_printf ("'%s'", str);
 		}
 		else
-			retval = g_strdup (NULL);	
+			retval = g_strdup ("NULL");	
 	}
 	else
-		retval = g_strdup (NULL);
+		retval = g_strdup ("NULL");
 
 	return retval;
 }

Modified: trunk/libgda/sqlite/gda-sqlite-handler-bin.c
==============================================================================
--- trunk/libgda/sqlite/gda-sqlite-handler-bin.c	(original)
+++ trunk/libgda/sqlite/gda-sqlite-handler-bin.c	Wed Feb 18 16:02:40 2009
@@ -195,7 +195,7 @@
 		retval [bin->binary_length * 2 + 2] = '\'';
 	}
 	else
-		retval = g_strdup (NULL);
+		retval = g_strdup ("NULL");
 
 	return retval;
 }
@@ -232,7 +232,7 @@
 		}
 	}
 	else
-		retval = g_strdup (NULL);
+		retval = g_strdup ("");
 
 	return retval;
 }

Modified: trunk/providers/mysql/gda-mysql-ddl.c
==============================================================================
--- trunk/providers/mysql/gda-mysql-ddl.c	(original)
+++ trunk/providers/mysql/gda-mysql-ddl.c	Wed Feb 18 16:02:40 2009
@@ -354,9 +354,11 @@
 
 			dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
 			str = gda_data_handler_get_sql_from_value (dh, value);
-			g_string_append (string, " COMMENT = ");
-			g_string_append (string, str);
-			g_free (str);
+			if (str) {
+				g_string_append (string, " COMMENT = ");
+				g_string_append (string, str);
+				g_free (str);
+			}
 		}
 
 		value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_MAX_ROWS");
@@ -382,9 +384,11 @@
 
 			dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
 			str = gda_data_handler_get_sql_from_value (dh, value);
-			g_string_append (string, " PASSWORD = ");
-			g_string_append (string, str);
-			g_free (str);
+			if (str) {
+				g_string_append (string, " PASSWORD = ");
+				g_string_append (string, str);
+				g_free (str);
+			}
 		}
 
 		value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_DELAY_KEY_WRITE");
@@ -420,9 +424,11 @@
 
 			dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
 			str = gda_data_handler_get_sql_from_value (dh, value);
-			g_string_append (string, " DATA_DIRECTORY = ");
-			g_string_append (string, str);
-			g_free (str);
+			if (str) {
+				g_string_append (string, " DATA_DIRECTORY = ");
+				g_string_append (string, str);
+				g_free (str);
+			}
 		}
 
 		value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_INDEX_DIR");
@@ -433,9 +439,11 @@
 
 			dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
 			str = gda_data_handler_get_sql_from_value (dh, value);
-			g_string_append (string, " INDEX_DIRECTORY = ");
-			g_string_append (string, str);
-			g_free (str);
+			if (str) {
+				g_string_append (string, " INDEX_DIRECTORY = ");
+				g_string_append (string, str);
+				g_free (str);
+			}
 		}
 	}
 

Modified: trunk/providers/postgres/gda-postgres-ddl.c
==============================================================================
--- trunk/providers/postgres/gda-postgres-ddl.c	(original)
+++ trunk/providers/postgres/gda-postgres-ddl.c	Wed Feb 18 16:02:40 2009
@@ -57,10 +57,11 @@
 		
 		dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
 		str = gda_data_handler_get_sql_from_value (dh, value);
-
-		g_string_append (string, " ENCODING ");
-		g_string_append (string, str);
-		g_free (str);
+		if (str) {
+			g_string_append (string, " ENCODING ");
+			g_string_append (string, str);
+			g_free (str);
+		}
 	}
 
 	value = gda_server_operation_get_value_at (op, "/DB_DEF_P/TABLESPACE");

Modified: trunk/providers/postgres/gda-postgres-handler-bin.c
==============================================================================
--- trunk/providers/postgres/gda-postgres-handler-bin.c	(original)
+++ trunk/providers/postgres/gda-postgres-handler-bin.c	Wed Feb 18 16:02:40 2009
@@ -220,13 +220,13 @@
 				}
 			}
 			else
-				retval = g_strdup (NULL);
+				retval = g_strdup ("NULL");
 		}
 		else
 			retval = g_strdup ("**BLOB**");	
 	}
 	else
-		retval = g_strdup (NULL);
+		retval = g_strdup ("NULL");
 
 	return retval;
 }



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