1 /* 2 * Copyright (C) 2000 Reinhard Müller <reinhard@src.gnome.org> 3 * Copyright (C) 2000 - 2002 Rodrigo Moya <rodrigo@gnome-db.org> 4 * Copyright (C) 2001 Carlos Perelló Marín <carlos@gnome-db.org> 5 * Copyright (C) 2001 - 2013 Vivien Malerba <malerba@gnome-db.org> 6 * Copyright (C) 2002 Gonzalo Paniagua Javier <gonzalo@src.gnome.org> 7 * Copyright (C) 2006 - 2007 Murray Cumming <murrayc@murrayc.com> 8 * Copyright (C) 2007 Armin Burgmeier <armin@openismus.com> 9 * Copyright (C) 2008 Przemysław Grzegorczyk <pgrzegorczyk@gmail.com> 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this library; if not, write to the 23 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 24 * Boston, MA 02110-1301, USA. 25 */ 26 27 #ifndef __GDA_UTIL_H__ 28 #define __GDA_UTIL_H__ 29 30 #include <glib.h> 31 #include "gda-holder.h" 32 #include "gda-row.h" 33 #include "gda-connection.h" 34 #include <sql-parser/gda-sql-statement.h> 35 #include <libgda/gda-data-select.h> 36 37 G_BEGIN_DECLS 38 39 /** 40 * SECTION:gda-util 41 * @short_description: Utility functions 42 * @title: Utility functions 43 * @stability: Stable 44 * @see_also: 45 * 46 * Some useful functions. 47 */ 48 49 /* 50 * Type utilities 51 */ 52 const gchar *gda_g_type_to_string (GType type); 53 GType gda_g_type_from_string (const gchar *str); 54 55 /* 56 * SQL escaping 57 */ 58 gchar *gda_default_escape_string (const gchar *string); 59 gchar *gda_default_unescape_string (const gchar *string); 60 guint gda_identifier_hash (const gchar *id); 61 gboolean gda_identifier_equal (const gchar *id1, const gchar *id2); 62 gchar **gda_completion_list_get (GdaConnection *cnc, const gchar *sql, gint start, gint end); 63 gchar **gda_sql_identifier_split (const gchar *id); 64 gchar *gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider *prov, 65 gboolean meta_store_convention, gboolean force_quotes); 66 67 /* 68 * Param & model utilities 69 */ 70 gboolean gda_utility_check_data_model (GdaDataModel *model, gint nbcols, ...); 71 gboolean gda_utility_check_data_model_v (GdaDataModel *model, gint nbcols, GType* types); 72 gboolean gda_utility_data_model_dump_data_to_xml (GdaDataModel *model, xmlNodePtr parent, 73 const gint *cols, gint nb_cols, const gint *rows, gint nb_rows, 74 gboolean use_col_ids); 75 const gchar *gda_utility_data_model_find_column_description (GdaDataSelect *model, const gchar *field_name); 76 gboolean gda_utility_holder_load_attributes (GdaHolder *holder, xmlNodePtr node, GSList *sources, GError **error); 77 78 GdaSqlStatement *gda_statement_rewrite_for_default_values (GdaStatement *stmt, GdaSet *params, 79 gboolean remove, GError **error); 80 81 /* 82 * translate any text to an alphanumerical text 83 */ 84 gchar *gda_text_to_alphanum (const gchar *text); 85 gchar *gda_alphanum_to_text (gchar *text); 86 87 /* 88 * Statement computation (using data from meta store) 89 */ 90 GdaSqlExpr *gda_compute_unique_table_row_condition (GdaSqlStatementSelect *stsel, GdaMetaTable *mtable, 91 gboolean require_pk, GError **error); 92 GdaSqlExpr *gda_compute_unique_table_row_condition_with_cnc (GdaConnection *cnc, 93 GdaSqlStatementSelect *stsel, 94 GdaMetaTable *mtable, gboolean require_pk, 95 GError **error); 96 97 gboolean gda_compute_dml_statements (GdaConnection *cnc, GdaStatement *select_stmt, gboolean require_pk, 98 GdaStatement **insert_stmt, GdaStatement **update_stmt, GdaStatement **delete_stmt, 99 GError **error); 100 GdaSqlStatement *gda_compute_select_statement_from_update (GdaStatement *update_stmt, GError **error); 101 GdaSqlStatement *gda_rewrite_sql_statement_for_null_parameters (GdaSqlStatement *sqlst, GdaSet *params, 102 gboolean *out_modified, GError **error); 103 gboolean gda_rewrite_statement_for_null_parameters (GdaStatement *stmt, GdaSet *params, 104 GdaStatement **out_stmt, GError **error); 105 void _gda_modify_statement_param_types (GdaStatement *stmt, GdaDataModel *model); 106 107 /* 108 * DSN and connection string manipulations 109 */ 110 gchar *gda_rfc1738_encode (const gchar *string); 111 gboolean gda_rfc1738_decode (gchar *string); 112 void gda_dsn_split (const gchar *string, gchar **out_dsn, 113 gchar **out_username, gchar **out_password); 114 void gda_connection_string_split (const gchar *string, gchar **out_cnc_params, gchar **out_provider, 115 gchar **out_username, gchar **out_password); 116 117 /* 118 * Date and time parsing from ISO 8601 (well, part of it) 119 */ 120 gboolean gda_parse_iso8601_date (GDate *gdate, const gchar *value); 121 gboolean gda_parse_iso8601_time (GdaTime *timegda, const gchar *value); 122 gboolean gda_parse_iso8601_timestamp (GdaTimestamp *timestamp, const gchar *value); 123 gboolean gda_parse_formatted_date (GDate *gdate, const gchar *value, 124 GDateDMY first, GDateDMY second, GDateDMY third, gchar sep); 125 gboolean gda_parse_formatted_time (GdaTime *timegda, const gchar *value, gchar sep); 126 gboolean gda_parse_formatted_timestamp (GdaTimestamp *timestamp, const gchar *value, 127 GDateDMY first, GDateDMY second, GDateDMY third, gchar sep); 128 129 G_END_DECLS 130 131 #endif 132