[libgda] Added gda_sql_statement_check_validity_m()
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Added gda_sql_statement_check_validity_m()
- Date: Sun, 5 Sep 2010 13:12:26 +0000 (UTC)
commit 009c1a888fd999330d004052493fac59153f9797
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Sep 3 22:29:27 2010 +0200
Added gda_sql_statement_check_validity_m()
which can be used in a similar way to gda_sql_statement_check_validity()
but using meta data information from a GdaMetaStruct instead of from
a GdaConnection
doc/C/libgda-sections.txt | 1 +
doc/C/tmpl/gda-sql-statement.sgml | 11 ++++++
libgda/libgda.symbols | 1 +
libgda/sql-parser/gda-statement-struct.c | 56 ++++++++++++++++++++++++++++-
libgda/sql-parser/gda-statement-struct.h | 4 ++
5 files changed, 71 insertions(+), 2 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index a46b61e..cd313bc 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -1153,6 +1153,7 @@ gda_sql_statement_type_to_string
gda_sql_statement_string_to_type
gda_sql_statement_check_structure
gda_sql_statement_check_validity
+gda_sql_statement_check_validity_m
gda_sql_statement_check_clean
gda_sql_statement_normalize
<SUBSECTION>
diff --git a/doc/C/tmpl/gda-sql-statement.sgml b/doc/C/tmpl/gda-sql-statement.sgml
index 1f6f66d..ae4eddc 100644
--- a/doc/C/tmpl/gda-sql-statement.sgml
+++ b/doc/C/tmpl/gda-sql-statement.sgml
@@ -142,6 +142,17 @@ Known types of statements
@Returns:
+<!-- ##### FUNCTION gda_sql_statement_check_validity_m ##### -->
+<para>
+
+</para>
+
+ stmt:
+ mstruct:
+ error:
+ Returns:
+
+
<!-- ##### FUNCTION gda_sql_statement_check_clean ##### -->
<para>
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 7bde6d0..4ed91b2 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -711,6 +711,7 @@
gda_sql_statement_check_clean
gda_sql_statement_check_structure
gda_sql_statement_check_validity
+ gda_sql_statement_check_validity_m
gda_sql_statement_compound_set_type
gda_sql_statement_compound_take_stmt
gda_sql_statement_compound_type_get_type
diff --git a/libgda/sql-parser/gda-statement-struct.c b/libgda/sql-parser/gda-statement-struct.c
index 48866d9..ef12a97 100644
--- a/libgda/sql-parser/gda-statement-struct.c
+++ b/libgda/sql-parser/gda-statement-struct.c
@@ -355,6 +355,60 @@ gda_sql_statement_check_validity (GdaSqlStatement *stmt, GdaConnection *cnc, GEr
return TRUE;
}
+/**
+ * gda_sql_statement_check_validity_m
+ * @stmt: a #GdaSqlStatement pointer
+ * @mstruct: a #GdaMetaStruct object, or %NULL
+ * @error: a place to store errors, or %NULL
+ *
+ * If @mstruct is not %NULL, then checks that all the database objects referenced in the statement i
+ * actually referenced in @mstruct
+ * (for example the table being updated in a UPDATE statement must exist in the
+ * connection's database for the check to succeed).
+ * This method sets the @stmt->validity_meta_struct attribute to @mstruct.
+ *
+ * If @mstruct is %NULL, then remove any information from a previous call to this method stored in @stmt. In this case,
+ * the @stmt->validity_meta_struct attribute is cleared.
+ *
+ * Also note that some parts of @stmt may be modified: for example leading and trailing spaces in aliases or
+ * objects names will be removed.
+ *
+ * Returns: TRUE if no error occurred
+ *
+ * Since: 4.2
+ */
+gboolean
+gda_sql_statement_check_validity_m (GdaSqlStatement *stmt, GdaMetaStruct *mstruct, GError **error)
+{
+ g_return_val_if_fail (stmt, FALSE);
+ g_return_val_if_fail (!mstruct || GDA_IS_META_STRUCT (mstruct), FALSE);
+
+ /* check the structure first */
+ if (!gda_sql_statement_check_structure (stmt, error))
+ return FALSE;
+
+ /* clear any previous setting */
+ gda_sql_statement_check_clean (stmt);
+
+ if (mstruct) {
+ GdaSqlStatementCheckValidityData data;
+ gboolean retval;
+
+ /* prepare data */
+ data.cnc = NULL;
+ data.store = NULL;
+ data.mstruct = g_object_ref (mstruct);
+
+ /* attach the GdaMetaStruct to @stmt */
+ stmt->validity_meta_struct = data.mstruct;
+ retval = gda_sql_any_part_foreach (GDA_SQL_ANY_PART (stmt->contents),
+ (GdaSqlForeachFunc) foreach_check_validity, &data, error);
+ return retval;
+ }
+ else
+ return TRUE;
+}
+
static gboolean
foreach_check_validity (GdaSqlAnyPart *node, GdaSqlStatementCheckValidityData *data, GError **error)
{
@@ -516,8 +570,6 @@ gda_sql_field_check_validity (GdaSqlField *field, GdaSqlStatementCheckValidityDa
if (!field) return TRUE;
_gda_sql_field_check_clean (field);
- if (!data->cnc) return TRUE;
-
for (any = GDA_SQL_ANY_PART(field)->parent;
any && (any->type != GDA_SQL_ANY_STMT_INSERT) && (any->type != GDA_SQL_ANY_STMT_UPDATE);
any = any->parent);
diff --git a/libgda/sql-parser/gda-statement-struct.h b/libgda/sql-parser/gda-statement-struct.h
index 0510477..4a45003 100644
--- a/libgda/sql-parser/gda-statement-struct.h
+++ b/libgda/sql-parser/gda-statement-struct.h
@@ -51,6 +51,10 @@ GdaSqlStatementType gda_sql_statement_string_to_type (const gchar *type
gboolean gda_sql_statement_check_structure (GdaSqlStatement *stmt, GError **error);
gboolean gda_sql_statement_check_validity (GdaSqlStatement *stmt, GdaConnection *cnc, GError **error);
+gboolean gda_sql_statement_check_validity_m (GdaSqlStatement *stmt,
+ GdaMetaStruct *mstruct,
+ GError **error);
+
void gda_sql_statement_check_clean (GdaSqlStatement *stmt);
gboolean gda_sql_statement_normalize (GdaSqlStatement *stmt, GdaConnection *cnc, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]