|| gda_col_gtype == GDA_TYPE_TIMESTAMP)
{
gdatetime = gdaex_data_model_iter_get_field_value_gdatetime_at (dm_iter, field_name);
- /* TODO find default format from locale */
- g_value_set_string (gval, g_date_time_format (gdatetime, gda_col_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
- g_date_time_unref (gdatetime);
+ if (gdatetime != NULL)
+ {
+ /* TODO find default format from locale */
+ g_value_set_string (gval, g_date_time_format (gdatetime, gda_col_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
+ g_date_time_unref (gdatetime);
+ }
+ else
+ {
+ g_value_set_string (gval, "");
+ }
}
else
{
return ret;
}
+/**
+ * gdaex_grid_html_fill_from_sql_with_missing_func:
+ * @grid: a #GdaExGrid object.
+ * @gdaex: a #GdaEx object.
+ * @sql: the sql statement to use as datasource.
+ * @missing_func:
+ * @user_data:
+ * @pagination_start:
+ * @pagination_page:
+ * @error: where return errors.
+ *
+ * Fills the grid.
+ *
+ * Returns: TRUE if success.
+ */
+gchar
+*gdaex_grid_html_fill_from_sql_with_missing_func (GdaExGrid *grid,
+ GdaEx *gdaex,
+ const gchar *sql,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error)
+{
+ GdaDataModel *dm;
+
+ gchar *_sql;
+
+ gchar *ret;
+
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), "");
+ g_return_val_if_fail (IS_GDAEX (gdaex), "");
+ g_return_val_if_fail (sql != NULL, "");
+
+ _sql = g_strstrip (g_strdup (sql));
+
+ g_return_val_if_fail (g_strcmp0 (_sql, "") != 0, "");
+
+ dm = gdaex_query (gdaex, _sql);
+ g_free (_sql);
+ ret = gdaex_grid_html_fill_from_datamodel_with_missing_func (grid, dm, missing_func, user_data, pagination_start, pagination_page, error);
+ g_object_unref (dm);
+
+ return ret;
+}
+
+/**
+ * gdaex_grid_html_fill_from_datamodel_with_missing_func:
+ * @grid: a #GdaExGrid object.
+ * @dm: a #GdaDataModel object to use as datasource.
+ * @missing_func:
+ * @user_data:
+ * @pagination_start:
+ * @pagination_page:
+ * @error: where return errors.
+ *
+ * Fills the grid.
+ *
+ * Returns: TRUE if success.
+ */
+gchar
+*gdaex_grid_html_fill_from_datamodel_with_missing_func (GdaExGrid *grid,
+ GdaDataModel *dm,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error)
+{
+ gchar *ret;
+
+ GdaExGridPrivate *priv;
+
+ GString *str;
+
+ GdaDataModelIter *dm_iter;
+
+ guint row;
+ guint rows;
+
+ guint col;
+
+ GdaExGridColumn *gdaex_col;
+
+ const gchar *field_name;
+
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), "");
+ g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), "");
+
+ priv = gdaex_grid_get_instance_private (grid);
+
+ dm_iter = gda_data_model_create_iter (dm);
+ g_return_val_if_fail (GDA_IS_DATA_MODEL_ITER (dm_iter), "");
+
+ str = g_string_new ("");
+
+ rows = gda_data_model_get_n_rows (dm);
+
+ if (priv->app_textdomain != NULL)
+ {
+ textdomain (priv->app_textdomain);
+ }
+
+ while (gda_data_model_iter_move_next (dm_iter))
+ {
+ g_string_append (str, "<tr>\n");
+ for (col = 0; col < priv->columns->len; col++)
+ {
+ GValue gval = {0};
+
+ g_value_init (&gval, G_TYPE_STRING);
+
+ gdaex_col = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
+ field_name = gdaex_grid_column_get_field_name (gdaex_col);
+
+ /* checking if field exists */
+ if (gda_data_model_get_column_index (dm, field_name) == -1)
+ {
+ g_value_set_string (&gval, missing_func (dm_iter, gdaex_col, user_data));
+ }
+ else
+ {
+ _set_gvalue_stringify_from_datamodel((GdaExGridColumn *)g_ptr_array_index (priv->columns, col), &gval, dm, dm_iter, field_name);
+ }
+
+ g_string_append_printf (str, "\t<td>%s</td>\n", g_value_get_string (&gval));
+ }
+
+ g_string_append (str, "</tr>\n");
+ }
+
+ ret = g_strdup (str->str);
+ g_string_free (str, TRUE);
+
+ if (priv->app_textdomain != NULL)
+ {
+ textdomain (GETTEXT_PACKAGE);
+ }
+
+ return ret;
+}
+
+/**
+ * gdaex_grid_html_fill_from_sqlbuilder_with_missing_func:
+ * @grid: a #GdaExGrid object.
+ * @gdaex: a #GdaEx object.
+ * @builder: a #GdaExSqlBuilder object.
+ * @missing_func:
+ * @user_data:
+ * @pagination_start:
+ * @pagination_page:
+ * @error: where return errors.
+ *
+ * Fills the grid.
+ *
+ * Returns: TRUE if success.
+ */
+gchar
+*gdaex_grid_html_fill_from_sqlbuilder_with_missing_func (GdaExGrid *grid,
+ GdaEx *gdaex,
+ GdaExSqlBuilder *builder,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error)
+{
+ GdaDataModel *dm;
+
+ gchar *ret;
+
+ g_return_val_if_fail (GDAEX_IS_GRID (grid), "");
+ g_return_val_if_fail (IS_GDAEX (gdaex), "");
+ g_return_val_if_fail (GDAEX_IS_SQLBUILDER (builder), "");
+
+ dm = gdaex_sql_builder_query (builder, gdaex, NULL);
+ ret = gdaex_grid_html_fill_from_datamodel_with_missing_func (grid, dm, missing_func, user_data, pagination_start, pagination_page, error);
+ g_object_unref (dm);
+
+ return ret;
+}
+
/* PRIVATE */
static void
gdaex_grid_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
gboolean gdaex_grid_fill_from_sqlbuilder (GdaExGrid *grid, GdaEx *gdaex, GdaExSqlBuilder *builder, GError **error);
+typedef gchar *(*GdaExGridHtmlFillMissingFunc) (GdaDataModelIter *iter, GdaExGridColumn *column, gpointer user_data);
+
gchar *gdaex_grid_html_get_header (GdaExGrid *grid);
+gchar *gdaex_grid_html_fill_from_sql_with_missing_func (GdaExGrid *grid,
+ GdaEx *gdaex,
+ const gchar *sql,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error);
+gchar *gdaex_grid_html_fill_from_datamodel_with_missing_func (GdaExGrid *grid,
+ GdaDataModel *dm,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error);
+gchar *gdaex_grid_html_fill_from_sqlbuilder_with_missing_func (GdaExGrid *grid,
+ GdaEx *gdaex,
+ GdaExSqlBuilder *sqlbuilder,
+ GdaExGridHtmlFillMissingFunc missing_func, gpointer user_data,
+ guint pagination_start,
+ guint pagination_page,
+ GError **error);
+
G_END_DECLS