]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Spostate le funzioni Allegato::get_blob e ::salva_in_db in GdaEx.
authorAndrea Zagli <azagli@libero.it>
Sat, 15 Aug 2015 09:29:05 +0000 (11:29 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 15 Aug 2015 09:29:05 +0000 (11:29 +0200)
.gitignore
src/allegato.c
src/allegato.h

index 1b4271ecfef16421908705b2421aef247548814e..32adc7ec2b6e23bab6d44722d85c57e26149718e 100644 (file)
@@ -67,5 +67,6 @@ tests/utils_gdatetime
 tests/utils_gstring_initial_capital
 tests/utils_gtktreemodel_copy
 tests/utils_infobar
+tests/utils_message_dialog
 tests/utils_round
 *.csv
index bbf3fbf33c0c5f050b276f4b8ae189823e16c425..fe8af788cc094ade8c4f614d9aa84069bd01bc7f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,8 +22,8 @@
 
 #include <glib/gstdio.h>
 
-#include <libgda/libgda.h>
 #include <sql-parser/gda-sql-parser.h>
+#include <libgdaex/libgdaex.h>
 
 #include <libgtkform/field.h>
 #include <libgtkform/fielddatetime.h>
@@ -294,181 +294,24 @@ solipa_allegato_apri_allegato (GtkWindow *transient, const gchar *filename)
                }
 }
 
+G_DEPRECATED_FOR (gdaex_save_file_in_blob)
 gboolean
-solipa_allegato_salva_in_db (GdaConnection *gda_con, const gchar *sql,
+solipa_allegato_salva_in_db (GdaEx *gdaex, const gchar *sql,
                              const gchar *blob_field_name, const gchar *percorso)
 {
-       GdaSqlParser *parser;
-       GdaStatement *stmt;
-       GError *error;
-       GdaSet *plist;
-       GdaHolder *param;
-       GValue *value;
-       gint res;
-
-       g_return_val_if_fail (GDA_IS_CONNECTION (gda_con), FALSE);
-
-       parser = gda_connection_create_parser (gda_con);
-       if (parser == NULL)
-               {
-                       parser = gda_sql_parser_new ();
-               }
-       if (parser == NULL)
-               {
-                       g_warning ("Errore nella creazione del parser sql.");
-                       return FALSE;
-               }
-
-       error = NULL;
-       stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
-       g_object_unref (parser);
-       if (stmt == NULL || error != NULL)
-               {
-                       g_warning ("Errore nell'analisi della stringa sql: %s.",
-                                  error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
-                       return FALSE;
-               }
-       gda_statement_get_parameters (stmt, &plist, NULL);
-
-       gda_connection_begin_transaction (gda_con, NULL, 0, NULL);
-
-       param = gda_set_get_holder (plist, blob_field_name);
-       value = gda_value_new_blob_from_file (percorso);
-       error = NULL;
-       if (!gda_holder_take_value (param, value, &error))
-               {
-                       g_object_unref (plist);
-
-                       gda_connection_rollback_transaction (gda_con, NULL, NULL);
-
-                       /* TODO error */
-                       g_warning ("Errore nell'impostare il blob: %s.",
-                                  error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
-                       return FALSE;
-               }
-       else
-               {
-                       error = NULL;
-                       res = gda_connection_statement_execute_non_select (gda_con, stmt, plist, NULL, &error);
-
-                       g_object_unref (plist);
-                       g_object_unref (stmt);
-
-                       if (error != NULL)
-                               {
-                                       gda_connection_rollback_transaction (gda_con, NULL, NULL);
-
-                                       /* TODO error */
-                                       g_warning ("Errore nell'esecuzione dello statement di aggiornamento del blob: %s.",
-                                                  error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
-                                       return FALSE;
-                               }
-                       gda_connection_commit_transaction (gda_con, NULL, NULL);
-               }
+       gdaex_save_file_in_blob (gdaex, sql, blob_field_name, percorso);
 
        return TRUE;
 }
 
+G_DEPRECATED_FOR (gdaex_get_blob)
 const gchar
 *solipa_allegato_get_blob (GdaEx *gdaex,
                            const gchar *sql,
                            const gchar *percorso_field_name,
                            const gchar *blob_field_name)
 {
-       GdaDataModel *dm;
-       GError *error;
-       gint fin;
-       gchar *filename_tmp;
-       const GValue *value;
-       const gchar *percorso;
-       gchar *filename_orig;
-       const GdaBlob *blob;
-       gint i;
-
-       gchar *ret;
-
-       ret = NULL;
-
-       dm = gdaex_query (gdaex, sql);
-       if (dm != NULL)
-               {
-                       error = NULL;
-                       value = gda_data_model_get_value_at (dm,
-                                                            gda_data_model_get_column_index (dm, blob_field_name),
-                                                            0, &error);
-                       if (!gda_value_is_null (value) && gda_value_isa (value, GDA_TYPE_BLOB))
-                               {
-                                       blob = gda_value_get_blob (value);
-
-                                       filename_orig = g_strdup ("");
-                                       error = NULL;
-                                       value = gda_data_model_get_value_at (dm,
-                                                                            gda_data_model_get_column_index (dm, percorso_field_name),
-                                                                            0, &error);
-                                       if (!gda_value_is_null (value))
-                                               {
-                                                       percorso = g_value_get_string (value);
-                                                       filename_orig = g_path_get_basename (percorso);
-                                               }
-
-                                       error = NULL;
-                                       fin = g_file_open_tmp (g_strdup_printf ("solipa-XXXXXX-%s", filename_orig),
-                                                              &filename_tmp, &error);
-                                       if (fin > 0 && error == NULL)
-                                               {
-                                                       close (fin);
-
-                                                       if (blob->op)
-                                                               {
-                                                                       GValue *dest_value;
-                                                                       GdaBlob *dest_blob;
-
-                                                                       dest_value = gda_value_new_blob_from_file (filename_tmp);
-                                                                       dest_blob = (GdaBlob *)gda_value_get_blob (dest_value);
-                                                                       if (!gda_blob_op_write_all (dest_blob->op, (GdaBlob *)blob))
-                                                                               {
-                                                                                       g_warning ("Errore nella lettura dell'allegato.");
-                                                                                       g_free (ret);
-                                                                                       ret = NULL;
-                                                                               }
-                                                                       else
-                                                                               {
-                                                                                       ret = g_strdup (filename_tmp);
-                                                                               }
-                                                                       gda_value_free (dest_value);
-                                                               }
-                                                       else
-                                                               {
-                                                                       error = NULL;
-                                                                       if (!g_file_set_contents (filename_tmp, (gchar *)((GdaBinary*)blob)->data,
-                                                                                                 ((GdaBinary*)blob)->binary_length, &error) || error != NULL)
-                                                                               {
-                                                                                       g_warning ("Errore nella lettura dell'allegato.");
-                                                                                       g_free (ret);
-                                                                                       ret = NULL;
-                                                                               }
-                                                                       else
-                                                                               {
-                                                                                       ret = g_strdup (filename_tmp);
-                                                                               }
-                                                               }
-                                               }
-                                       else
-                                               {
-                                                       g_warning ("Errore nella lettura dell'allegato: %s.",
-                                                                  error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
-                                                       g_free (ret);
-                                                       ret = NULL;
-                                               }
-
-                                       g_free (filename_tmp);
-                                       g_free (filename_orig);
-                               }
-
-                       g_object_unref (dm);
-               }
-
-       return ret;
+       return gdaex_get_blob (gdaex, sql, percorso_field_name, blob_field_name);
 }
 
 void
index 51f9e562d80574e27c6c445cf3ad3546a556626d..f9ba9021ad7ee92154cb6c4b88721bc01bca0635 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include <libgda/libgda.h>
+#include <libgdaex/libgdaex.h>
 #include <libgtkform/form.h>
 
 #include "solipa.h"
@@ -67,6 +67,7 @@ guint solipa_allegato_get_dimensione (SolipaAllegato *solipa_allegato);
 gboolean solipa_allegato_get_salva_in_db (SolipaAllegato *solipa_allegato);
 void solipa_allegato_set_salva_in_db (SolipaAllegato *solipa_allegato, gboolean salva);
 
+G_DEPRECATED_FOR (gdaex_get_blob)
 const gchar *solipa_allegato_get_blob (GdaEx *gdaex,
                            const gchar *sql,
                            const gchar *percorso_field_name,
@@ -79,7 +80,8 @@ void solipa_allegato_add_to_gtkform (SolipaAllegato *solipa_allegato, GtkForm *f
 
 void solipa_allegato_apri_allegato (GtkWindow *transient, const gchar *filename);
 
-gboolean solipa_allegato_salva_in_db (GdaConnection *gda_con, const gchar *sql,
+G_DEPRECATED_FOR (gdaex_save_file_in_blob)
+gboolean solipa_allegato_salva_in_db (GdaEx *gdaexx, const gchar *sql,
                                       const gchar *blob_field_name, const gchar *percorso);