[libgda] SQLite3: Adding RENAME COLUMN operation
- From: Pavlo Solntsev <psolntsev src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] SQLite3: Adding RENAME COLUMN operation
- Date: Sun, 12 Jul 2020 03:38:47 +0000 (UTC)
commit 72e92b9b0063b04ee224f8ef056580c5198381d3
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Wed May 27 13:49:21 2020 -0500
SQLite3: Adding RENAME COLUMN operation
Implementing DROP COLUMN and RENAME COLUMN operations for SQLite3
provider.
libgda/gda-server-operation.h | 1 +
libgda/sqlite/gda-sqlite-ddl.c | 67 +++++++++++++++++++++++++++++++++++++
libgda/sqlite/gda-sqlite-ddl.h | 4 +++
libgda/sqlite/gda-sqlite-provider.c | 6 ++++
4 files changed, 78 insertions(+)
---
diff --git a/libgda/gda-server-operation.h b/libgda/gda-server-operation.h
index 7935ea4a4..cb5c084d0 100644
--- a/libgda/gda-server-operation.h
+++ b/libgda/gda-server-operation.h
@@ -48,6 +48,7 @@ typedef enum {
GDA_SERVER_OPERATION_ADD_COLUMN,
GDA_SERVER_OPERATION_DROP_COLUMN,
+ GDA_SERVER_OPERATION_RENAME_COLUMN,
GDA_SERVER_OPERATION_CREATE_INDEX,
GDA_SERVER_OPERATION_DROP_INDEX,
diff --git a/libgda/sqlite/gda-sqlite-ddl.c b/libgda/sqlite/gda-sqlite-ddl.c
index 40dd3d76f..66ce0aec1 100644
--- a/libgda/sqlite/gda-sqlite-ddl.c
+++ b/libgda/sqlite/gda-sqlite-ddl.c
@@ -21,6 +21,7 @@
*/
#include "gda-sqlite-ddl.h"
+#include "gda-server-provider.h"
#include <glib/gi18n-lib.h>
#include <libgda/gda-data-handler.h>
@@ -713,3 +714,69 @@ _gda_sqlite_render_DROP_VIEW (G_GNUC_UNUSED GdaServerProvider *provider, GdaConn
return sql;
}
+
+gchar *
+_gda_sqlite_render_DROP_COLUMN (GdaServerProvider *provider,
+ GdaConnection *cnc,
+ GdaServerOperation *op,
+ GError **error)
+{
+ gchar *sql = NULL;
+
+ g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_NON_SUPPORTED_ERROR,
+ _("DROP COLUMN operation is not supported by SQLite3 provider"));
+ return sql;
+}
+
+gchar *
+_gda_sqlite_render_RENAME_COLUMN (GdaServerProvider *provider,
+ GdaConnection *cnc,
+ GdaServerOperation *op,
+ GError **error)
+{
+ gchar *sql = NULL;
+
+ GString *string;
+ gchar *tmp;
+
+ /* ALTER TABLE */
+ string = g_string_new ("ALTER TABLE ");
+
+ tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, "/COLUMN_DEF_P/TABLE_NAME", error);
+
+ if (!tmp) {
+ g_string_free (string, TRUE);
+ return NULL;
+ }
+
+ g_string_append (string, tmp);
+ g_free (tmp);
+
+ g_string_append (string, " RENAME COLUMN ");
+
+ tmp = gda_connection_operation_get_sql_identifier_at(cnc, op, "/COLUMN_DEF_P/COLUMN_NAME", error);
+ if (!tmp) {
+ g_string_free(string, TRUE);
+ return NULL;
+ }
+
+ g_string_append (string, tmp);
+ g_free (tmp);
+
+ g_string_append (string, " TO ");
+
+ tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, "/COLUMN_DEF_P/COLUMN_NEW_NAME", error);
+
+ if (!tmp) {
+ g_string_free (string, TRUE);
+ return NULL;
+ }
+
+ g_string_append (string, tmp);
+ g_free (tmp);
+
+ sql = string->str;
+ g_string_free (string, FALSE);
+
+ return sql;
+}
diff --git a/libgda/sqlite/gda-sqlite-ddl.h b/libgda/sqlite/gda-sqlite-ddl.h
index 30afc4d62..fbdba303d 100644
--- a/libgda/sqlite/gda-sqlite-ddl.h
+++ b/libgda/sqlite/gda-sqlite-ddl.h
@@ -36,6 +36,10 @@ gchar *_gda_sqlite_render_RENAME_TABLE (GdaServerProvider *provider, GdaConnecti
GdaServerOperation *op, GError **error);
gchar *_gda_sqlite_render_ADD_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error);
+gchar *_gda_sqlite_render_DROP_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
+ GdaServerOperation *op, GError **error);
+gchar *_gda_sqlite_render_RENAME_COLUMN (GdaServerProvider *provider, GdaConnection *cnc,
+ GdaServerOperation *op, GError **error);
gchar *_gda_sqlite_render_CREATE_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
GdaServerOperation *op, GError **error);
gchar *_gda_sqlite_render_DROP_INDEX (GdaServerProvider *provider, GdaConnection *cnc,
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 0ec465272..21fa20b71 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1607,6 +1607,12 @@ gda_sqlite_provider_render_operation (GdaServerProvider *provider, GdaConnection
case GDA_SERVER_OPERATION_ADD_COLUMN:
sql = _gda_sqlite_render_ADD_COLUMN (provider, cnc, op, error);
break;
+ case GDA_SERVER_OPERATION_DROP_COLUMN:
+ sql = _gda_sqlite_render_DROP_COLUMN (provider, cnc, op, error);
+ break;
+ case GDA_SERVER_OPERATION_RENAME_COLUMN:
+ sql = _gda_sqlite_render_RENAME_COLUMN (provider, cnc, op, error);
+ break;
case GDA_SERVER_OPERATION_CREATE_INDEX:
sql = _gda_sqlite_render_CREATE_INDEX (provider, cnc, op, error);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]