[libgda] PostgreSQL provider: use new functions to work correctly in case some files are missing
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] PostgreSQL provider: use new functions to work correctly in case some files are missing
- Date: Mon, 22 Dec 2014 20:25:37 +0000 (UTC)
commit 2859cf4964a65e1991779eebdda6f5d118cead3c
Author: Vivien Malerba <malerba gnome-db org>
Date: Mon Dec 22 20:47:21 2014 +0100
PostgreSQL provider: use new functions to work correctly in case some files are missing
providers/.gitignore | 1 +
providers/postgres/Makefile.am | 14 ++++++
providers/postgres/gda-postgres-provider.c | 64 +++++++++++++--------------
providers/postgres/libmain.c | 5 ++-
providers/postgres/postgres.gresource.xml | 21 +++++++++
5 files changed, 71 insertions(+), 34 deletions(-)
---
diff --git a/providers/.gitignore b/providers/.gitignore
index ea0412c..ebe26ba 100644
--- a/providers/.gitignore
+++ b/providers/.gitignore
@@ -3,3 +3,4 @@ parser.c
parser.h
gen_def
*token_types.h
+*.gresources.c
diff --git a/providers/postgres/Makefile.am b/providers/postgres/Makefile.am
index 92ad0a2..27346d7 100644
--- a/providers/postgres/Makefile.am
+++ b/providers/postgres/Makefile.am
@@ -24,6 +24,7 @@ libgda_postgres_la_SOURCES = \
gda-postgres-util.c \
gda-postgres-util.h \
gda-postgres.h \
+ postgres.gresources.c \
libmain.c
libgda_postgres_la_LDFLAGS = -export-dynamic -module -avoid-version $(NO_UNDEFINED)
$(LIBTOOL_PROV_EXPORT_OPTIONS)
@@ -55,8 +56,21 @@ xml_in_files = \
xml_DATA = $(xml_in_files:.xml.in=.xml)
+# resources
+RESOURCES=$(xml_in_files:.xml.in=.raw.xml)
+postgres.gresources.c: postgres.gresource.xml $(RESOURCES)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source
$(srcdir)/postgres.gresource.xml
+
+%.raw.xml:%.xml.in
+ @echo " GEN $@"
+ @cat $< | sed -e 's/_\([a-zA-Z0-9]*\)=/\1=/g' -e 's/<_\([a-ZA-Z0-9_]*\)>/<\1>/g' -e
's/<\/_\([a-ZA-Z0-9_]*\)>/<\/\1>/g' -e 's/<!-- .* -->//'> $@
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgda-postgres-6.0.pc
+CLEANFILES = \
+ postgres.gresources.c \
+ $(RESOURCES)
+
EXTRA_DIST = $(xml_in_files) libgda-postgres-6.0.pc.in
DISTCLEANFILES = $(xml_DATA)
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index bd32f13..eeab7b4 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -836,35 +836,41 @@ gda_postgres_provider_create_operation (GdaServerProvider *provider, GdaConnecti
if (type == GDA_SERVER_OPERATION_CREATE_USER) {
if (cdata && (cdata->reuseable->version_float < 8.1))
- str = g_strdup ("postgres_specs_create_user.xml");
+ str = g_strdup ("postgres_specs_create_user");
else
- str = g_strdup ("postgres_specs_create_role.xml");
+ str = g_strdup ("postgres_specs_create_role");
}
else if (type == GDA_SERVER_OPERATION_DROP_USER) {
if (cdata && (cdata->reuseable->version_float < 8.1))
- str = g_strdup ("postgres_specs_drop_user.xml");
+ str = g_strdup ("postgres_specs_drop_user");
else
- str = g_strdup ("postgres_specs_drop_role.xml");
+ str = g_strdup ("postgres_specs_drop_role");
}
else {
file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
- str = g_strdup_printf ("postgres_specs_%s.xml", file);
+ str = g_strdup_printf ("postgres_specs_%s", file);
g_free (file);
}
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s.xml", str);
dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, str);
+ file = gda_server_provider_find_file (provider, dir, tmp);
g_free (dir);
+ g_free (tmp);
- if (! file) {
- g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_OPERATION_ERROR,
_("Missing spec. file '%s'"), str);
+ if (file) {
g_free (str);
- return NULL;
+ op = gda_server_operation_new (type, file);
+ g_free (file);
+ }
+ else {
+ file = g_strdup_printf ("/spec/postgres/%s.raw.xml", str);
+ g_free (str);
+ op = GDA_SERVER_OPERATION (g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", type,
+ "spec-resource", file, NULL));
+ g_free (file);
}
- g_free (str);
-
- op = gda_server_operation_new (type, file);
- g_free (file);
return op;
}
@@ -879,7 +885,6 @@ gda_postgres_provider_render_operation (GdaServerProvider *provider, GdaConnecti
gchar *sql = NULL;
gchar *file;
gchar *str;
- gchar *dir;
PostgresConnectionData *cdata = NULL;
GdaServerOperationType type;
@@ -891,38 +896,31 @@ gda_postgres_provider_render_operation (GdaServerProvider *provider, GdaConnecti
type = gda_server_operation_get_op_type (op);
if (type == GDA_SERVER_OPERATION_CREATE_USER) {
if (cdata && (cdata->reuseable->version_float < 8.1))
- str = g_strdup ("postgres_specs_create_user.xml");
+ str = g_strdup ("postgres_specs_create_user");
else
- str = g_strdup ("postgres_specs_create_role.xml");
+ str = g_strdup ("postgres_specs_create_role");
}
else if (type == GDA_SERVER_OPERATION_DROP_USER) {
if (cdata && (cdata->reuseable->version_float < 8.1))
- str = g_strdup ("postgres_specs_drop_user.xml");
+ str = g_strdup ("postgres_specs_drop_user");
else
- str = g_strdup ("postgres_specs_drop_role.xml");
+ str = g_strdup ("postgres_specs_drop_role");
}
else {
file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
- str = g_strdup_printf ("postgres_specs_%s.xml", file);
+ str = g_strdup_printf ("postgres_specs_%s", file);
g_free (file);
}
/* test @op's validity */
- dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
- file = gda_server_provider_find_file (provider, dir, str);
- g_free (dir);
+ file = g_strdup_printf ("/spec/postgres/%s.raw.xml", str);
+ g_free (str);
- if (! file) {
- g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_OPERATION_ERROR,
_("Missing spec. file '%s'"), str);
- g_free (str);
- return NULL;
- }
- g_free (str);
- if (!gda_server_operation_is_valid (op, file, error)) {
- g_free (file);
- return NULL;
- }
- g_free (file);
+ if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
+ g_free (file);
+ return NULL;
+ }
+ g_free (file);
/* actual rendering */
switch (gda_server_operation_get_op_type (op)) {
diff --git a/providers/postgres/libmain.c b/providers/postgres/libmain.c
index cb063f8..a40dd05 100644
--- a/providers/postgres/libmain.c
+++ b/providers/postgres/libmain.c
@@ -90,7 +90,10 @@ plugin_get_dsn_spec (void)
dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
ret = gda_server_provider_load_file_contents (module_path, dir, "postgres_specs_dsn.xml");
g_free (dir);
- return ret;
+ if (ret)
+ return ret;
+ else
+ return gda_server_provider_load_resource_contents ("postgres", "postgres_specs_dsn.raw.xml");
}
GdaServerProvider *
diff --git a/providers/postgres/postgres.gresource.xml b/providers/postgres/postgres.gresource.xml
new file mode 100644
index 0000000..093af57
--- /dev/null
+++ b/providers/postgres/postgres.gresource.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/spec/postgres">
+ <file compressed="true">postgres_specs_add_column.raw.xml</file>
+ <file compressed="true">postgres_specs_create_db.raw.xml</file>
+ <file compressed="true">postgres_specs_create_index.raw.xml</file>
+ <file compressed="true">postgres_specs_create_role.raw.xml</file>
+ <file compressed="true">postgres_specs_create_table.raw.xml</file>
+ <file compressed="true">postgres_specs_create_user.raw.xml</file>
+ <file compressed="true">postgres_specs_create_view.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_column.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_db.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_index.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_role.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_table.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_user.raw.xml</file>
+ <file compressed="true">postgres_specs_drop_view.raw.xml</file>
+ <file compressed="true">postgres_specs_dsn.raw.xml</file>
+ <file compressed="true">postgres_specs_rename_table.raw.xml</file>
+ </gresource>
+</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]