[libgda] GdaDataHandler code cleanups
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaDataHandler code cleanups
- Date: Sun, 6 Jan 2013 14:51:10 +0000 (UTC)
commit e2078146ddeeb4476425908a6468ae8619e21941
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Jan 4 21:54:57 2013 +0100
GdaDataHandler code cleanups
libgda/gda-data-handler.c | 31 +++--
libgda/handlers/gda-handler-bin.c | 151 +++++++-----------
libgda/handlers/gda-handler-boolean.c | 92 +++--------
libgda/handlers/gda-handler-numerical.c | 77 +++------
libgda/handlers/gda-handler-string.c | 91 +++--------
libgda/handlers/gda-handler-time.c | 77 ++++-----
libgda/handlers/gda-handler-type.c | 116 ++++---------
libgda/sqlite/gda-sqlite-handler-bin.c | 220 +++++++++----------------
libgda/sqlite/gda-sqlite-handler-boolean.c | 96 ++---------
providers/mysql/gda-mysql-handler-boolean.c | 93 ++---------
providers/postgres/gda-postgres-handler-bin.c | 182 +++++++--------------
providers/postgres/gda-postgres-provider.c | 10 +-
12 files changed, 393 insertions(+), 843 deletions(-)
---
diff --git a/libgda/gda-data-handler.c b/libgda/gda-data-handler.c
index 97e606e..66fc101 100644
--- a/libgda/gda-data-handler.c
+++ b/libgda/gda-data-handler.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
@@ -101,10 +101,12 @@ gchar *
gda_data_handler_get_sql_from_value (GdaDataHandler *dh, const GValue *value)
{
g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
-
+
if (! value || gda_value_is_null (value))
return g_strdup ("NULL");
+ g_return_val_if_fail (_accepts_g_type (dh, G_VALUE_TYPE (value)), 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)
return (GDA_DATA_HANDLER_GET_IFACE (dh)->get_sql_from_value) (dh, value);
@@ -131,6 +133,8 @@ gda_data_handler_get_str_from_value (GdaDataHandler *dh, const GValue *value)
if (! value || gda_value_is_null (value))
return g_strdup ("");
+ g_return_val_if_fail (_accepts_g_type (dh, G_VALUE_TYPE (value)), NULL);
+
/* Calling the real function with value != NULL and not of type GDA_TYPE_NULL */
if (GDA_DATA_HANDLER_GET_IFACE (dh)->get_str_from_value)
return (GDA_DATA_HANDLER_GET_IFACE (dh)->get_str_from_value) (dh, value);
@@ -158,7 +162,7 @@ GValue *
gda_data_handler_get_value_from_sql (GdaDataHandler *dh, const gchar *sql, GType type)
{
g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
- g_return_val_if_fail (gda_data_handler_accepts_g_type (GDA_DATA_HANDLER (dh), type), NULL);
+ g_return_val_if_fail (_accepts_g_type (dh, type), NULL);
if (!sql)
return gda_value_new_null ();
@@ -190,7 +194,7 @@ GValue *
gda_data_handler_get_value_from_str (GdaDataHandler *dh, const gchar *str, GType type)
{
g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
- g_return_val_if_fail (gda_data_handler_accepts_g_type (GDA_DATA_HANDLER (dh), type), NULL);
+ g_return_val_if_fail (_accepts_g_type (dh, type), NULL);
if (!str)
return gda_value_new_null ();
@@ -222,7 +226,7 @@ GValue *
gda_data_handler_get_sane_init_value (GdaDataHandler *dh, GType type)
{
g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
- g_return_val_if_fail (gda_data_handler_accepts_g_type (GDA_DATA_HANDLER (dh), type), NULL);
+ g_return_val_if_fail (_accepts_g_type (dh, type), NULL);
if (GDA_DATA_HANDLER_GET_IFACE (dh)->get_sane_init_value)
return (GDA_DATA_HANDLER_GET_IFACE (dh)->get_sane_init_value) (dh, type);
@@ -230,6 +234,15 @@ gda_data_handler_get_sane_init_value (GdaDataHandler *dh, GType type)
return NULL;
}
+static gboolean
+_accepts_g_type (GdaDataHandler *dh, GType type)
+{
+ if (GDA_DATA_HANDLER_GET_IFACE (dh)->accepts_g_type)
+ return (GDA_DATA_HANDLER_GET_IFACE (dh)->accepts_g_type) (dh, type);
+ else
+ return FALSE;
+}
+
/**
* gda_data_handler_accepts_g_type:
* @dh: an object which implements the #GdaDataHandler interface
@@ -242,12 +255,8 @@ gda_data_handler_get_sane_init_value (GdaDataHandler *dh, GType type)
gboolean
gda_data_handler_accepts_g_type (GdaDataHandler *dh, GType type)
{
- g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), FALSE);
-
- if (GDA_DATA_HANDLER_GET_IFACE (dh)->accepts_g_type)
- return (GDA_DATA_HANDLER_GET_IFACE (dh)->accepts_g_type) (dh, type);
-
- return FALSE;
+ g_return_val_if_fail (GDA_IS_DATA_HANDLER (dh), FALSE);
+ return _accepts_g_type (dh, type);
}
/**
diff --git a/libgda/handlers/gda-handler-bin.c b/libgda/handlers/gda-handler-bin.c
index 081a6e7..eb8dd6b 100644
--- a/libgda/handlers/gda-handler-bin.c
+++ b/libgda/handlers/gda-handler-bin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
@@ -47,7 +47,6 @@ static gboolean gda_handler_bin_accepts_g_type (GdaDataHandler * dh, G
static const gchar *gda_handler_bin_get_descr (GdaDataHandler *dh);
struct _GdaHandlerBinPriv {
- gchar *detailed_descr;
guint nb_g_types;
GType *valid_g_types;
};
@@ -72,7 +71,7 @@ gda_handler_bin_get_type (void)
sizeof (GdaHandlerBin),
0,
(GInstanceInitFunc) gda_handler_bin_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -119,7 +118,6 @@ gda_handler_bin_init (GdaHandlerBin * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerBinPriv, 1);
- hdl->priv->detailed_descr = _("Binary handler");
hdl->priv->nb_g_types = 2;
hdl->priv->valid_g_types = g_new0 (GType, hdl->priv->nb_g_types);
hdl->priv->valid_g_types[0] = GDA_TYPE_BINARY;
@@ -170,57 +168,45 @@ gda_handler_bin_new (void)
static gchar *
-gda_handler_bin_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_bin_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaHandlerBin *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), NULL);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (value) {
- if (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY)) {
- gchar *str, *str2;
- str = gda_binary_to_string (gda_value_get_binary ((GValue *) value), 0);
- str2 = gda_default_escape_string (str);
- g_free (str);
- retval = g_strdup_printf ("'%s'", str2);
- g_free (str2);
- }
- else {
- GdaBlob *blob;
- GdaBinary *bin;
- blob = (GdaBlob*) gda_value_get_blob ((GValue *) value);
- bin = (GdaBinary *) blob;
- if (blob->op &&
- (bin->binary_length != gda_blob_op_get_length (blob->op)))
- gda_blob_op_read_all (blob->op, blob);
+ g_assert (value);
- gchar *str, *str2;
- str = gda_binary_to_string (bin, 0);
- str2 = gda_default_escape_string (str);
- g_free (str);
- retval = g_strdup_printf ("'%s'", str2);
- g_free (str2);
- }
+ gchar *retval;
+ if (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY)) {
+ gchar *str, *str2;
+ str = gda_binary_to_string (gda_value_get_binary ((GValue *) value), 0);
+ str2 = gda_default_escape_string (str);
+ g_free (str);
+ retval = g_strdup_printf ("'%s'", str2);
+ g_free (str2);
+ }
+ else {
+ GdaBlob *blob;
+ GdaBinary *bin;
+ blob = (GdaBlob*) gda_value_get_blob ((GValue *) value);
+ bin = (GdaBinary *) blob;
+ if (blob->op &&
+ (bin->binary_length != gda_blob_op_get_length (blob->op)))
+ gda_blob_op_read_all (blob->op, blob);
+
+ gchar *str, *str2;
+ str = gda_binary_to_string (bin, 0);
+ str2 = gda_default_escape_string (str);
+ g_free (str);
+ retval = g_strdup_printf ("'%s'", str2);
+ g_free (str2);
}
- else
- retval = g_strdup ("NULL");
return retval;
}
static gchar *
-gda_handler_bin_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_bin_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaHandlerBin *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), NULL);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (value);
+ gchar *retval = NULL;
if (value) {
if (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY))
retval = gda_binary_to_string (gda_value_get_binary ((GValue *) value), 0);
@@ -232,38 +218,29 @@ gda_handler_bin_get_str_from_value (GdaDataHandler *iface, const GValue *value)
retval = gda_binary_to_string ((GdaBinary *) blob, 0);
}
}
- else
- retval = g_strdup (NULL);
return retval;
}
static GValue *
-gda_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GType type)
+gda_handler_bin_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, GType type)
{
- GdaHandlerBin *hdl;
- GValue *value = NULL;
+ g_assert (sql);
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), NULL);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if ((type == GDA_TYPE_BINARY) ||
- (type == GDA_TYPE_BLOB)) {
- if (sql && *sql) {
- gint i = strlen (sql);
- if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
- gchar *str = g_strdup (sql);
- gchar *unstr;
-
- str[i-1] = 0;
- unstr = gda_default_unescape_string (str+1);
- if (unstr) {
- value = gda_handler_bin_get_value_from_str (iface, unstr, type);
- g_free (unstr);
- }
- g_free (str);
+ GValue *value = NULL;
+ if (*sql) {
+ gint i = strlen (sql);
+ if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
+ gchar *str = g_strdup (sql);
+ gchar *unstr;
+
+ str[i-1] = 0;
+ unstr = gda_default_unescape_string (str+1);
+ if (unstr) {
+ value = gda_handler_bin_get_value_from_str (iface, unstr, type);
+ g_free (unstr);
}
+ g_free (str);
}
}
@@ -271,15 +248,11 @@ gda_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GTy
}
static GValue *
-gda_handler_bin_get_value_from_str (GdaDataHandler *iface, const gchar *str, GType type)
+gda_handler_bin_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, GType type)
{
- GdaHandlerBin *hdl;
- GValue *value = NULL;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), NULL);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (str);
+ GValue *value = NULL;
if (type == GDA_TYPE_BINARY) {
GdaBinary *bin;
bin = gda_string_to_binary (str);
@@ -288,7 +261,7 @@ gda_handler_bin_get_value_from_str (GdaDataHandler *iface, const gchar *str, GTy
gda_value_take_binary (value, bin);
}
}
- else if (type == GDA_TYPE_BLOB) {
+ else {
GdaBlob *blob;
blob = gda_string_to_blob (str);
if (blob) {
@@ -304,30 +277,22 @@ static gboolean
gda_handler_bin_accepts_g_type (GdaDataHandler *iface, GType type)
{
GdaHandlerBin *hdl;
- guint i = 0;
- gboolean found = FALSE;
+ guint i;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), FALSE);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, 0);
+ g_assert (iface);
+ hdl = (GdaHandlerBin*) (iface);
- while (!found && (i < hdl->priv->nb_g_types)) {
+ for (i = 0; i < hdl->priv->nb_g_types; i++) {
if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
+ return TRUE;
}
- return found;
+ return FALSE;
}
static const gchar *
gda_handler_bin_get_descr (GdaDataHandler *iface)
{
- GdaHandlerBin *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BIN (iface), NULL);
- hdl = GDA_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_BIN (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/handlers/gda-handler-boolean.c b/libgda/handlers/gda-handler-boolean.c
index 6c615c5..0ddff95 100644
--- a/libgda/handlers/gda-handler-boolean.c
+++ b/libgda/handlers/gda-handler-boolean.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 Rodrigo Moya <rodrigo gnome-db org>
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
@@ -47,9 +47,7 @@ static gboolean gda_handler_boolean_accepts_g_type (GdaDataHandler * d
static const gchar *gda_handler_boolean_get_descr (GdaDataHandler *dh);
struct _GdaHandlerBooleanPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
+ gchar dummy;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -72,7 +70,7 @@ gda_handler_boolean_get_type (void)
sizeof (GdaHandlerBoolean),
0,
(GInstanceInitFunc) gda_handler_boolean_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -119,10 +117,6 @@ gda_handler_boolean_init (GdaHandlerBoolean *hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerBooleanPriv, 1);
- hdl->priv->detailed_descr = _("Boolean values handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, 1);
- hdl->priv->valid_g_types[0] = G_TYPE_BOOLEAN;
g_object_set_data (G_OBJECT (hdl), "name", "InternalBoolean");
g_object_set_data (G_OBJECT (hdl), "descr", _("Boolean representation"));
@@ -138,9 +132,6 @@ gda_handler_boolean_dispose (GObject *object)
hdl = GDA_HANDLER_BOOLEAN (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
g_free (hdl->priv);
hdl->priv = NULL;
}
@@ -167,15 +158,11 @@ gda_handler_boolean_new (void)
}
static gchar *
-gda_handler_boolean_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_boolean_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaHandlerBoolean *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (value);
+ gchar *retval;
if (g_value_get_boolean (value))
retval = g_strdup ("TRUE");
else
@@ -185,46 +172,34 @@ gda_handler_boolean_get_sql_from_value (GdaDataHandler *iface, const GValue *val
}
static gchar *
-gda_handler_boolean_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_boolean_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- GdaHandlerBoolean *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
+ g_assert (value);
return gda_value_stringify ((GValue *) value);
}
static GValue *
-gda_handler_boolean_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
+gda_handler_boolean_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
{
- GdaHandlerBoolean *hdl;
- GValue *value;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (sql);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
if ((*sql == 't') || (*sql == 'T'))
g_value_set_boolean (value, TRUE);
else
g_value_set_boolean (value, FALSE);
+
return value;
}
static GValue *
-gda_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
+gda_handler_boolean_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
{
- GdaHandlerBoolean *hdl;
- GValue *value = NULL;
- gchar *lcstr;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (str);
+ GValue *value;
+ gchar *lcstr;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
lcstr = g_utf8_strdown (str, -1);
if (!strcmp (lcstr, "true") || (*lcstr == 't'))
@@ -236,15 +211,10 @@ gda_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gchar *str,
static GValue *
-gda_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNUSED GType type)
+gda_handler_boolean_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, G_GNUC_UNUSED GType type)
{
- GdaHandlerBoolean *hdl;
GValue *value;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
g_value_set_boolean (value, FALSE);
@@ -252,33 +222,15 @@ gda_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNUSED GT
}
static gboolean
-gda_handler_boolean_accepts_g_type (GdaDataHandler *iface, GType type)
+gda_handler_boolean_accepts_g_type (G_GNUC_UNUSED GdaDataHandler *iface, GType type)
{
- GdaHandlerBoolean *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), FALSE);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == G_TYPE_BOOLEAN ? TRUE : FALSE;
}
static const gchar *
gda_handler_boolean_get_descr (GdaDataHandler *iface)
{
- GdaHandlerBoolean *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_BOOLEAN (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/handlers/gda-handler-numerical.c b/libgda/handlers/gda-handler-numerical.c
index ea55210..8b61ade 100644
--- a/libgda/handlers/gda-handler-numerical.c
+++ b/libgda/handlers/gda-handler-numerical.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 Rodrigo Moya <rodrigo gnome-db org>
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 - 2011 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
@@ -48,7 +48,6 @@ static gboolean gda_handler_numerical_accepts_g_type (GdaDataHandler *
static const gchar *gda_handler_numerical_get_descr (GdaDataHandler *dh);
struct _GdaHandlerNumericalPriv {
- gchar *detailed_descr;
guint nb_g_types;
GType *valid_g_types;
};
@@ -73,7 +72,7 @@ gda_handler_numerical_get_type (void)
sizeof (GdaHandlerNumerical),
0,
(GInstanceInitFunc) gda_handler_numerical_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -120,7 +119,6 @@ gda_handler_numerical_init (GdaHandlerNumerical * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerNumericalPriv, 1);
- hdl->priv->detailed_descr = "";
hdl->priv->nb_g_types = 13;
hdl->priv->valid_g_types = g_new0 (GType, hdl->priv->nb_g_types);
hdl->priv->valid_g_types[0] = G_TYPE_INT64;
@@ -183,43 +181,34 @@ gda_handler_numerical_new (void)
/* Interface implementation */
static gchar *
-gda_handler_numerical_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_numerical_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *str, *retval;
- GdaHandlerNumerical *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), NULL);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (value);
+ gchar *retval;
setlocale (LC_NUMERIC, "C");
- str = gda_value_stringify ((GValue *) value);
+ retval = gda_value_stringify ((GValue *) value);
setlocale (LC_NUMERIC, gda_numeric_locale);
- if (str)
- retval = str;
- else
+
+ if (!retval)
retval = g_strdup ("0");
return retval;
}
static gchar *
-gda_handler_numerical_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_numerical_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- GdaHandlerNumerical *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), NULL);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
+ g_assert (value);
return gda_value_stringify ((GValue *) value);
}
static GValue *
-gda_handler_numerical_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GType type)
+gda_handler_numerical_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, GType type)
{
- GValue *value;
+ g_assert (sql);
+ GValue *value;
setlocale (LC_NUMERIC, "C");
value = gda_handler_numerical_get_value_from_str (iface, sql, type);
setlocale (LC_NUMERIC, gda_numeric_locale);
@@ -228,17 +217,13 @@ gda_handler_numerical_get_value_from_sql (GdaDataHandler *iface, const gchar *sq
}
static GValue *
-gda_handler_numerical_get_value_from_str (GdaDataHandler *iface, const gchar *str, GType type)
+gda_handler_numerical_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, GType type)
{
- GdaHandlerNumerical *hdl;
+ g_assert (str);
GValue *value = NULL;
long long int llint;
char *endptr = NULL;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), NULL);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
llint = strtoll (str, &endptr, 10);
if (type == G_TYPE_INT64) {
@@ -381,16 +366,11 @@ gda_handler_numerical_get_value_from_str (GdaDataHandler *iface, const gchar *st
static GValue *
-gda_handler_numerical_get_sane_init_value (GdaDataHandler *iface, GType type)
+gda_handler_numerical_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, GType type)
{
- GdaHandlerNumerical *hdl;
GValue *value;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), NULL);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
value = gda_handler_numerical_get_value_from_sql (iface, "", type);
+
return value;
}
@@ -399,29 +379,20 @@ gda_handler_numerical_accepts_g_type (GdaDataHandler *iface, GType type)
{
GdaHandlerNumerical *hdl;
guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), FALSE);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, 0);
- while (!found && (i < hdl->priv->nb_g_types)) {
+ g_assert (iface);
+ hdl = (GdaHandlerNumerical*) (iface);
+ for (i = 0; i < hdl->priv->nb_g_types; i++) {
if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
+ return TRUE;
}
- return found;
+ return FALSE;
}
static const gchar *
gda_handler_numerical_get_descr (GdaDataHandler *iface)
{
- GdaHandlerNumerical *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_NUMERICAL (iface), NULL);
- hdl = GDA_HANDLER_NUMERICAL (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_NUMERICAL (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/handlers/gda-handler-string.c b/libgda/handlers/gda-handler-string.c
index 65dae19..2274afa 100644
--- a/libgda/handlers/gda-handler-string.c
+++ b/libgda/handlers/gda-handler-string.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
@@ -48,10 +48,6 @@ static gboolean gda_handler_string_accepts_g_type (GdaDataHandler * dh
static const gchar *gda_handler_string_get_descr (GdaDataHandler *dh);
struct _GdaHandlerStringPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
-
GdaServerProvider *prov;
GdaConnection *cnc;
};
@@ -76,7 +72,7 @@ gda_handler_string_get_type (void)
sizeof (GdaHandlerString),
0,
(GInstanceInitFunc) gda_handler_string_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -123,11 +119,6 @@ gda_handler_string_init (GdaHandlerString * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerStringPriv, 1);
- hdl->priv->detailed_descr = _("Strings handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, 1);
- hdl->priv->valid_g_types[0] = G_TYPE_STRING;
-
g_object_set_data (G_OBJECT (hdl), "name", _("InternalString"));
g_object_set_data (G_OBJECT (hdl), "descr", _("Strings representation"));
}
@@ -143,9 +134,6 @@ gda_handler_string_dispose (GObject * object)
hdl = GDA_HANDLER_STRING (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
if (hdl->priv->prov)
g_object_remove_weak_pointer (G_OBJECT (hdl->priv->prov), (gpointer) &(hdl->priv->prov));
if (hdl->priv->cnc)
@@ -212,15 +200,17 @@ gda_handler_string_new_with_provider (GdaServerProvider *prov, GdaConnection *cn
static gchar *
gda_handler_string_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
{
- gchar *str, *str2, *retval;
+ g_assert (value);
+
+ gchar *str, *retval;
GdaHandlerString *hdl;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_STRING (iface), NULL);
+ hdl = (GdaHandlerString*) (iface);
str = gda_value_stringify ((GValue *) value);
if (str) {
+ gchar *str2;
if (hdl->priv->prov)
str2 = gda_server_provider_escape_string (hdl->priv->prov, hdl->priv->cnc, str);
else
@@ -236,28 +226,24 @@ gda_handler_string_get_sql_from_value (GdaDataHandler *iface, const GValue *valu
}
static gchar *
-gda_handler_string_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_string_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- GdaHandlerString *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
+ g_assert (value);
return gda_value_stringify ((GValue *) value);
}
static GValue *
gda_handler_string_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
{
+ g_assert (sql);
+
GdaHandlerString *hdl;
GValue *value = NULL;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_STRING (iface), NULL);
+ hdl = (GdaHandlerString*) (iface);
- if (sql && *sql) {
+ if (*sql) {
gint i = strlen (sql);
if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
gchar *str = g_strdup (sql);
@@ -277,68 +263,41 @@ gda_handler_string_get_value_from_sql (GdaDataHandler *iface, const gchar *sql,
}
else
value = gda_value_new_null ();
+
return value;
}
static GValue *
-gda_handler_string_get_value_from_str (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
+gda_handler_string_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
{
- GdaHandlerString *hdl;
- GValue *value;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (str);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_STRING);
- g_value_set_string (value, sql);
+ g_value_set_string (value, str);
return value;
}
static GValue *
-gda_handler_string_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNUSED GType type)
+gda_handler_string_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, G_GNUC_UNUSED GType type)
{
- GdaHandlerString *hdl;
GValue *value;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
value = g_value_init (g_new0 (GValue, 1), G_TYPE_STRING);
g_value_set_string (value, "");
-
return value;
}
static gboolean
gda_handler_string_accepts_g_type (GdaDataHandler *iface, GType type)
{
- GdaHandlerString *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), FALSE);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == G_TYPE_STRING ? TRUE : FALSE;
}
static const gchar *
gda_handler_string_get_descr (GdaDataHandler *iface)
{
- GdaHandlerString *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_STRING (iface), NULL);
- hdl = GDA_HANDLER_STRING (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_STRING (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/handlers/gda-handler-time.c b/libgda/handlers/gda-handler-time.c
index a7406b7..fb4c91b 100644
--- a/libgda/handlers/gda-handler-time.c
+++ b/libgda/handlers/gda-handler-time.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
@@ -70,7 +70,6 @@ typedef struct _LocaleSetting {
static gchar *render_date_locale (const GDate *date, LocaleSetting *locale);
struct _GdaHandlerTimePriv {
- gchar *detailed_descr;
guint nb_g_types;
GType *valid_g_types;
@@ -99,7 +98,7 @@ gda_handler_time_get_type (void)
sizeof (GdaHandlerTime),
0,
(GInstanceInitFunc) gda_handler_time_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -146,7 +145,6 @@ gda_handler_time_init (GdaHandlerTime *hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerTimePriv, 1);
- hdl->priv->detailed_descr = _("Time and Date handler");
hdl->priv->nb_g_types = 4;
hdl->priv->valid_g_types = g_new0 (GType, 7);
hdl->priv->valid_g_types[0] = G_TYPE_DATE;
@@ -440,7 +438,6 @@ gda_handler_time_get_no_locale_str_from_value (GdaHandlerTime *dh, const GValue
GType type;
g_return_val_if_fail (GDA_IS_HANDLER_TIME (dh), NULL);
- g_return_val_if_fail (dh->priv, NULL);
type = G_VALUE_TYPE (value);
if (type == G_TYPE_DATE) {
@@ -557,7 +554,6 @@ gda_handler_time_get_format (GdaHandlerTime *dh, GType type)
gint i;
g_return_val_if_fail (GDA_IS_HANDLER_TIME (dh), NULL);
- g_return_val_if_fail (dh->priv, NULL);
string = g_string_new ("");
if ((type == G_TYPE_DATE) || (type == GDA_TYPE_TIMESTAMP) || (type == G_TYPE_DATE_TIME)) {
@@ -600,13 +596,14 @@ gda_handler_time_get_format (GdaHandlerTime *dh, GType type)
static gchar *
gda_handler_time_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
{
+ g_assert (value);
+
gchar *retval = NULL, *str;
GdaHandlerTime *hdl;
GType type;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
type = G_VALUE_TYPE (value);
if (type == G_TYPE_DATE) {
@@ -711,13 +708,14 @@ static gchar *strip_quotes (const gchar *str);
static gchar *
gda_handler_time_get_str_from_value (GdaDataHandler *iface, const GValue *value)
{
+ g_assert (value);
+
GdaHandlerTime *hdl;
gchar *retval = NULL, *str;
GType type;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
type = G_VALUE_TYPE (value);
if (type == G_TYPE_DATE) {
@@ -876,14 +874,15 @@ static GValue *gda_handler_time_get_value_from_locale (GdaDataHandler *iface, co
static GValue *
gda_handler_time_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GType type)
{
+ g_assert (sql);
+
GdaHandlerTime *hdl;
GValue *value = NULL;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
- if (sql && *sql) {
+ if (*sql) {
gint i = strlen (sql);
if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
gchar *str = g_strdup (sql);
@@ -899,18 +898,18 @@ gda_handler_time_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GT
}
static GValue *
-gda_handler_time_get_value_from_str (GdaDataHandler *iface, const gchar *sql, GType type)
+gda_handler_time_get_value_from_str (GdaDataHandler *iface, const gchar *str, GType type)
{
+ g_assert (str);
GdaHandlerTime *hdl;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
- if (sql && (*sql == '\''))
+ if (*str == '\'')
return NULL;
else
- return gda_handler_time_get_value_from_locale (iface, sql, type, hdl->priv->str_locale);
+ return gda_handler_time_get_value_from_locale (iface, str, type, hdl->priv->str_locale);
}
@@ -928,9 +927,8 @@ gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql,
GdaHandlerTime *hdl;
GValue *value = NULL;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
if (type == G_TYPE_DATE) {
GDate date;
@@ -1298,9 +1296,8 @@ gda_handler_time_get_sane_init_value (GdaDataHandler *iface, GType type)
time_t now;
struct tm *stm;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ hdl = (GdaHandlerTime*) (iface);
now = time (NULL);
#ifdef HAVE_LOCALTIME_R
@@ -1364,30 +1361,22 @@ static gboolean
gda_handler_time_accepts_g_type (GdaDataHandler *iface, GType type)
{
GdaHandlerTime *hdl;
- guint i = 0;
- gboolean found = FALSE;
+ guint i;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), FALSE);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, 0);
+ g_assert (iface);
+ hdl = (GdaHandlerTime*) (iface);
- while (!found && (i < hdl->priv->nb_g_types)) {
+ for (i = 0; i < hdl->priv->nb_g_types; i++) {
if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
+ return TRUE;
}
- return found;
+ return FALSE;
}
static const gchar *
gda_handler_time_get_descr (GdaDataHandler *iface)
{
- GdaHandlerTime *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TIME (iface), NULL);
- hdl = GDA_HANDLER_TIME (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_TIME (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/handlers/gda-handler-type.c b/libgda/handlers/gda-handler-type.c
index 9db4cb1..69932e9 100644
--- a/libgda/handlers/gda-handler-type.c
+++ b/libgda/handlers/gda-handler-type.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 - 2007 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
@@ -44,9 +44,7 @@ static gboolean gda_handler_type_accepts_g_type (GdaDataHandler * dh,
static const gchar *gda_handler_type_get_descr (GdaDataHandler *dh);
struct _GdaHandlerTypePriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
+ gchar dummy;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -69,7 +67,7 @@ gda_handler_type_get_type (void)
sizeof (GdaHandlerType),
0,
(GInstanceInitFunc) gda_handler_type_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -104,7 +102,7 @@ gda_handler_type_data_handler_init (GdaDataHandlerIface *iface)
static void
gda_handler_type_class_init (GdaHandlerTypeClass * class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class);
@@ -116,10 +114,6 @@ gda_handler_type_init (GdaHandlerType * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaHandlerTypePriv, 1);
- hdl->priv->detailed_descr = _("Gda type handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, 1);
- hdl->priv->valid_g_types[0] = G_TYPE_GTYPE;
g_object_set_data (G_OBJECT (hdl), "descr", "InternalType");
g_object_set_data (G_OBJECT (hdl), "descr", _("Gda type representation"));
@@ -136,9 +130,6 @@ gda_handler_type_dispose (GObject * object)
hdl = GDA_HANDLER_TYPE (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
g_free (hdl->priv);
hdl->priv = NULL;
}
@@ -165,68 +156,48 @@ gda_handler_type_new (void)
}
static gchar *
-gda_handler_type_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_type_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaHandlerType *hdl;
+ g_assert (value);
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), NULL);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (value) {
- GTypeQuery tq;
- g_type_query (g_value_get_gtype (value), &tq);
- if (tq.type != 0) {
- const gchar *str;
- str = gda_g_type_to_string (g_value_get_gtype (value));
- retval = g_strdup_printf ("'%s'", str);
- }
- else
- retval = g_strdup ("NULL");
+ gchar *retval;
+ GTypeQuery tq;
+ g_type_query (g_value_get_gtype (value), &tq);
+ if (tq.type != 0) {
+ const gchar *str;
+ str = gda_g_type_to_string (g_value_get_gtype (value));
+ retval = g_strdup_printf ("'%s'", str);
}
else
- retval = g_strdup ("NULL");
+ retval = g_strdup ("NULL");
return retval;
}
static gchar *
-gda_handler_type_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_handler_type_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaHandlerType *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), NULL);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (value);
- if (value) {
- GTypeQuery tq;
+ gchar *retval;
+ GTypeQuery tq;
- g_type_query (g_value_get_gtype (value), &tq);
- if (tq.type != 0)
- retval = g_strdup (gda_g_type_to_string (g_value_get_gtype (value)));
- else
- retval = g_strdup (NULL); /* FIXME: return NULL instead because of the error? */
- }
+ g_type_query (g_value_get_gtype (value), &tq);
+ if (tq.type != 0)
+ retval = g_strdup (gda_g_type_to_string (g_value_get_gtype (value)));
else
- retval = g_strdup (NULL);
+ retval = NULL;
return retval;
}
static GValue *
-gda_handler_type_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
+gda_handler_type_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
{
- GdaHandlerType *hdl;
- GValue *value = NULL;
+ g_assert (sql);
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), NULL);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (sql && *sql) {
+ GValue *value = NULL;
+ if (*sql) {
gint i = strlen (sql);
if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
gchar *str = g_strdup (sql);
@@ -246,16 +217,13 @@ gda_handler_type_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_
}
static GValue *
-gda_handler_type_get_value_from_str (GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
+gda_handler_type_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
{
- GdaHandlerType *hdl;
+ g_assert (str);
+
GValue *value = NULL;
GType vtype;
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), NULL);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
vtype = gda_g_type_from_string (str);
if (vtype != G_TYPE_INVALID) {
value = g_value_init (g_new0 (GValue, 1), G_TYPE_GTYPE);
@@ -268,31 +236,13 @@ gda_handler_type_get_value_from_str (GdaDataHandler *iface, const gchar *str, G_
static gboolean
gda_handler_type_accepts_g_type (GdaDataHandler *iface, GType type)
{
- GdaHandlerType *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), FALSE);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == G_TYPE_GTYPE ? TRUE : FALSE;
}
static const gchar *
gda_handler_type_get_descr (GdaDataHandler *iface)
{
- GdaHandlerType *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_HANDLER_TYPE (iface), NULL);
- hdl = GDA_HANDLER_TYPE (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_HANDLER_TYPE (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/sqlite/gda-sqlite-handler-bin.c b/libgda/sqlite/gda-sqlite-handler-bin.c
index e6646cc..0ca3748 100644
--- a/libgda/sqlite/gda-sqlite-handler-bin.c
+++ b/libgda/sqlite/gda-sqlite-handler-bin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
@@ -37,17 +37,15 @@ static void gda_sqlite_handler_bin_data_handler_init (GdaDataHandle
static gchar *gda_sqlite_handler_bin_get_sql_from_value (GdaDataHandler *dh, const GValue *value);
static gchar *gda_sqlite_handler_bin_get_str_from_value (GdaDataHandler *dh, const GValue *value);
static GValue *gda_sqlite_handler_bin_get_value_from_sql (GdaDataHandler *dh, const gchar *sql,
- GType type);
+ GType type);
static GValue *gda_sqlite_handler_bin_get_value_from_str (GdaDataHandler *dh, const gchar *sql,
- GType type);
+ GType type);
static gboolean gda_sqlite_handler_bin_accepts_g_type (GdaDataHandler * dh, GType type);
static const gchar *gda_sqlite_handler_bin_get_descr (GdaDataHandler *dh);
struct _GdaSqliteHandlerBinPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
+ gchar dummy;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -70,7 +68,7 @@ _gda_sqlite_handler_bin_get_type (void)
sizeof (GdaSqliteHandlerBin),
0,
(GInstanceInitFunc) gda_sqlite_handler_bin_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -117,13 +115,8 @@ gda_sqlite_handler_bin_init (GdaSqliteHandlerBin * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaSqliteHandlerBinPriv, 1);
- hdl->priv->detailed_descr = _("SQlite binary handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, hdl->priv->nb_g_types);
- hdl->priv->valid_g_types[0] = GDA_TYPE_BINARY;
-
g_object_set_data (G_OBJECT (hdl), "name", "SqliteBin");
- g_object_set_data (G_OBJECT (hdl), "descr", _("SQlite binary representation"));
+ g_object_set_data (G_OBJECT (hdl), "descr", _("SQLite binary representation"));
}
static void
@@ -137,9 +130,6 @@ gda_sqlite_handler_bin_dispose (GObject * object)
hdl = GDA_SQLITE_HANDLER_BIN (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
g_free (hdl->priv);
hdl->priv = NULL;
}
@@ -166,78 +156,60 @@ _gda_sqlite_handler_bin_new (void)
}
static gchar *
-gda_sqlite_handler_bin_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_sqlite_handler_bin_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaSqliteHandlerBin *hdl;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (value);
- if (value) {
- GdaBinary *bin;
- gint i;
- g_return_val_if_fail (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY), NULL);
-
- bin = (GdaBinary *) gda_value_get_binary ((GValue *) value);
- retval = g_new0 (gchar, bin->binary_length * 2 + 4);
- retval [0] = 'x';
- retval [1] = '\'';
- for (i = 0; i < bin->binary_length; i++) {
- guchar *ptr;
-
- ptr = bin->data + i;
- if ((*ptr >> 4) <= 9)
- retval [2*i + 2] = (*ptr >> 4) + '0';
- else
- retval [2*i + 2] = (*ptr >> 4) + 'A' - 10;
- if ((*ptr & 0xF) <= 9)
- retval [2*i + 3] = (*ptr & 0xF) + '0';
- else
- retval [2*i + 3] = (*ptr & 0xF) + 'A' - 10;
- }
- retval [bin->binary_length * 2 + 2] = '\'';
+ gchar *retval;
+ GdaBinary *bin;
+ gint i;
+
+ bin = (GdaBinary *) gda_value_get_binary ((GValue *) value);
+ retval = g_new0 (gchar, bin->binary_length * 2 + 4);
+ retval [0] = 'x';
+ retval [1] = '\'';
+ for (i = 0; i < bin->binary_length; i++) {
+ guchar *ptr;
+
+ ptr = bin->data + i;
+ if ((*ptr >> 4) <= 9)
+ retval [2*i + 2] = (*ptr >> 4) + '0';
+ else
+ retval [2*i + 2] = (*ptr >> 4) + 'A' - 10;
+ if ((*ptr & 0xF) <= 9)
+ retval [2*i + 3] = (*ptr & 0xF) + '0';
+ else
+ retval [2*i + 3] = (*ptr & 0xF) + 'A' - 10;
}
- else
- retval = g_strdup ("NULL");
+ retval [bin->binary_length * 2 + 2] = '\'';
return retval;
}
static gchar *
-gda_sqlite_handler_bin_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_sqlite_handler_bin_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
+ g_assert (value);
+
gchar *retval;
- GdaSqliteHandlerBin *hdl;
+ GdaBinary *bin;
+ gint i;
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ bin = (GdaBinary *) gda_value_get_binary ((GValue *) value);
+ retval = g_new0 (gchar, bin->binary_length * 2 + 1);
+ for (i = 0; i < bin->binary_length; i++) {
+ guchar *ptr;
- if (value) {
- GdaBinary *bin;
- gint i;
- g_return_val_if_fail (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY), NULL);
-
- bin = (GdaBinary *) gda_value_get_binary ((GValue *) value);
- retval = g_new0 (gchar, bin->binary_length * 2 + 1);
- for (i = 0; i < bin->binary_length; i++) {
- guchar *ptr;
-
- ptr = bin->data + i;
- if ((*ptr >> 4) <= 9)
- retval [2*i] = (*ptr >> 4) + '0';
- else
- retval [2*i] = (*ptr >> 4) + 'A' - 10;
- if ((*ptr & 0xF) <= 9)
- retval [2*i + 1] = (*ptr & 0xF) + '0';
- else
- retval [2*i + 1] = (*ptr & 0xF) + 'A' - 10;
- }
+ ptr = bin->data + i;
+ if ((*ptr >> 4) <= 9)
+ retval [2*i] = (*ptr >> 4) + '0';
+ else
+ retval [2*i] = (*ptr >> 4) + 'A' - 10;
+ if ((*ptr & 0xF) <= 9)
+ retval [2*i + 1] = (*ptr & 0xF) + '0';
+ else
+ retval [2*i + 1] = (*ptr & 0xF) + 'A' - 10;
}
- else
- retval = g_strdup ("");
return retval;
}
@@ -256,16 +228,12 @@ static int hex_to_int (int h) {
}
static GValue *
-gda_sqlite_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GType type)
+gda_sqlite_handler_bin_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, GType type)
{
- GdaSqliteHandlerBin *hdl;
+ g_assert (sql);
GValue *value = NULL;
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if ((type == GDA_TYPE_BINARY) && sql && *sql) {
+ if (*sql) {
gint n = strlen (sql);
if ((n >= 3) &&
! ((n-3) % 2) &&
@@ -287,87 +255,55 @@ gda_sqlite_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar *s
gda_value_take_binary (value, bin);
}
}
- else
- g_assert_not_reached ();
return value;
}
static GValue *
-gda_sqlite_handler_bin_get_value_from_str (GdaDataHandler *iface, const gchar *str, GType type)
+gda_sqlite_handler_bin_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, GType type)
{
- GdaSqliteHandlerBin *hdl;
+ g_assert (str);
+
GValue *value = NULL;
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (type == GDA_TYPE_BINARY) {
- if (str && *str) {
- gint n = strlen (str);
- if (! (n % 2)) {
- GdaBinary *bin;
-
- bin = g_new0 (GdaBinary, 1);
- if (n > 0) {
- gint i;
- bin->data = g_new0 (guchar, n/2);
- for (i = 0; i < n; i += 2)
- bin->data [i/2] = (hex_to_int (str[i]) << 4) | hex_to_int (str [i+1]);
- bin->binary_length = n;
- }
-
- value = gda_value_new (GDA_TYPE_BINARY);
- gda_value_take_binary (value, bin);
- }
- }
- else {
- if (str) {
- GdaBinary *bin;
-
- bin = g_new0 (GdaBinary, 1);
- value = gda_value_new (GDA_TYPE_BINARY);
- gda_value_take_binary (value, bin);
+ if (*str) {
+ gint n = strlen (str);
+ if (! (n % 2)) {
+ GdaBinary *bin;
+
+ bin = g_new0 (GdaBinary, 1);
+ if (n > 0) {
+ gint i;
+ bin->data = g_new0 (guchar, n/2);
+ for (i = 0; i < n; i += 2)
+ bin->data [i/2] = (hex_to_int (str[i]) << 4) | hex_to_int (str [i+1]);
+ bin->binary_length = n;
}
- else
- value = gda_value_new_null ();
+
+ value = gda_value_new (GDA_TYPE_BINARY);
+ gda_value_take_binary (value, bin);
}
}
- else
- g_assert_not_reached ();
+ else {
+ GdaBinary *bin;
+ bin = gda_string_to_binary (str);
+ value = gda_value_new (GDA_TYPE_BINARY);
+ gda_value_take_binary (value, bin);
+ }
return value;
}
static gboolean
-gda_sqlite_handler_bin_accepts_g_type (GdaDataHandler *iface, GType type)
+gda_sqlite_handler_bin_accepts_g_type (G_GNUC_UNUSED GdaDataHandler *iface, GType type)
{
- GdaSqliteHandlerBin *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), FALSE);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == GDA_TYPE_BINARY ? TRUE : FALSE;
}
static const gchar *
gda_sqlite_handler_bin_get_descr (GdaDataHandler *iface)
{
- GdaSqliteHandlerBin *hdl;
-
g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BIN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/libgda/sqlite/gda-sqlite-handler-boolean.c b/libgda/sqlite/gda-sqlite-handler-boolean.c
index 4dd7d12..ff1d564 100644
--- a/libgda/sqlite/gda-sqlite-handler-boolean.c
+++ b/libgda/sqlite/gda-sqlite-handler-boolean.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2013 Vivien Malerba <malerba gnome-db org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -43,9 +43,7 @@ static gboolean gda_sqlite_handler_boolean_accepts_g_type (GdaDataHa
static const gchar *gda_sqlite_handler_boolean_get_descr (GdaDataHandler *dh);
struct _GdaSqliteHandlerBooleanPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
+ gchar dummy;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -68,7 +66,7 @@ _gda_sqlite_handler_boolean_get_type (void)
sizeof (GdaSqliteHandlerBoolean),
0,
(GInstanceInitFunc) gda_sqlite_handler_boolean_init,
- 0
+ NULL
};
static const GInterfaceInfo data_entry_info = {
@@ -115,11 +113,6 @@ gda_sqlite_handler_boolean_init (GdaSqliteHandlerBoolean *hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaSqliteHandlerBooleanPriv, 1);
- hdl->priv->detailed_descr = _("Boolean values handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, 1);
- hdl->priv->valid_g_types[0] = G_TYPE_BOOLEAN;
-
g_object_set_data (G_OBJECT (hdl), "name", "SqliteBoolean");
g_object_set_data (G_OBJECT (hdl), "descr", _("Sqlite boolean representation"));
}
@@ -134,9 +127,6 @@ gda_sqlite_handler_boolean_dispose (GObject *object)
hdl = GDA_SQLITE_HANDLER_BOOLEAN (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
g_free (hdl->priv);
hdl->priv = NULL;
}
@@ -163,45 +153,25 @@ _gda_sqlite_handler_boolean_new (void)
}
static gchar *
-gda_sqlite_handler_boolean_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_sqlite_handler_boolean_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaSqliteHandlerBoolean *hdl;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (g_value_get_boolean (value))
- retval = g_strdup ("1");
- else
- retval = g_strdup ("0");
-
- return retval;
+ g_assert (value);
+ return g_strdup (g_value_get_boolean (value) ? "1" : "0");
}
static gchar *
-gda_sqlite_handler_boolean_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_sqlite_handler_boolean_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- GdaSqliteHandlerBoolean *hdl;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
+ g_assert (value);
return g_strdup (g_value_get_boolean (value) ? "1" : "0");
}
static GValue *
-gda_sqlite_handler_boolean_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
+gda_sqlite_handler_boolean_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
{
- GdaSqliteHandlerBoolean *hdl;
- GValue *value;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (sql);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
if (*sql == '0')
g_value_set_boolean (value, FALSE);
@@ -211,15 +181,11 @@ gda_sqlite_handler_boolean_get_value_from_sql (GdaDataHandler *iface, const gcha
}
static GValue *
-gda_sqlite_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
+gda_sqlite_handler_boolean_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
{
- GdaSqliteHandlerBoolean *hdl;
- GValue *value = NULL;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (str);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
if (*str == '0')
g_value_set_boolean (value, FALSE);
@@ -231,15 +197,9 @@ gda_sqlite_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gcha
static GValue *
-gda_sqlite_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNUSED GType type)
+gda_sqlite_handler_boolean_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, G_GNUC_UNUSED GType type)
{
- GdaSqliteHandlerBoolean *hdl;
GValue *value;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
g_value_set_boolean (value, FALSE);
@@ -247,33 +207,15 @@ gda_sqlite_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UN
}
static gboolean
-gda_sqlite_handler_boolean_accepts_g_type (GdaDataHandler *iface, GType type)
+gda_sqlite_handler_boolean_accepts_g_type (G_GNUC_UNUSED GdaDataHandler *iface, GType type)
{
- GdaSqliteHandlerBoolean *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), FALSE);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == G_TYPE_BOOLEAN ? TRUE : FALSE;
}
static const gchar *
gda_sqlite_handler_boolean_get_descr (GdaDataHandler *iface)
{
- GdaSqliteHandlerBoolean *hdl;
-
g_return_val_if_fail (GDA_IS_SQLITE_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_SQLITE_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/providers/mysql/gda-mysql-handler-boolean.c b/providers/mysql/gda-mysql-handler-boolean.c
index 95c4faa..c7ab3a3 100644
--- a/providers/mysql/gda-mysql-handler-boolean.c
+++ b/providers/mysql/gda-mysql-handler-boolean.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This library is free software; you can redistribute it and/or
@@ -43,9 +43,7 @@ static gboolean gda_mysql_handler_boolean_accepts_g_type (GdaDataHan
static const gchar *gda_mysql_handler_boolean_get_descr (GdaDataHandler *dh);
struct _GdaMysqlHandlerBooleanPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
+ gchar dummy;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -115,11 +113,6 @@ gda_mysql_handler_boolean_init (GdaMysqlHandlerBoolean *hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaMysqlHandlerBooleanPriv, 1);
- hdl->priv->detailed_descr = _("Boolean values handler");
- hdl->priv->nb_g_types = 1;
- hdl->priv->valid_g_types = g_new0 (GType, 1);
- hdl->priv->valid_g_types[0] = G_TYPE_BOOLEAN;
-
g_object_set_data (G_OBJECT (hdl), "name", "MySQLBoolean");
g_object_set_data (G_OBJECT (hdl), "descr", _("MySQL boolean representation"));
}
@@ -134,9 +127,6 @@ gda_mysql_handler_boolean_dispose (GObject *object)
hdl = GDA_MYSQL_HANDLER_BOOLEAN (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
g_free (hdl->priv);
hdl->priv = NULL;
}
@@ -163,45 +153,25 @@ gda_mysql_handler_boolean_new (void)
}
static gchar *
-gda_mysql_handler_boolean_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
+gda_mysql_handler_boolean_get_sql_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaMysqlHandlerBoolean *hdl;
-
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (g_value_get_boolean (value))
- retval = g_strdup ("1");
- else
- retval = g_strdup ("0");
-
- return retval;
+ g_assert (value);
+ return g_strdup (g_value_get_boolean (value) ? "1" : "0");
}
static gchar *
-gda_mysql_handler_boolean_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_mysql_handler_boolean_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- GdaMysqlHandlerBoolean *hdl;
-
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
+ g_assert (value);
return g_strdup (g_value_get_boolean (value) ? "1" : "0");
}
static GValue *
-gda_mysql_handler_boolean_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
+gda_mysql_handler_boolean_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, G_GNUC_UNUSED GType type)
{
- GdaMysqlHandlerBoolean *hdl;
- GValue *value;
-
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (sql);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
if (*sql == '0')
g_value_set_boolean (value, FALSE);
@@ -211,15 +181,11 @@ gda_mysql_handler_boolean_get_value_from_sql (GdaDataHandler *iface, const gchar
}
static GValue *
-gda_mysql_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
+gda_mysql_handler_boolean_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, G_GNUC_UNUSED GType type)
{
- GdaMysqlHandlerBoolean *hdl;
- GValue *value = NULL;
-
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ g_assert (str);
+ GValue *value;
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
if (*str == '0')
g_value_set_boolean (value, FALSE);
@@ -231,15 +197,10 @@ gda_mysql_handler_boolean_get_value_from_str (GdaDataHandler *iface, const gchar
static GValue *
-gda_mysql_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNUSED GType type)
+gda_mysql_handler_boolean_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, G_GNUC_UNUSED GType type)
{
- GdaMysqlHandlerBoolean *hdl;
GValue *value;
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
value = g_value_init (g_new0 (GValue, 1), G_TYPE_BOOLEAN);
g_value_set_boolean (value, FALSE);
@@ -247,33 +208,15 @@ gda_mysql_handler_boolean_get_sane_init_value (GdaDataHandler *iface, G_GNUC_UNU
}
static gboolean
-gda_mysql_handler_boolean_accepts_g_type (GdaDataHandler *iface, GType type)
+gda_mysql_handler_boolean_accepts_g_type (G_GNUC_UNUSED GdaDataHandler *iface, GType type)
{
- GdaMysqlHandlerBoolean *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), FALSE);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == G_TYPE_BOOLEAN ? TRUE : FALSE;
}
static const gchar *
gda_mysql_handler_boolean_get_descr (GdaDataHandler *iface)
{
- GdaMysqlHandlerBoolean *hdl;
-
g_return_val_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (iface), NULL);
- hdl = GDA_MYSQL_HANDLER_BOOLEAN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/providers/postgres/gda-postgres-handler-bin.c b/providers/postgres/gda-postgres-handler-bin.c
index 67414bd..d3da924 100644
--- a/providers/postgres/gda-postgres-handler-bin.c
+++ b/providers/postgres/gda-postgres-handler-bin.c
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2007 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2007 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2007 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
*
@@ -46,9 +46,6 @@ static gboolean gda_postgres_handler_bin_accepts_g_type (GdaDataHand
static const gchar *gda_postgres_handler_bin_get_descr (GdaDataHandler *dh);
struct _GdaPostgresHandlerBinPriv {
- gchar *detailed_descr;
- guint nb_g_types;
- GType *valid_g_types;
GdaConnection *cnc;
};
@@ -72,8 +69,8 @@ gda_postgres_handler_bin_get_type (void)
sizeof (GdaPostgresHandlerBin),
0,
(GInstanceInitFunc) gda_postgres_handler_bin_init,
- 0
- };
+ NULL
+ };
static const GInterfaceInfo data_entry_info = {
(GInterfaceInitFunc) gda_postgres_handler_bin_data_handler_init,
@@ -119,12 +116,6 @@ gda_postgres_handler_bin_init (GdaPostgresHandlerBin * hdl)
{
/* Private structure */
hdl->priv = g_new0 (GdaPostgresHandlerBinPriv, 1);
- hdl->priv->detailed_descr = _("Postgresql binary handler");
- hdl->priv->nb_g_types = 2;
- hdl->priv->valid_g_types = g_new0 (GType, hdl->priv->nb_g_types);
- hdl->priv->valid_g_types[0] = GDA_TYPE_BINARY;
- hdl->priv->valid_g_types[1] = GDA_TYPE_BLOB;
-
g_object_set_data (G_OBJECT (hdl), "name", _("PostgresqlBin"));
g_object_set_data (G_OBJECT (hdl), "descr", _("PostgreSQL binary representation"));
}
@@ -140,9 +131,6 @@ gda_postgres_handler_bin_dispose (GObject * object)
hdl = GDA_POSTGRES_HANDLER_BIN (object);
if (hdl->priv) {
- g_free (hdl->priv->valid_g_types);
- hdl->priv->valid_g_types = NULL;
-
if (hdl->priv->cnc)
g_object_remove_weak_pointer (G_OBJECT (hdl->priv->cnc), (gpointer) &(hdl->priv->cnc));
@@ -182,106 +170,80 @@ gda_postgres_handler_bin_new (GdaConnection *cnc)
static gchar *
gda_postgres_handler_bin_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
{
+ g_assert (value);
+
gchar *retval;
GdaPostgresHandlerBin *hdl;
PostgresConnectionData *cdata = NULL;
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
+ g_return_val_if_fail (GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
+ hdl = (GdaPostgresHandlerBin*) (iface);
if (hdl->priv->cnc) {
g_return_val_if_fail (GDA_IS_CONNECTION (hdl->priv->cnc), NULL);
cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data (hdl->priv->cnc);
}
- if (value) {
- if (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY)) {
- GdaBinary *data = (GdaBinary *) gda_value_get_binary ((GValue *) value);
- if (data) {
- gchar *tmp;
- size_t retlength;
- if (0 && cdata) {
- /* FIXME: use this call but it's only defined for Postgres >= 8.1 */
- /*tmp = PQescapeByteaConn (cdata->pconn, data, length, &retlength);*/
- }
- else
- tmp = (gchar *)PQescapeBytea (data->data,
- data->binary_length, &retlength);
-
- if (tmp) {
- retval = g_strdup_printf ("'%s'", tmp);
- PQfreemem (tmp);
- }
- else {
- g_warning (_("Insufficient memory to convert binary buffer to string"));
- return NULL;
- }
- }
- else
- retval = g_strdup ("NULL");
+ GdaBinary *data = (GdaBinary *) gda_value_get_binary ((GValue *) value);
+ if (data) {
+ gchar *tmp;
+ size_t retlength;
+ if (0 && cdata) {
+ /* FIXME: use this call but it's only defined for Postgres >= 8.1 */
+ /*tmp = PQescapeByteaConn (cdata->pconn, data, length, &retlength);*/
}
else
- retval = g_strdup ("**BLOB**");
+ tmp = (gchar *) PQescapeBytea (data->data,
+ data->binary_length, &retlength);
+ if (tmp) {
+ retval = g_strdup_printf ("'%s'", tmp);
+ PQfreemem (tmp);
+ }
+ else {
+ g_warning (_("Insufficient memory to convert binary buffer to string"));
+ return NULL;
+ }
}
else
retval = g_strdup ("NULL");
-
+
return retval;
}
static gchar *
-gda_postgres_handler_bin_get_str_from_value (GdaDataHandler *iface, const GValue *value)
+gda_postgres_handler_bin_get_str_from_value (G_GNUC_UNUSED GdaDataHandler *iface, const GValue *value)
{
- gchar *retval;
- GdaPostgresHandlerBin *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (value) {
- if (gda_value_isa ((GValue *) value, GDA_TYPE_BINARY))
- retval = gda_binary_to_string (gda_value_get_binary ((GValue *) value), 0);
- else
- retval = g_strdup ("**BLOB**");
- }
- else
- retval = g_strdup (NULL);
+ g_assert (value);
+ gchar *retval;
+ retval = gda_binary_to_string (gda_value_get_binary ((GValue *) value), 0);
return retval;
}
static GValue *
-gda_postgres_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar *sql, GType type)
+gda_postgres_handler_bin_get_value_from_sql (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *sql, GType type)
{
- GdaPostgresHandlerBin *hdl;
- GValue *value = NULL;
+ g_assert (sql);
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (type == GDA_TYPE_BINARY) {
- if (sql && *sql) {
- gint i = strlen (sql);
- if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
- gchar *str = g_strdup (sql);
- guchar *unstr;
- size_t retlength;
-
- str[i-1] = 0;
- unstr = PQunescapeBytea ((guchar*) (str+1), &retlength);
- if (unstr) {
- value = gda_value_new_binary (unstr, retlength);
- PQfreemem (unstr);
- }
- else
- g_warning (_("Insufficient memory to convert string to binary buffer"));
-
- g_free (str);
+ GValue *value = NULL;
+ if (*sql) {
+ gint i = strlen (sql);
+ if ((i>=2) && (*sql=='\'') && (sql[i-1]=='\'')) {
+ gchar *str = g_strdup (sql);
+ guchar *unstr;
+ size_t retlength;
+
+ str[i-1] = 0;
+ unstr = PQunescapeBytea ((guchar*) (str+1), &retlength);
+ if (unstr) {
+ value = gda_value_new_binary (unstr, retlength);
+ PQfreemem (unstr);
}
+ else
+ g_warning (_("Insufficient memory to convert string to binary buffer"));
+
+ g_free (str);
}
}
@@ -289,22 +251,16 @@ gda_postgres_handler_bin_get_value_from_sql (GdaDataHandler *iface, const gchar
}
static GValue *
-gda_postgres_handler_bin_get_value_from_str (GdaDataHandler *iface, const gchar *str, GType type)
+gda_postgres_handler_bin_get_value_from_str (G_GNUC_UNUSED GdaDataHandler *iface, const gchar *str, GType type)
{
- GdaPostgresHandlerBin *hdl;
- GValue *value = NULL;
+ g_assert (str);
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- if (type == GDA_TYPE_BINARY) {
- GdaBinary *bin;
- bin = gda_string_to_binary (str);
- if (bin) {
- value = gda_value_new (GDA_TYPE_BINARY);
- gda_value_take_binary (value, bin);
- }
+ GValue *value = NULL;
+ GdaBinary *bin;
+ bin = gda_string_to_binary (str);
+ if (bin) {
+ value = gda_value_new (GDA_TYPE_BINARY);
+ gda_value_take_binary (value, bin);
}
return value;
@@ -313,31 +269,13 @@ gda_postgres_handler_bin_get_value_from_str (GdaDataHandler *iface, const gchar
static gboolean
gda_postgres_handler_bin_accepts_g_type (GdaDataHandler *iface, GType type)
{
- GdaPostgresHandlerBin *hdl;
- guint i = 0;
- gboolean found = FALSE;
-
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), FALSE);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, 0);
-
- while (!found && (i < hdl->priv->nb_g_types)) {
- if (hdl->priv->valid_g_types [i] == type)
- found = TRUE;
- i++;
- }
-
- return found;
+ g_assert (iface);
+ return type == GDA_TYPE_BINARY ? TRUE : FALSE;
}
static const gchar *
gda_postgres_handler_bin_get_descr (GdaDataHandler *iface)
{
- GdaPostgresHandlerBin *hdl;
-
- g_return_val_if_fail (iface && GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
- hdl = GDA_POSTGRES_HANDLER_BIN (iface);
- g_return_val_if_fail (hdl->priv, NULL);
-
- return g_object_get_data (G_OBJECT (hdl), "descr");
+ g_return_val_if_fail (GDA_IS_POSTGRES_HANDLER_BIN (iface), NULL);
+ return g_object_get_data (G_OBJECT (iface), "descr");
}
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 8c4b65f..9ab23a8 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -1335,16 +1335,12 @@ gda_postgres_provider_get_data_handler (GdaServerProvider *provider, GdaConnecti
TO_IMPLEMENT; /* use @dbms_type */
dh = NULL;
}
- else if ((type == GDA_TYPE_BINARY) ||
- (type == GDA_TYPE_BLOB)) {
+ else if (type == GDA_TYPE_BINARY) {
dh = gda_server_provider_handler_find (provider, cnc, type, NULL);
if (!dh) {
dh = gda_postgres_handler_bin_new (cnc);
- if (dh) {
- gda_server_provider_handler_declare (provider, dh, cnc, GDA_TYPE_BINARY, NULL);
- gda_server_provider_handler_declare (provider, dh, cnc, GDA_TYPE_BLOB, NULL);
- g_object_unref (dh);
- }
+ gda_server_provider_handler_declare (provider, dh, cnc, GDA_TYPE_BINARY, NULL);
+ g_object_unref (dh);
}
}
else if ((type == GDA_TYPE_TIME) ||
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]