[libgda] Added gda_parse_string()



commit 1d73889dc16b2757051ced2376082d8695d92c8e
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Jun 11 21:38:45 2010 +0200

    Added gda_parse_string()
    
    thanks to Daniel Espinosa

 doc/C/libgda-sections.txt      |    2 +
 doc/C/tmpl/gda-convenient.sgml |   12 +++++++++++
 libgda/gda-easy.c              |   41 ++++++++++++++++++++++++++++++++++++++++
 libgda/gda-easy.h              |    3 +-
 libgda/libgda.symbols          |    1 +
 5 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index 8abeb24..5b3792a 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -919,6 +919,8 @@ gda_insert_row_into_table
 gda_update_row_in_table
 gda_delete_row_from_table
 <SUBSECTION>
+gda_parse_string
+<SUBSECTION>
 gda_get_default_handler
 </SECTION>
 
diff --git a/doc/C/tmpl/gda-convenient.sgml b/doc/C/tmpl/gda-convenient.sgml
index 814d12b..4ba249d 100644
--- a/doc/C/tmpl/gda-convenient.sgml
+++ b/doc/C/tmpl/gda-convenient.sgml
@@ -168,6 +168,18 @@ Do quickly some actions
 @Returns: 
 
 
+<!-- ##### FUNCTION gda_parse_string ##### -->
+<para>
+
+</para>
+
+ cnc: 
+ sql: 
+ params: 
+ error: 
+ Returns: 
+
+
 <!-- ##### FUNCTION gda_get_default_handler ##### -->
 <para>
 
diff --git a/libgda/gda-easy.c b/libgda/gda-easy.c
index 5879c9d..0c43559 100644
--- a/libgda/gda-easy.c
+++ b/libgda/gda-easy.c
@@ -1050,3 +1050,44 @@ gda_delete_row_from_table (GdaConnection *cnc, const gchar *table,
 	return retval;
 }
 
+/**
+ * gda_parse_string
+ * @cnc: (allow-none): a #GdaConnection object, or %NULL
+ * @sql: an SQL command to parse, not %NULL
+ * @params: (out) (allow-none) (transfer full): a place to store a new #GdaSet, for parameters used in SQL command, or %NULL
+ * @error: a place to store errors, or %NULL
+ *
+ * This function helps to parse a SQL witch use paramenters and store them at @params.
+ *
+ * Returns: a #GdaStatement representing the SQL command, or %NULL if an error occurred
+ *
+ * Since: 4.2
+ */
+GdaStatement*
+gda_parse_string (GdaConnection *cnc, const gchar *sql, GdaSet **params, GError **error)
+{
+	GdaStatement *stmt;
+	GdaSqlParser *parser = NULL;
+
+	g_return_val_if_fail (!cnc || GDA_IS_CONNECTION (cnc), NULL);
+	g_return_val_if_fail (sql, NULL);
+
+	if (params)
+		*params = NULL;
+	if (cnc)
+		parser = gda_connection_create_parser (cnc);
+	if (!parser)
+		parser = gda_sql_parser_new ();
+
+	stmt = gda_sql_parser_parse_string (parser, sql, NULL, error);
+	g_object_unref (parser);
+	if (! stmt)
+		return NULL;
+
+	if (params && !gda_statement_get_parameters (stmt, params, error)) {
+		g_object_unref (stmt);
+		return NULL;
+	}
+	
+	return stmt;
+}
diff --git a/libgda/gda-easy.h b/libgda/gda-easy.h
index 22d1e4f..b44f97f 100644
--- a/libgda/gda-easy.h
+++ b/libgda/gda-easy.h
@@ -60,7 +60,8 @@ typedef enum
  * Convenient Functions
  */
 GdaDataHandler     *gda_get_default_handler           (GType for_type);
-
+GdaStatement       *gda_parse_string                  (GdaConnection *cnc, const gchar *sql, GdaSet **params,
+    												   GError **error);
 /*
  * Quick commands execution
  */
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 75b7d4b..084b1d2 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -457,6 +457,7 @@
 	gda_parse_iso8601_date
 	gda_parse_iso8601_time
 	gda_parse_iso8601_timestamp
+	gda_parse_string
 	gda_perform_create_database
 	gda_perform_create_table
 	gda_perform_drop_database



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]