From 48f81eb4369df802b37f4abb9dfcf918d897db35 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 24 Jun 2010 10:49:38 +0200 Subject: [PATCH] Bugfix on insert NULL values. --- src/audit.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/audit.c b/src/audit.c index 01c002c..fb9dcec 100644 --- a/src/audit.c +++ b/src/audit.c @@ -392,6 +392,7 @@ insert_value (Audit *audit, /* find the new id */ GdaDataModel *dm; guint id_new; + gchar *real_value; id_new = 0; sql = g_strdup_printf ("SELECT COALESCE (MAX (id)) FROM values"); @@ -401,12 +402,24 @@ insert_value (Audit *audit, id_new = gdaex_data_model_get_value_integer_at (dm, 0, 0); } id_new++; - + + if (g_strcmp0 (g_utf8_strup (value, -1), "NULL") == 0) + { + real_value = g_strdup ("NULL"); + } + else + { + real_value = g_strconcat ("'", + gdaex_strescape ((const gchar *)string_unquote (value), NULL), + "'", + NULL); + } + sql = g_strdup_printf ("INSERT INTO values" " (id, id_actions, id_fields, value)" - " VALUES (%d, %d, %d, '%s')", + " VALUES (%d, %d, %d, %s)", id_new, id_actions, field->id, - gdaex_strescape ((const gchar *)string_unquote (value), NULL)); + real_value); gdaex_execute (priv->gdaex, sql); } -- 2.49.0