]> saetta.ns0.it Git - libgdaex/commitdiff
Added function save_data_in_blob.
authorAndrea Zagli <andrea.zagli@email.it>
Mon, 8 May 2017 14:40:20 +0000 (16:40 +0200)
committerAndrea Zagli <andrea.zagli@email.it>
Mon, 8 May 2017 14:40:20 +0000 (16:40 +0200)
src/gdaex.c
src/gdaex.h

index ae68ed6322481b1f2c44fdd676734fdb94c778cd..fc6938ef6dbdf4f0c76e3e8972c75209ef61668c 100644 (file)
@@ -3530,20 +3530,13 @@ gchar
        return ret;
 }
 
-/**
- * gdaex_save_file_in_blob:
- * @gdaex:
- * @sql:
- * @blob_field_name:
- * @filename:
- *
- * Returns:
- */
 gboolean
-gdaex_save_file_in_blob (GdaEx *gdaex,
-                                                const gchar *sql,
-                                                const gchar *blob_field_name,
-                                                const gchar *filename)
+_gdaex_save_data_file_in_blob (GdaEx *gdaex,
+                               const gchar *sql,
+                               const gchar *blob_field_name,
+                               const guchar *data,
+                               glong size,
+                               const gchar *filename)
 {
        GdaConnection *gda_con;
        GdaSqlParser *parser;
@@ -3578,7 +3571,16 @@ gdaex_save_file_in_blob (GdaEx *gdaex,
        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 (filename);
+
+       if (data != NULL)
+               {
+                       value = gda_value_new_blob (data, size);
+               }
+       else
+               {
+                       value = gda_value_new_blob_from_file (filename);
+               }
+
        error = NULL;
        if (!gda_holder_take_value (param, value, &error))
                {
@@ -3611,9 +3613,52 @@ gdaex_save_file_in_blob (GdaEx *gdaex,
                        gda_connection_commit_transaction (gda_con, NULL, NULL);
                }
 
+       if (value != NULL)
+               {
+                       g_value_unset (value);
+               }
+
        return TRUE;
 }
 
+/**
+ * gdaex_save_file_in_blob:
+ * @gdaex:
+ * @sql:
+ * @blob_field_name:
+ * @data:
+ * @size:
+ *
+ * Returns:
+ */
+gboolean
+gdaex_save_data_in_blob (GdaEx *gdaex,
+                         const gchar *sql,
+                         const gchar *blob_field_name,
+                         const guchar *data,
+                         glong size)
+{
+       return _gdaex_save_data_file_in_blob (gdaex, sql, blob_field_name, data, size, NULL);
+}
+
+/**
+ * gdaex_save_file_in_blob:
+ * @gdaex:
+ * @sql:
+ * @blob_field_name:
+ * @filename:
+ *
+ * Returns:
+ */
+gboolean
+gdaex_save_file_in_blob (GdaEx *gdaex,
+                         const gchar *sql,
+                         const gchar *blob_field_name,
+                         const gchar *filename)
+{
+       return _gdaex_save_data_file_in_blob (gdaex, sql, blob_field_name, NULL, 0, filename);
+}
+
 /**
  * gdaex_get_blob:
  * @gdaex:
index 4ee5bbe961560f1ab5a74e0a1cf9b9fb24b52cc4..555c9b5682f21ee9f50a83ca61b873c6bb9bebff 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  gdaex.h
  *
- *  Copyright (C) 2005-2016 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2005-2017 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaex.
  *
@@ -110,81 +110,81 @@ GDateTime *gdaex_data_model_get_field_value_gdatetime_at (GdaDataModel *data_mod
                                                  gint row,
                                                  const gchar *field_name);
 struct tm *gdaex_data_model_get_field_value_tm_at (GdaDataModel *data_model,
-                                                 gint row,
-                                                 const gchar *field_name);
+                                                   gint row,
+                                                   const gchar *field_name);
 
 gchar *gdaex_data_model_get_value_stringify_at (GdaDataModel *data_model,
-                                               gint row,
-                                               gint col);
+                                                gint row,
+                                                gint col);
 gchar *gdaex_data_model_get_value_stringify_escaped_at (GdaDataModel *data_model,
-                                               gint row,
-                                               gint col);
+                                                        gint row,
+                                                        gint col);
 gint gdaex_data_model_get_value_integer_at (GdaDataModel *data_model,
-                                           gint row,
-                                           gint col);
+                                            gint row,
+                                            gint col);
 gfloat gdaex_data_model_get_value_float_at (GdaDataModel *data_model,
-                                           gint row,
-                                           gint col);
+                                            gint row,
+                                            gint col);
 gdouble gdaex_data_model_get_value_double_at (GdaDataModel *data_model,
-                                             gint row,
-                                             gint col);
+                                              gint row,
+                                              gint col);
 gboolean gdaex_data_model_get_value_boolean_at (GdaDataModel *data_model,
-                                               gint row,
-                                               gint col);
+                                                gint row,
+                                                gint col);
 GdaTimestamp *gdaex_data_model_get_value_gdatimestamp_at (GdaDataModel *data_model,
                                                           gint row,
                                                           gint col);
 GDate *gdaex_data_model_get_value_gdate_at (GdaDataModel *data_model,
-                                           gint row,
-                                           gint col);
+                                            gint row,
+                                            gint col);
 GDateTime *gdaex_data_model_get_value_gdatetime_at (GdaDataModel *data_model,
-                                           gint row,
-                                           gint col);
+                                                    gint row,
+                                                    gint col);
 struct tm *gdaex_data_model_get_value_tm_at (GdaDataModel *data_model,
-                                           gint row,
-                                           gint col);
+                                             gint row,
+                                             gint col);
 
 gchar *gdaex_data_model_iter_get_field_value_stringify_at (GdaDataModelIter *iter,
-                                                     const gchar *field_name);
+                                                           const gchar *field_name);
 gchar *gdaex_data_model_iter_get_field_value_stringify_escaped_at (GdaDataModelIter *iter,
-                                                     const gchar *field_name);
+                                                                   const gchar *field_name);
 gint gdaex_data_model_iter_get_field_value_integer_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                       const gchar *field_name);
 gfloat gdaex_data_model_iter_get_field_value_float_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                       const gchar *field_name);
 gdouble gdaex_data_model_iter_get_field_value_double_at (GdaDataModelIter *iter,
-                                                   const gchar *field_name);
+                                                         const gchar *field_name);
 gboolean gdaex_data_model_iter_get_field_value_boolean_at (GdaDataModelIter *iter,
-                                                     const gchar *field_name);
+                                                           const gchar *field_name);
 GdaTimestamp *gdaex_data_model_iter_get_field_value_gdatimestamp_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                                     const gchar *field_name);
 GDate *gdaex_data_model_iter_get_field_value_gdate_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                       const gchar *field_name);
 GDateTime *gdaex_data_model_iter_get_field_value_gdatetime_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                               const gchar *field_name);
 struct tm *gdaex_data_model_iter_get_field_value_tm_at (GdaDataModelIter *iter,
-                                                 const gchar *field_name);
+                                                        const gchar *field_name);
 
 gchar *gdaex_data_model_iter_get_value_stringify_at (GdaDataModelIter *iter,
-                                               gint col);
+                                                     gint col);
 gchar *gdaex_data_model_iter_get_value_stringify_escaped_at (GdaDataModelIter *iter,
-                                               gint col);
+                                                             gint col);
 gint gdaex_data_model_iter_get_value_integer_at (GdaDataModelIter *iter,
-                                           gint col);
+                                                 gint col);
 gfloat gdaex_data_model_iter_get_value_float_at (GdaDataModelIter *iter,
-                                           gint col);
+                                                 gint col);
 gdouble gdaex_data_model_iter_get_value_double_at (GdaDataModelIter *iter,
-                                             gint col);
+                                                   gint col);
 gboolean gdaex_data_model_iter_get_value_boolean_at (GdaDataModelIter *iter,
-                                               gint col);
+                                                     gint col);
 GdaTimestamp *gdaex_data_model_iter_get_value_gdatimestamp_at (GdaDataModelIter *iter,
-                                                          gint col);
+                                                               gint col);
 GDate *gdaex_data_model_iter_get_value_gdate_at (GdaDataModelIter *iter,
-                                           gint col);
+                                                 gint col);
 GDateTime *gdaex_data_model_iter_get_value_gdatetime_at (GdaDataModelIter *iter,
-                                           gint col);
+                                                         gint col);
 struct tm *gdaex_data_model_iter_get_value_tm_at (GdaDataModelIter *iter,
-                                           gint col);
+                                                  gint col);
 
 GHashTable *gdaex_data_model_columns_to_hashtable (GdaDataModel *dm);
 GHashTable *gdaex_data_model_row_to_hashtable (GdaDataModel *dm, guint row);
@@ -295,15 +295,21 @@ gchar *gdaex_format_money (gdouble number,
                      gint decimals,
                      gboolean with_currency_symbol);
 
+gboolean gdaex_save_data_in_blob (GdaEx *gdaex,
+                                  const gchar *sql,
+                                  const gchar *blob_field_name,
+                                  const guchar *data,
+                                  glong size);
+
 gboolean gdaex_save_file_in_blob (GdaEx *gdaex,
-                                                                 const gchar *sql,
-                                                                 const gchar *blob_field_name,
-                                                                 const gchar *filename);
+                                  const gchar *sql,
+                                  const gchar *blob_field_name,
+                                  const gchar *filename);
 
 const gchar *gdaex_get_blob (GdaEx *gdaex,
-                                                        const gchar *sql,
-                                                        const gchar *filename_field_name,
-                                                        const gchar *blob_field_name);
+                             const gchar *sql,
+                             const gchar *filename_field_name,
+                             const gchar *blob_field_name);
 
 
 G_END_DECLS