From 0b79feca32645331e827a53bbc7599ed9d6d88fa Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 8 May 2017 16:40:20 +0200 Subject: [PATCH] Added function save_data_in_blob. --- src/gdaex.c | 73 ++++++++++++++++++++++++++++++-------- src/gdaex.h | 100 ++++++++++++++++++++++++++++------------------------ 2 files changed, 112 insertions(+), 61 deletions(-) diff --git a/src/gdaex.c b/src/gdaex.c index ae68ed6..fc6938e 100644 --- a/src/gdaex.c +++ b/src/gdaex.c @@ -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: diff --git a/src/gdaex.h b/src/gdaex.h index 4ee5bbe..555c9b5 100644 --- a/src/gdaex.h +++ b/src/gdaex.h @@ -1,7 +1,7 @@ /* * gdaex.h * - * Copyright (C) 2005-2016 Andrea Zagli + * Copyright (C) 2005-2017 Andrea Zagli * * 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 -- 2.49.0