[libgda] SQL identifiers case sensitiveness specified in the connection
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgda] SQL identifiers case sensitiveness specified in the connection
- Date: Thu, 23 Jul 2009 19:37:30 +0000 (UTC)
commit 97569cef94d94bc0a7ab0af68534a18651c45597
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Jul 23 20:49:57 2009 +0200
SQL identifiers case sensitiveness specified in the connection
* added the GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE flag
when opening a connection
* added gda_connection_quote_sql_identifier()
* added gda_meta_store_sql_identifier_quote()
* added gda_server_operation_get_sql_identifier_at(), to be used by database provider's
implementations when getting a value which is an SQL identifier from a GdaServerOperation
* modified the providers' DDL implemntations to use gda_server_operation_get_sql_identifier_at()
doc/C/libgda-4.0-sections.txt | 3 +
doc/C/tmpl/gda-connection.sgml | 19 ++-
doc/C/tmpl/gda-meta-store.sgml | 10 +
doc/C/tmpl/gda-server-operation.sgml | 13 +
libgda/gda-connection.c | 45 ++++-
libgda/gda-connection.h | 30 +++-
libgda/gda-meta-store.c | 31 +++-
libgda/gda-meta-store.h | 1 +
libgda/gda-server-operation.c | 101 +++++++--
libgda/gda-server-operation.h | 3 +
libgda/libgda.symbols | 3 +
libgda/sqlite/gda-sqlite-ddl.c | 117 +++++-----
providers/jdbc/gda-jdbc-ddl.c | 33 ++-
providers/mysql/gda-mysql-ddl.c | 245 ++++++++++---------
providers/oracle/gda-oracle-ddl.c | 37 ++--
providers/postgres/gda-postgres-ddl.c | 262 +++++++++++----------
providers/skel-implementation/capi/gda-capi-ddl.c | 39 ++--
17 files changed, 622 insertions(+), 370 deletions(-)
---
diff --git a/doc/C/libgda-4.0-sections.txt b/doc/C/libgda-4.0-sections.txt
index 5e4a694..997d65a 100644
--- a/doc/C/libgda-4.0-sections.txt
+++ b/doc/C/libgda-4.0-sections.txt
@@ -116,6 +116,7 @@ gda_connection_is_opened
<SUBSECTION>
gda_connection_create_parser
gda_connection_value_to_sql_string
+gda_connection_quote_sql_identifier
gda_connection_statement_to_sql
gda_connection_statement_prepare
gda_connection_statement_execute
@@ -439,6 +440,7 @@ gda_server_operation_get_op_type
gda_server_operation_op_type_to_string
<SUBSECTION>
gda_server_operation_get_value_at
+gda_server_operation_get_sql_identifier_at
gda_server_operation_set_value_at
gda_server_operation_save_data_to_xml
gda_server_operation_load_data_from_xml
@@ -1299,6 +1301,7 @@ GdaMetaContext
gda_meta_store_new
gda_meta_store_new_with_file
gda_meta_store_get_version
+gda_meta_store_sql_identifier_quote
gda_meta_store_extract
gda_meta_store_schema_get_structure
gda_meta_store_get_attribute_value
diff --git a/doc/C/tmpl/gda-connection.sgml b/doc/C/tmpl/gda-connection.sgml
index 3fef6d4..ab70731 100644
--- a/doc/C/tmpl/gda-connection.sgml
+++ b/doc/C/tmpl/gda-connection.sgml
@@ -149,12 +149,13 @@ A connection to a database
<!-- ##### ENUM GdaConnectionOptions ##### -->
<para>
- Specifies some aspects of a connection when opening it.
+
</para>
- GDA_CONNECTION_OPTIONS_NONE: no specific aspect
- GDA_CONNECTION_OPTIONS_READ_ONLY: the connection to open should be in a read-only mode (this policy is not correctly enforced at the moment)
- GDA_CONNECTION_OPTIONS_THREAD_SAFE: this flag specifies that the connection to open will be used by several threads at once so it has to be thread safe
+ GDA_CONNECTION_OPTIONS_NONE:
+ GDA_CONNECTION_OPTIONS_READ_ONLY:
+ GDA_CONNECTION_OPTIONS_THREAD_SAFE:
+ GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE:
<!-- ##### ENUM GdaConnectionError ##### -->
<para>
@@ -258,6 +259,16 @@ A connection to a database
@Returns:
+<!-- ##### FUNCTION gda_connection_quote_sql_identifier ##### -->
+<para>
+
+</para>
+
+ cnc:
+ id:
+ Returns:
+
+
<!-- ##### FUNCTION gda_connection_statement_to_sql ##### -->
<para>
diff --git a/doc/C/tmpl/gda-meta-store.sgml b/doc/C/tmpl/gda-meta-store.sgml
index 51a939b..3302653 100644
--- a/doc/C/tmpl/gda-meta-store.sgml
+++ b/doc/C/tmpl/gda-meta-store.sgml
@@ -155,6 +155,16 @@ Dictionary object
@Returns:
+<!-- ##### FUNCTION gda_meta_store_sql_identifier_quote ##### -->
+<para>
+
+</para>
+
+ Param1:
+ cnc:
+ Returns:
+
+
<!-- ##### FUNCTION gda_meta_store_extract ##### -->
<para>
diff --git a/doc/C/tmpl/gda-server-operation.sgml b/doc/C/tmpl/gda-server-operation.sgml
index 573cd6b..fb958f7 100644
--- a/doc/C/tmpl/gda-server-operation.sgml
+++ b/doc/C/tmpl/gda-server-operation.sgml
@@ -132,6 +132,19 @@ Handles any DDL query in an abstract way
@Returns:
+<!-- ##### FUNCTION gda_server_operation_get_sql_identifier_at ##### -->
+<para>
+
+</para>
+
+ op:
+ cnc:
+ prov:
+ path_format:
+ Varargs:
+ Returns:
+
+
<!-- ##### FUNCTION gda_server_operation_set_value_at ##### -->
<para>
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 4d2cc89..7481878 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -1750,6 +1750,41 @@ gda_connection_batch_execute (GdaConnection *cnc, GdaBatch *batch, GdaSet *param
/**
+ * gda_connection_quote_sql_identifier
+ * @cnc: a #GdaConnection object
+ * @id: an SQL identifier
+ *
+ * Use this method to get a correctly quoted (if necessary) SQL identifier which can be used
+ * in SQL statements, from @id. If @id is already correctly quoted for @cnc, then a copy of @id
+ * may be returned.
+ *
+ * This method may add double quotes (or other characters) around @id:
+ * <itemizedlist>
+ * <listitem><para>if @id is a reserved SQL keyword (such as SELECT, INSERT, ...)</para></listitem>
+ * <listitem><para>if @id contains non allowed characters such as spaces, or if it starts with a digit</para></listitem>
+ * <listitem><para>in any other event as necessary for @cnc, depending on the the options passed when opening the @cnc
+ * connection, and specifically the <link linkend="GDA-CONNECTION-OPTIONS-SQL-IDENTIFIERS-CASE-SENSITIVE:CAPS">
+ * GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE</link> option.</para></listitem>
+ * </itemizedlist>
+ *
+ * One can safely pass an already quoted @id to this method, either with quoting characters allowed by @cnc or using the
+ * double quote (") character.
+ *
+ * Returns: a new string, to free with g_free() once not needed anymore
+ *
+ * Since: 4.0.3
+ */
+gchar *
+gda_connection_quote_sql_identifier (GdaConnection *cnc, const gchar *id)
+{
+ g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+ g_return_val_if_fail (id, NULL);
+
+ return gda_sql_identifier_quote (id, cnc, NULL, FALSE,
+ cnc->priv->options & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+}
+
+/**
* gda_connection_statement_to_sql
* @cnc: a #GdaConnection object
* @stmt: a #GdaStatement object
@@ -3746,7 +3781,9 @@ suggest_update_cb_downstream (GdaMetaStore *store, GdaMetaContext *suggest, Down
*
* When @context is not %NULL, and contains specified SQL identifiers (for example the "table_name" of the "_tables"
* table), then each SQL identifier has to match the convention the #GdaMetaStore has adopted regarding
- * case sensitivity. see the <link linkend="information_schema:sql_identifiers">
+ * case sensitivity, using gda_meta_store_sql_identifier_quote().
+ *
+ * see the <link linkend="information_schema:sql_identifiers">
* meta data section about SQL identifiers</link> for more information, and the documentation about the
* gda_sql_identifier_quote() function which will be most usefull.
*
@@ -4115,7 +4152,7 @@ prepare_meta_statements_hash (void)
* @cnc: a #GdaConnection object.
* @meta_type: describes which data to get.
* @error: a place to store errors, or %NULL
- * @nb_filters: the number of filters in the ... argument
+ * @nb_filters: the number of filters in the @... argument
* @...: a list of (filter name (gchar *), filter value (GValue*)) pairs specifying
* the filter to apply to the returned data model's contents (there must be @nb_filters pairs)
*
@@ -4131,7 +4168,9 @@ prepare_meta_statements_hash (void)
* see <link linkend="GdaConnectionMetaTypeHead">this description</link>.
*
* Also, when using filters involving data which are SQL identifiers, make sure each SQL identifier
- * is represented using the #GdaMetaStore convention; see the <link linkend="information_schema:sql_identifiers">
+ * is represented using the #GdaMetaStore convention, using gda_meta_store_sql_identifier_quote().
+ *
+ * See the <link linkend="information_schema:sql_identifiers">
* meta data section about SQL identifiers</link> for more information, and the documentation about the
* gda_sql_identifier_quote() function which will be most usefull.
*
diff --git a/libgda/gda-connection.h b/libgda/gda-connection.h
index 5e636a9..9c1ccb3 100644
--- a/libgda/gda-connection.h
+++ b/libgda/gda-connection.h
@@ -83,10 +83,37 @@ struct _GdaConnectionClass {
void (*_gda_reserved4) (void);
};
+/**
+ * GdaConnectionOptions:
+ * @GDA_CONNECTION_OPTIONS_NONE: no specific aspect
+ * @GDA_CONNECTION_OPTIONS_READ_ONLY: this flag specifies that the connection to open should be in a read-only mode
+ * (this policy is not correctly enforced at the moment)
+ * @GDA_CONNECTION_OPTIONS_THREAD_SAFE: this flag specifies that the connection to open will be used
+ * by several threads at once so it has to be thread safe
+ * @GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE: this flag specifies that SQL identifiers submitted as input
+ * to Libgda have to keep their case sensitivity.
+ *
+ *
+ * Specifies some aspects of a connection when opening it.
+ *
+ * Additionnal information about the GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE flag:
+ * <itemizedlist>
+ * <listitem><para>For example without this flag, if the table
+ * name specified in a #GdaServerOperation to create a table is
+ * <emphasis>MyTable</emphasis>, then usually the database will create a table named
+ * <emphasis>mytable</emphasis>, whereas with this flag, the table will be created
+ * as <emphasis>MyTable</emphasis> (note that in the end the database may still decide
+ * to name the table <emphasis>mytable</emphasis> or differently if it can't do
+ * otherwise).</para></listitem>
+ * <listitem><para>Libgda will not apply this rule when parsing SQL code, the SQL code being parsed
+ * has to be conform to the database it will be used with</para></listitem>
+ * </itemizedlist>
+ */
typedef enum {
GDA_CONNECTION_OPTIONS_NONE = 0,
GDA_CONNECTION_OPTIONS_READ_ONLY = 1 << 0,
- GDA_CONNECTION_OPTIONS_THREAD_SAFE = 1 << 1
+ GDA_CONNECTION_OPTIONS_THREAD_SAFE = 1 << 1,
+ GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE = 1 << 2
} GdaConnectionOptions;
typedef enum {
@@ -169,6 +196,7 @@ GSList *gda_connection_batch_execute (GdaConnection *cnc,
GdaBatch *batch, GdaSet *params,
GdaStatementModelUsage model_usage, GError **error);
+gchar *gda_connection_quote_sql_identifier (GdaConnection *cnc, const gchar *id);
gchar *gda_connection_statement_to_sql (GdaConnection *cnc,
GdaStatement *stmt, GdaSet *params, GdaStatementSqlFlag flags,
GSList **params_used, GError **error);
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index 0afaeca..ea4efb0 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -2071,6 +2071,33 @@ gda_meta_store_get_internal_connection (GdaMetaStore *store) {
}
/**
+ * gda_meta_store_sql_identifier_quote
+ * @id: an SQL identifier
+ * @cnc: a #GdaConnection
+ *
+ * Use this method to get a correctly quoted (if necessary) SQL identifier which can be used
+ * to retreive or filter information in a #GdaMetaStore which stores meta data about @cnc.
+ *
+ * The returned SQL identifier can be used in conjunction with gda_connection_update_meta_store(),
+ * gda_connection_get_meta_store_data(), gda_connection_get_meta_store_data_v() and
+ * gda_meta_store_extract().
+ *
+ * Returns: a new string, to free with g_free() once not needed anymore
+ *
+ * Since: 4.0.3
+ */
+gchar *
+gda_meta_store_sql_identifier_quote (const char *id, GdaConnection *cnc)
+{
+ GdaConnectionOptions cncoptions;
+ g_return_val_if_fail (!cnc || GDA_IS_CONNECTION (cnc), NULL);
+
+ g_object_get (G_OBJECT (cnc), "options", &cncoptions, NULL);
+ return gda_sql_identifier_quote (id, cnc, NULL, TRUE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+}
+
+/**
* gda_meta_store_extract
* @store: a #GdaMetaStore object
* @select_sql: a SELECT statement
@@ -2078,7 +2105,9 @@ gda_meta_store_get_internal_connection (GdaMetaStore *store) {
* @...: a list of (variable name (gchar *), GValue *value) terminated with NULL, representing values for all the
* variables mentionned in @select_sql. If there is no variable then this part can be omitted.
*
- * Extracts some data stored in @store using a custom SELECT query.
+ * Extracts some data stored in @store using a custom SELECT query. If the @select_sql filter involves
+ * SQL identifiers (such as table or column names), then the values should have been adapted using
+ * gda_meta_store_sql_identifier_quote().
*
* For more information about
* SQL identifiers are represented in @store, see the
diff --git a/libgda/gda-meta-store.h b/libgda/gda-meta-store.h
index c575ef2..4cda20e 100644
--- a/libgda/gda-meta-store.h
+++ b/libgda/gda-meta-store.h
@@ -108,6 +108,7 @@ GdaMetaStore *gda_meta_store_new (const gchar *cnc_stri
gint gda_meta_store_get_version (GdaMetaStore *store);
GdaConnection *gda_meta_store_get_internal_connection (GdaMetaStore *store);
+gchar *gda_meta_store_sql_identifier_quote (const char*, GdaConnection *cnc);
GdaDataModel *gda_meta_store_extract (GdaMetaStore *store, const gchar *select_sql, GError **error, ...);
gboolean gda_meta_store_modify (GdaMetaStore *store, const gchar *table_name,
GdaDataModel *new_data, const gchar *condition, GError **error, ...);
diff --git a/libgda/gda-server-operation.c b/libgda/gda-server-operation.c
index 77f1b36..d148ea8 100644
--- a/libgda/gda-server-operation.c
+++ b/libgda/gda-server-operation.c
@@ -1893,33 +1893,25 @@ gda_server_operation_del_item_from_sequence (GdaServerOperation *op, const gchar
return FALSE;
}
-/**
- * gda_server_operation_get_value_at
+/*
+ * real_gda_server_operation_get_value_at
* @op: a #GdaServerOperation object
- * @path_format: a complete path to a node (starting with "/")
- * @...: arguments to use with @path_format to make a complete path
+ * @path: a complete path to a node (starting with "/")
*
- * Get the value for the node at the path formed using @path_format and ... (the rules are the same as
- * for g_strdup_printf())
+ * Get the value for the node at the @path path
*
* Returns: a constant #GValue if a value has been defined, or %NULL if the value is undefined or
* if the @path is not defined or @path does not hold any value.
*/
-const GValue *
-gda_server_operation_get_value_at (GdaServerOperation *op, const gchar *path_format, ...)
+static const GValue *
+real_gda_server_operation_get_value_at (GdaServerOperation *op, const gchar *path)
{
const GValue *value = NULL;
GdaServerOperationNode *node_info;
- gchar *path;
- va_list args;
g_return_val_if_fail (GDA_IS_SERVER_OPERATION (op), NULL);
g_return_val_if_fail (op->priv, NULL);
-
- /* build path */
- va_start (args, path_format);
- path = g_strdup_vprintf (path_format, args);
- va_end (args);
+ g_return_val_if_fail (path && *path, NULL);
/* use path */
node_info = gda_server_operation_get_node_info (op, path);
@@ -1962,11 +1954,90 @@ gda_server_operation_get_value_at (GdaServerOperation *op, const gchar *path_for
}
}
+ return value;
+}
+
+/**
+ * gda_server_operation_get_value_at
+ * @op: a #GdaServerOperation object
+ * @path_format: a complete path to a node (starting with "/")
+ * @...: arguments to use with @path_format to make a complete path
+ *
+ * Get the value for the node at the path formed using @path_format and ... (the rules are the same as
+ * for g_strdup_printf())
+ *
+ * Returns: a constant #GValue if a value has been defined, or %NULL if the value is undefined or
+ * if the @path is not defined or @path does not hold any value.
+ */
+const GValue *
+gda_server_operation_get_value_at (GdaServerOperation *op, const gchar *path_format, ...)
+{
+ const GValue *value = NULL;
+ gchar *path;
+ va_list args;
+
+ g_return_val_if_fail (GDA_IS_SERVER_OPERATION (op), NULL);
+ g_return_val_if_fail (op->priv, NULL);
+
+ /* build path */
+ va_start (args, path_format);
+ path = g_strdup_vprintf (path_format, args);
+ va_end (args);
+
+ value = real_gda_server_operation_get_value_at (op, path);
g_free (path);
+
return value;
}
/**
+ * gda_server_operation_get_sql_identifier_at
+ * @op: a #GdaServerOperation object
+ * @cnc: a #GdaConnection, or %NULL
+ * @prov: a #GdaServerProvider, or %NULL
+ * @path_format: a complete path to a node (starting with "/")
+ * @...: arguments to use with @path_format to make a complete path
+ *
+ * This method is similar to gda_server_operation_get_value_at(), but for SQL identifiers: a new string
+ * is returned instead of a #GValue. Also the returned string is assumed to represents an SQL identifier
+ * and will correctly be quoted to be used with @cnc, or @prov if @cnc is %NULL (a generic quoting rule
+ * will be applied if both are %NULL).
+ *
+ * Returns: a new string, or %NULL if the value is undefined or
+ * if the @path is not defined or @path does not hold any value, or if the value held is not a string
+ * (in that last case a warning is shown).
+ *
+ * Since: 4.0.3
+ */
+gchar *
+gda_server_operation_get_sql_identifier_at (GdaServerOperation *op, GdaConnection *cnc, GdaServerProvider *prov,
+ const gchar *path_format, ...)
+{
+ const GValue *value = NULL;
+ gchar *path;
+ va_list args;
+ GdaConnectionOptions cncoptions;
+
+ g_return_val_if_fail (GDA_IS_SERVER_OPERATION (op), NULL);
+
+ /* build path */
+ va_start (args, path_format);
+ path = g_strdup_vprintf (path_format, args);
+ va_end (args);
+
+ value = real_gda_server_operation_get_value_at (op, path);
+ g_free (path);
+
+ if (!value || (G_VALUE_TYPE (value) == GDA_TYPE_NULL))
+ return NULL;
+ g_return_val_if_fail (G_VALUE_TYPE (value) == G_TYPE_STRING, NULL);
+
+ g_object_get (G_OBJECT (cnc), "options", &cncoptions, NULL);
+ return gda_sql_identifier_quote (g_value_get_string (value), cnc, prov, FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+}
+
+/**
* gda_server_operation_set_value_at
* @op: a #GdaServerOperation object
* @value: a string
diff --git a/libgda/gda-server-operation.h b/libgda/gda-server-operation.h
index bf6944b..028c8fd 100644
--- a/libgda/gda-server-operation.h
+++ b/libgda/gda-server-operation.h
@@ -116,6 +116,9 @@ const gchar *gda_server_operation_op_type_to_string (GdaServ
GdaServerOperationNode *gda_server_operation_get_node_info (GdaServerOperation *op, const gchar *path_format, ...);
const GValue *gda_server_operation_get_value_at (GdaServerOperation *op, const gchar *path_format, ...);
+gchar *gda_server_operation_get_sql_identifier_at (GdaServerOperation *op,
+ GdaConnection *cnc, GdaServerProvider *prov,
+ const gchar *path_format, ...);
gboolean gda_server_operation_set_value_at (GdaServerOperation *op, const gchar *value,
GError **error, const gchar *path_format, ...);
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 0f90787..6cc559d 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -149,6 +149,7 @@
gda_connection_open_from_string
gda_connection_options_get_type
gda_connection_perform_operation
+ gda_connection_quote_sql_identifier
gda_connection_repetitive_statement_execute
gda_connection_rollback_savepoint
gda_connection_rollback_transaction
@@ -414,6 +415,7 @@
gda_meta_store_schema_get_structure
gda_meta_store_schema_remove_custom_object
gda_meta_store_set_attribute_value
+ gda_meta_store_sql_identifier_quote
gda_meta_struct_add_db_object
gda_meta_struct_complement
gda_meta_struct_complement_all
@@ -497,6 +499,7 @@
gda_server_operation_get_sequence_size
gda_server_operation_get_type
gda_server_operation_get_value_at
+ gda_server_operation_get_sql_identifier_at
gda_server_operation_is_valid
gda_server_operation_load_data_from_xml
gda_server_operation_new
diff --git a/libgda/sqlite/gda-sqlite-ddl.c b/libgda/sqlite/gda-sqlite-ddl.c
index 2005fe6..7369ef5 100644
--- a/libgda/sqlite/gda-sqlite-ddl.c
+++ b/libgda/sqlite/gda-sqlite-ddl.c
@@ -28,7 +28,7 @@
gchar *
_gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
- GdaServerOperation *op, GError **error)
+ GdaServerOperation *op, GError **error)
{
GString *string;
const GValue *value;
@@ -41,6 +41,7 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
gint nbpkfields = 0;
gchar *sql = NULL;
gchar *conflict_algo = NULL;
+ gchar *tmp;
/* CREATE TABLE */
string = g_string_new ("CREATE ");
@@ -53,9 +54,9 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF NOT EXISTS ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -69,11 +70,13 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -85,8 +88,9 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
if (nbpkfields == 1) {
@@ -191,14 +195,13 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
/* composed primary key */
if (nbpkfields > 1) {
- GSList *list = pkfields;
+ GSList *list;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- list = list->next;
+ g_string_append (string, (gchar *) list->data);
}
g_string_append_c (string, ')');
@@ -207,6 +210,8 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
g_string_append (string, conflict_algo);
}
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
g_free (conflict_algo);
g_string_append (string, ")");
@@ -215,8 +220,6 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
allok = FALSE;
g_set_error (error, 0, 0, "%s", _("Table to create must have at least one row"));
}
- g_slist_free (pkfields);
-
sql = string->str;
g_string_free (string, FALSE);
@@ -226,11 +229,12 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
gchar *
_gda_sqlite_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
- GdaServerOperation *op, GError **error)
+ GdaServerOperation *op, GError **error)
{
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
/* DROP TABLE */
string = g_string_new ("DROP TABLE");
@@ -239,10 +243,10 @@ _gda_sqlite_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, " IF EXISTS");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
g_string_append_c (string, ' ');
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -252,23 +256,23 @@ _gda_sqlite_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
gchar *
_gda_sqlite_render_RENAME_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
- GdaServerOperation *op, GError **error)
+ GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
/* DROP TABLE */
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NEW_NAME");
g_string_append (string, " RENAME TO ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -283,19 +287,20 @@ _gda_sqlite_render_ADD_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
/* DROP TABLE */
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " ADD COLUMN ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/COLUMN_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_TYPE");
g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
@@ -353,6 +358,7 @@ _gda_sqlite_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc
gchar *sql = NULL;
GdaServerOperationNode *node;
gint nrows, i;
+ gchar *tmp;
/* CREATE INDEX */
string = g_string_new ("CREATE ");
@@ -371,16 +377,15 @@ _gda_sqlite_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc
g_string_append (string, " IF NOT EXISTS ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " ON ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_ON_TABLE");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
-
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_ON_TABLE");
+ g_string_append (string, tmp);
+ g_free (tmp);
/* fields or expressions the index is on */
g_string_append (string, " (");
@@ -388,11 +393,13 @@ _gda_sqlite_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc
g_assert (node);
nrows = gda_server_operation_get_sequence_size (op, "/INDEX_FIELDS_S");
for (i = 0; i < nrows; i++) {
- value = gda_server_operation_get_value_at (op, "/INDEX_FIELDS_S/%d/INDEX_FIELD", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/INDEX_FIELDS_S/%d/INDEX_FIELD", i);
+ if (tmp) {
if (i != 0)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/INDEX_FIELDS_S/%d/INDEX_COLLATE", i);
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
@@ -430,6 +437,7 @@ _gda_sqlite_render_DROP_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
/* DROP INDEX */
string = g_string_new ("DROP INDEX ");
@@ -438,9 +446,9 @@ _gda_sqlite_render_DROP_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF EXISTS ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DESC_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DESC_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -456,6 +464,7 @@ _gda_sqlite_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
const GValue *value;
gboolean allok = TRUE;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("CREATE ");
value = gda_server_operation_get_value_at (op, "/VIEW_DEF_P/VIEW_TEMP");
@@ -468,10 +477,9 @@ _gda_sqlite_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF NOT EXISTS ");
-
- value = gda_server_operation_get_value_at (op, "/VIEW_DEF_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/VIEW_DEF_P/VIEW_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
if (allok) {
value = gda_server_operation_get_value_at (op, "/VIEW_DEF_P/VIEW_DEF");
@@ -499,6 +507,7 @@ _gda_sqlite_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP VIEW");
@@ -506,10 +515,10 @@ _gda_sqlite_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, " IF EXISTS");
- value = gda_server_operation_get_value_at (op, "/VIEW_DESC_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/VIEW_DESC_P/VIEW_NAME");
g_string_append_c (string, ' ');
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
diff --git a/providers/jdbc/gda-jdbc-ddl.c b/providers/jdbc/gda-jdbc-ddl.c
index b48bd6e..6631c28 100644
--- a/providers/jdbc/gda-jdbc-ddl.c
+++ b/providers/jdbc/gda-jdbc-ddl.c
@@ -38,13 +38,14 @@ gda_jdbc_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GSList *pkfields = NULL; /* list of GValue* composing the pkey */
gint nbpkfields = 0;
gchar *sql = NULL;
+ gchar *tmp;
/* CREATE TABLE */
string = g_string_new ("CREATE TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -58,11 +59,13 @@ gda_jdbc_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -73,8 +76,10 @@ gda_jdbc_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
@@ -117,17 +122,18 @@ gda_jdbc_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
/* composed primary key */
if (nbpkfields > 1) {
- GSList *list = pkfields;
+ GSList *list;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- list = list->next;
+ g_string_append (string, (gchar*) list->data);
}
g_string_append_c (string, ')');
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
g_string_append (string, ")");
@@ -135,7 +141,6 @@ gda_jdbc_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
allok = FALSE;
g_set_error (error, 0, 0, "%s", _("Table to create must have at least one row"));
}
- g_slist_free (pkfields);
sql = string->str;
g_string_free (string, FALSE);
diff --git a/providers/mysql/gda-mysql-ddl.c b/providers/mysql/gda-mysql-ddl.c
index 5f36d69..5b8adec 100644
--- a/providers/mysql/gda-mysql-ddl.c
+++ b/providers/mysql/gda-mysql-ddl.c
@@ -24,6 +24,7 @@
#include "gda-mysql-ddl.h"
#include <glib/gi18n-lib.h>
#include <libgda/gda-data-handler.h>
+#include <libgda/sql-parser/gda-sql-parser.h>
gchar *
gda_mysql_render_CREATE_DB (GdaServerProvider *provider, GdaConnection *cnc,
@@ -33,6 +34,7 @@ gda_mysql_render_CREATE_DB (GdaServerProvider *provider, GdaConnection *cnc,
const GValue *value;
gchar *sql = NULL;
gboolean first = TRUE;
+ gchar *tmp;
string = g_string_new ("CREATE DATABASE ");
@@ -40,9 +42,9 @@ gda_mysql_render_CREATE_DB (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF NOT EXISTS ");
- value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/DB_DEF_P/DB_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_CSET");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
@@ -51,14 +53,15 @@ gda_mysql_render_CREATE_DB (GdaServerProvider *provider, GdaConnection *cnc,
first = FALSE;
}
- value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_COLLATION");
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/DB_DEF_P/DB_COLLATION");
+ if (tmp) {
if (first)
first = FALSE;
else
g_string_append (string, ", ");
g_string_append (string, " COLLATION ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
}
sql = string->str;
@@ -74,6 +77,7 @@ gda_mysql_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP DATABASE ");
@@ -81,9 +85,9 @@ gda_mysql_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF EXISTS ");
- value = gda_server_operation_get_value_at (op, "/DB_DESC_P/DB_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/DB_DESC_P/DB_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -106,6 +110,7 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GSList *pkfields = NULL; /* list of GValue* composing the pkey */
gint nbpkfields = 0;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("CREATE ");
value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_TEMP");
@@ -117,9 +122,9 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "IF NOT EXISTS ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -133,11 +138,13 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields ++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -148,8 +155,10 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
@@ -226,14 +235,15 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GSList *list = pkfields;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- list = list->next;
+ g_string_append (string, (gchar *) tmp);
}
g_string_append_c (string, ')');
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
/* foreign keys */
if (allok) {
@@ -256,10 +266,12 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
for (j = 0; j < nbfields; j++) {
if (j != 0)
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op,
- "/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d", i, j);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d", i, j);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
else {
allok = FALSE;
g_set_error (error, 0, 0, "%s",
@@ -268,11 +280,9 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
}
}
g_string_append (string, ") REFERENCES ");
- value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_REF_TABLE", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
- gchar *tmp;
- tmp = gda_sql_identifier_quote (g_value_get_string (value), cnc, NULL,
- FALSE, FALSE);
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_REF_TABLE", i);
+ if (tmp) {
g_string_append (string, tmp);
g_free (tmp);
}
@@ -285,10 +295,12 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
for (j = 0; j < nbfields; j++) {
if (j != 0)
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op,
- "/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d", i, j);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d", i, j);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
else {
allok = FALSE;
g_set_error (error, 0, 0, "%s",
@@ -322,7 +334,7 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
g_value_get_string (value) && *g_value_get_string (value))
g_string_append (string, " ENGINE = ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, g_value_get_string (value));
value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_AUTOINC_VALUE");
if (value && G_VALUE_HOLDS (value, G_TYPE_INT))
@@ -339,11 +351,12 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
g_string_append (string, " CHARACTER SET ");
g_string_append (string, g_value_get_string (value));
- value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_COLLATION");
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
- g_value_get_string (value) && *g_value_get_string (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/TABLE_OPTIONS_P/TABLE_COLLATION");
+ if (tmp) {
g_string_append (string, " COLLATE ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
}
}
@@ -356,7 +369,7 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
g_value_get_string (value) && *g_value_get_string (value)) {
GdaDataHandler *dh;
gchar *str;
-
+
dh = gda_server_provider_get_data_handler_g_type (provider, cnc, G_TYPE_STRING);
str = gda_data_handler_get_sql_from_value (dh, value);
if (str) {
@@ -365,15 +378,15 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
g_free (str);
}
}
-
+
value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_MAX_ROWS");
if (value && G_VALUE_HOLDS (value, G_TYPE_INT))
g_string_append_printf (string, " MAX_ROWS = %d", g_value_get_int (value));
-
+
value = gda_server_operation_get_value_at (op, "/TABLE_OPTIONS_P/TABLE_MIN_ROWS");
if (value && G_VALUE_HOLDS (value, G_TYPE_INT))
g_string_append_printf (string, " MIN_ROWS = %d", g_value_get_int (value));
-
+
value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_PACK_KEYS");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
g_value_get_string (value) && *g_value_get_string (value)) {
@@ -452,12 +465,9 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
}
}
- g_slist_free (pkfields);
-
-
sql = string->str;
g_string_free (string, FALSE);
-
+
return sql;
}
@@ -468,6 +478,7 @@ gda_mysql_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP");
@@ -481,10 +492,10 @@ gda_mysql_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, " IF EXISTS");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
g_string_append_c (string, ' ');
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
@@ -503,19 +514,19 @@ gda_mysql_render_RENAME_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NEW_NAME");
g_string_append (string, " RENAME TO ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -526,19 +537,18 @@ gda_mysql_render_RENAME_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
gchar *
gda_mysql_render_COMMENT_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
- GdaServerOperation *op, GError **error)
+ GdaServerOperation *op, GError **error)
{
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
-
- gchar *table_name = g_value_dup_string (value);
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_COMMENT");
g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
@@ -560,18 +570,19 @@ gda_mysql_render_ADD_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " ADD COLUMN ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/COLUMN_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_TYPE");
g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
@@ -665,19 +676,19 @@ gda_mysql_render_DROP_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/COLUMN_NAME");
g_string_append (string, " DROP COLUMN ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -693,32 +704,31 @@ gda_mysql_render_COMMENT_COLUMN (GdaServerProvider *provider, GdaConnection *cnc
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
+ gchar *table_name;
+ gchar *column_name;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
-
- gchar *table_name = g_value_dup_string (value);
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/TABLE_NAME");
+ table_name = tmp;
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/COLUMN_NAME");
+ column_name = tmp;
g_string_append (string, " CHANGE COLUMN ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
g_string_append (string, " ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
g_string_append (string, " ");
- gchar *column_name = g_value_dup_string (value);
-
GString *tmp_string = g_string_new ("SELECT column_type FROM "
"information_schema.columns "
- "WHERE table_name = '");
+ "WHERE table_name = ");
g_string_append (tmp_string, table_name);
- g_string_append (tmp_string, "' AND column_name = '");
+ g_string_append (tmp_string, " AND column_name = ");
g_string_append (tmp_string, column_name);
- g_string_append (tmp_string, "'");
g_free (table_name);
g_free (column_name);
@@ -739,7 +749,7 @@ gda_mysql_render_COMMENT_COLUMN (GdaServerProvider *provider, GdaConnection *cnc
g_assert (model != NULL && gda_data_model_get_n_rows (model) == 1);
- GValue *tmp_value;
+ const GValue *tmp_value;
tmp_value = gda_data_model_get_value_at (model, 0, 0, error);
gchar *str;
@@ -774,6 +784,7 @@ gda_mysql_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
gchar *sql = NULL;
GdaServerOperationNode *node;
gint nrows, i;
+ gchar *tmp;
string = g_string_new ("CREATE ");
@@ -786,9 +797,9 @@ gda_mysql_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
g_string_append (string, "INDEX ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_METHOD");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
@@ -798,10 +809,9 @@ gda_mysql_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
g_string_append (string, " ON ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_ON_TABLE");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
-
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_ON_TABLE");
+ g_string_append (string, tmp);
+ g_free (tmp);
/* fields or expressions the index is on */
g_string_append (string, " (");
@@ -840,19 +850,19 @@ gda_mysql_render_DROP_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP INDEX ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DESC_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DESC_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/INDEX_DESC_P/INDEX_ON_TABLE");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DESC_P/INDEX_ON_TABLE");
g_string_append (string, " ON ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -869,6 +879,7 @@ gda_mysql_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
gboolean allok = TRUE;
gchar *sql = NULL;
GdaServerOperationNode *node;
+ gchar *tmp;
string = g_string_new ("CREATE ");
@@ -877,10 +888,10 @@ gda_mysql_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
g_string_append (string, "OR REPLACE ");
g_string_append (string, "VIEW ");
-
- value = gda_server_operation_get_value_at (op, "/VIEW_DEF_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/VIEW_DEF_P/VIEW_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
node = gda_server_operation_get_node_info (op, "/FIELDS_A");
if (node) {
@@ -891,13 +902,16 @@ gda_mysql_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
for (i = 0; (i < nrows) && allok; i++) {
if (i == 0)
g_string_append (string, " (");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
+
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ if (tmp) {
if (i != 0)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
g_string_append_c (string, ' ');
+ g_free (tmp);
}
else {
g_set_error (error, 0, 0, "%s", _("Incorrect specified column name"));
@@ -934,6 +948,7 @@ gda_mysql_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP VIEW");
@@ -941,10 +956,10 @@ gda_mysql_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, " IF EXISTS");
- value = gda_server_operation_get_value_at (op, "/VIEW_DESC_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/VIEW_DESC_P/VIEW_NAME");
g_string_append_c (string, ' ');
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
diff --git a/providers/oracle/gda-oracle-ddl.c b/providers/oracle/gda-oracle-ddl.c
index 0149e4f..9609616 100644
--- a/providers/oracle/gda-oracle-ddl.c
+++ b/providers/oracle/gda-oracle-ddl.c
@@ -1,5 +1,5 @@
/* GDA Oracle Provider
- * Copyright (C) 2008 The GNOME Foundation
+ * Copyright (C) 2008 - 2009 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -26,7 +26,7 @@
gchar *
gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
- GdaServerOperation *op, GError **error)
+ GdaServerOperation *op, GError **error)
{
GString *string;
const GValue *value;
@@ -38,13 +38,14 @@ gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
GSList *pkfields = NULL; /* list of GValue* composing the pkey */
gint nbpkfields = 0;
gchar *sql = NULL;
+ gchar *tmp;
/* CREATE TABLE */
string = g_string_new ("CREATE TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -58,11 +59,13 @@ gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields ++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -73,8 +76,10 @@ gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
@@ -117,17 +122,18 @@ gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
/* composed primary key */
if (nbpkfields > 1) {
- GSList *list = pkfields;
+ GSList *list;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- list = list->next;
+ g_string_append (string, (gchar*) list->data);
}
g_string_append_c (string, ')');
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
g_string_append (string, ")");
@@ -135,7 +141,6 @@ gda_oracle_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
allok = FALSE;
g_set_error (error, 0, 0, "%s", _("Table to create must have at least one row"));
}
- g_slist_free (pkfields);
sql = string->str;
g_string_free (string, FALSE);
diff --git a/providers/postgres/gda-postgres-ddl.c b/providers/postgres/gda-postgres-ddl.c
index eec43cf..34b9791 100644
--- a/providers/postgres/gda-postgres-ddl.c
+++ b/providers/postgres/gda-postgres-ddl.c
@@ -2,7 +2,7 @@
* Copyright (C) 2008 The GNOME Foundation
*
* AUTHORS:
- * TO_ADD: your name and email
+ * Vivien Malerba <malerba gnome-db org>
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
@@ -31,12 +31,13 @@ gda_postgres_render_CREATE_DB (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("CREATE DATABASE ");
- value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append_printf (string, "\"%s\"", g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/DB_DEF_P/DB_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/DB_DEF_P/OWNER");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
@@ -81,14 +82,14 @@ gda_postgres_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP DATABASE ");
- value = gda_server_operation_get_value_at (op, "/DB_DESC_P/DB_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append_printf (string, "\"%s\"", g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/DB_DESC_P/DB_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -110,6 +111,7 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
GSList *pkfields = NULL; /* list of GValue* composing the pkey */
gint nbpkfields = 0;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("CREATE ");
value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_TEMP");
@@ -117,9 +119,10 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
g_string_append (string, "TEMP ");
g_string_append (string, "TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -133,11 +136,13 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields ++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -148,12 +153,11 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append_c (string, '\"');
- g_string_append (string, g_value_get_string (value));
- g_string_append_c (string, '\"');
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
-
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_AUTOINC/%d", i);
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
@@ -213,44 +217,43 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY", i);
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && !g_value_get_boolean (value)) {
- value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
- const gchar *str = g_value_get_string (value);
- if (str && *str) {
- hasfields = TRUE;
- if (first)
- first = FALSE;
- else
- g_string_append (string, ", ");
- g_string_append (string, "LIKE ");
- g_string_append (string, str);
- value = gda_server_operation_get_value_at (op,
- "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY_DEFAULTS", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) &&
- g_value_get_boolean (value))
- g_string_append (string, " INCLUDING DEFAULTS");
- }
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE", i);
+ if (tmp && *tmp) {
+ hasfields = TRUE;
+ if (first)
+ first = FALSE;
+ else
+ g_string_append (string, ", ");
+
+ g_string_append (string, "LIKE ");
+ g_string_append (string, tmp);
+ value = gda_server_operation_get_value_at (op,
+ "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY_DEFAULTS", i);
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) &&
+ g_value_get_boolean (value))
+ g_string_append (string, " INCLUDING DEFAULTS");
}
+ g_free (tmp);
}
}
}
/* composed primary key */
if (nbpkfields > 1) {
- GSList *list = pkfields;
+ GSList *list;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append_c (string, '\"');
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- g_string_append_c (string, '\"');
- list = list->next;
+ g_string_append (string, (gchar*) list->data);
}
g_string_append_c (string, ')');
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
/* foreign keys */
if (allok) {
@@ -273,13 +276,11 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
for (j = 0; j < nbfields; j++) {
if (j != 0)
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op,
- "/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d", i, j);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
- {
- g_string_append_c (string, '\"');
- g_string_append (string, g_value_get_string (value));
- g_string_append_c (string, '\"');
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d", i, j);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
}
else {
allok = FALSE;
@@ -289,9 +290,13 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
}
}
g_string_append (string, ") REFERENCES ");
- value = gda_server_operation_get_value_at (op, "/FKEY_S/%d/FKEY_REF_TABLE", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
- g_string_append (string, g_value_get_string (value));
+
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_REF_TABLE", i);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
else {
allok = FALSE;
g_set_error (error, 0, 0, "%s", _("No referenced table specified in foreign key constraint"));
@@ -301,13 +306,11 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
for (j = 0; j < nbfields; j++) {
if (j != 0)
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op,
- "/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d", i, j);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
- {
- g_string_append_c (string, '\"');
- g_string_append (string, g_value_get_string (value));
- g_string_append_c (string, '\"');
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d", i, j);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
}
else {
allok = FALSE;
@@ -340,19 +343,18 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_COPY", i);
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
- value = gda_server_operation_get_value_at (op, "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
- const gchar *str = g_value_get_string (value);
- if (str && *str) {
- hasfields = TRUE;
- if (first) {
- g_string_append (string, " INHERITS ");
- first = FALSE;
- }
- else
- g_string_append (string, ", ");
- g_string_append (string, str);
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/TABLE_PARENTS_S/%d/TABLE_PARENT_TABLE", i);
+ if (tmp) {
+ hasfields = TRUE;
+ if (first) {
+ g_string_append (string, " INHERITS ");
+ first = FALSE;
}
+ else
+ g_string_append (string, ", ");
+ g_string_append (string, tmp);
+ g_free (tmp);
}
}
}
@@ -368,9 +370,6 @@ gda_postgres_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cn
g_string_append (string, " WITH OIDS");
}
- g_slist_free (pkfields);
-
-
sql = string->str;
g_string_free (string, FALSE);
@@ -384,12 +383,14 @@ gda_postgres_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cn
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/TABLE_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
@@ -408,19 +409,19 @@ gda_postgres_render_RENAME_TABLE (GdaServerProvider *provider, GdaConnection *cn
GdaServerOperation *op, GError **error)
{
GString *string;
- const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
- value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DESC_P/TABLE_NEW_NAME");
g_string_append (string, " RENAME TO ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
sql = string->str;
g_string_free (string, FALSE);
@@ -436,6 +437,7 @@ gda_postgres_render_ADD_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
@@ -443,15 +445,15 @@ gda_postgres_render_ADD_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, "ONLY ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " ADD COLUMN ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DEF_P/COLUMN_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/COLUMN_DEF_P/COLUMN_TYPE");
g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
@@ -513,17 +515,17 @@ gda_postgres_render_DROP_COLUMN (GdaServerProvider *provider, GdaConnection *cn
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("ALTER TABLE ");
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
-
- value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/COLUMN_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/COLUMN_DESC_P/COLUMN_NAME");
g_string_append (string, " DROP COLUMN ");
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/COLUMN_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
@@ -550,6 +552,7 @@ gda_postgres_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cn
gchar *sql = NULL;
GdaServerOperationNode *node;
gint nrows, i;
+ gchar *tmp;
string = g_string_new ("CREATE ");
@@ -562,15 +565,15 @@ gda_postgres_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cn
g_string_append (string, "INDEX ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " ON ");
-
- value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_ON_TABLE");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DEF_P/INDEX_ON_TABLE");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/INDEX_DEF_P/INDEX_METHOD");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
@@ -584,13 +587,13 @@ gda_postgres_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cn
g_assert (node);
nrows = gda_server_operation_get_sequence_size (op, "/INDEX_FIELDS_S");
for (i = 0; i < nrows; i++) {
- value = gda_server_operation_get_value_at (op, "/INDEX_FIELDS_S/%d/INDEX_FIELD", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/INDEX_FIELDS_S/%d/INDEX_FIELD", i);
+ if (tmp) {
if (i != 0)
g_string_append (string, ", ");
- g_string_append_c (string, '\"');
- g_string_append (string, g_value_get_string (value));
- g_string_append_c (string, '\"');
+ g_string_append (string, tmp);
+ g_free (tmp);
}
}
@@ -622,12 +625,13 @@ gda_postgres_render_DROP_INDEX (GdaServerProvider *provider, GdaConnection *cn
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP INDEX ");
- value = gda_server_operation_get_value_at (op, "/INDEX_DESC_P/INDEX_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/INDEX_DESC_P/INDEX_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/INDEX_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
@@ -649,6 +653,7 @@ gda_postgres_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc
const GValue *value;
gboolean allok = TRUE;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("CREATE ");
@@ -661,10 +666,10 @@ gda_postgres_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc
g_string_append (string, "TEMP ");
g_string_append (string, "VIEW ");
-
- value = gda_server_operation_get_value_at (op, "/VIEW_DEF_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/VIEW_DEF_P/VIEW_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
if (allok) {
GdaServerOperationNode *node;
@@ -676,16 +681,15 @@ gda_postgres_render_CREATE_VIEW (GdaServerProvider *provider, GdaConnection *cnc
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- if (!value || !G_VALUE_HOLDS (value, G_TYPE_STRING))
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ if (!tmp)
continue;
- if (!cols)
- cols = g_string_new ("(\"");
- else
- g_string_append (cols, ", \"");
- g_string_append (cols, g_value_get_string (value));
- g_string_append_c (cols, '\"');
+ if (cols)
+ g_string_append (cols, ", ");
+ g_string_append (cols, tmp);
g_string_append_c (cols, ' ');
+ g_free (tmp);
}
if (cols) {
g_string_append_c (cols, ')');
@@ -721,6 +725,7 @@ gda_postgres_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
GString *string;
const GValue *value;
gchar *sql = NULL;
+ gchar *tmp;
string = g_string_new ("DROP VIEW");
@@ -728,10 +733,11 @@ gda_postgres_render_DROP_VIEW (GdaServerProvider *provider, GdaConnection *cnc,
if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
g_string_append (string, " IF EXISTS");
- value = gda_server_operation_get_value_at (op, "/VIEW_DESC_P/VIEW_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/VIEW_DESC_P/VIEW_NAME");
g_string_append_c (string, ' ');
- g_string_append (string, g_value_get_string (value));
+ g_string_append (string, tmp);
+ g_free (tmp);
value = gda_server_operation_get_value_at (op, "/VIEW_DESC_P/REFERENCED_ACTION");
g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
diff --git a/providers/skel-implementation/capi/gda-capi-ddl.c b/providers/skel-implementation/capi/gda-capi-ddl.c
index a0e3bdc..76d4139 100644
--- a/providers/skel-implementation/capi/gda-capi-ddl.c
+++ b/providers/skel-implementation/capi/gda-capi-ddl.c
@@ -37,14 +37,14 @@ gda_capi_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
gboolean first;
GSList *pkfields = NULL; /* list of GValue* composing the pkey */
gint nbpkfields = 0;
- gchar *sql = NULL;
+ gchar *tmp;
/* CREATE TABLE */
string = g_string_new ("CREATE TABLE ");
- value = gda_server_operation_get_value_at (op, "/TABLE_DEF_P/TABLE_NAME");
- g_assert (value && G_VALUE_HOLDS (value, G_TYPE_STRING));
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider, "/TABLE_DEF_P/TABLE_NAME");
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append (string, " (");
/* FIELDS */
@@ -58,11 +58,13 @@ gda_capi_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
nrows = gda_data_model_get_n_rows (node->model);
for (i = 0; i < nrows; i++) {
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_PKEY/%d", i);
- if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value))
- pkfields = g_slist_append (pkfields,
- (GValue *) gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i));
+ if (value && G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) && g_value_get_boolean (value)) {
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ pkfields = g_slist_append (pkfields, tmp);
+ nbpkfields++;
+ }
}
- nbpkfields = g_slist_length (pkfields);
/* manually defined fields */
first = TRUE;
@@ -73,8 +75,10 @@ gda_capi_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
else
g_string_append (string, ", ");
- value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_NAME/%d", i);
- g_string_append (string, g_value_get_string (value));
+ tmp = gda_server_operation_get_sql_identifier_at (op, cnc, provider,
+ "/FIELDS_A/@COLUMN_NAME/%d", i);
+ g_string_append (string, tmp);
+ g_free (tmp);
g_string_append_c (string, ' ');
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
@@ -117,17 +121,18 @@ gda_capi_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
/* composed primary key */
if (nbpkfields > 1) {
- GSList *list = pkfields;
+ GSList *list;
g_string_append (string, ", PRIMARY KEY (");
- while (list) {
+ for (list = pkfields; list; list = list->next) {
if (list != pkfields)
g_string_append (string, ", ");
- g_string_append (string, g_value_get_string ((GValue*) list->data));
- list = list->next;
+ g_string_append (string, (gchar*) list->data);
}
g_string_append_c (string, ')');
}
+ g_slist_foreach (pkfields, (GFunc) g_free, NULL);
+ g_slist_free (pkfields);
g_string_append (string, ")");
@@ -135,10 +140,6 @@ gda_capi_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
allok = FALSE;
g_set_error (error, 0, 0, "%s", _("Table to create must have at least one row"));
}
- g_slist_free (pkfields);
-
- sql = string->str;
- g_string_free (string, FALSE);
- return sql;
+ return g_string_free (string, FALSE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]