[libgda/LIBGDA_4.2] Oracle provider: added the "SCHEMA" parameter when opening a connection



commit bdf8dc2b3651efb6764914dffd46f8694e2e69d8
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Mar 30 18:41:33 2011 +0200

    Oracle provider: added the "SCHEMA" parameter when opening a connection

 doc/C/prov-notes.xml                     |    5 +++++
 providers/oracle/gda-oracle-provider.c   |   17 ++++++++++++-----
 providers/oracle/oracle_specs_dsn.xml.in |    1 +
 3 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/doc/C/prov-notes.xml b/doc/C/prov-notes.xml
index 91f1292..2f2fcff 100644
--- a/doc/C/prov-notes.xml
+++ b/doc/C/prov-notes.xml
@@ -29,6 +29,11 @@
               <entry>Port: database server port (leave this field empty for the default 1521 port)</entry>
               <entry>No</entry>
 	    </row>
+	    <row>
+              <entry>SCHEMA</entry>
+              <entry>Schema: Name of the schema to use. If not specified, the schema defaults to that of the connected user.</entry>
+              <entry>No</entry>
+	    </row>
 	  </tbody>
 	</tgroup>
       </table>
diff --git a/providers/oracle/gda-oracle-provider.c b/providers/oracle/gda-oracle-provider.c
index 653ac12..c2a89c2 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -1,11 +1,12 @@
-/* GDA Oracle provider
- * Copyright (C) 2009 - 2010 The GNOME Foundation.
+/*
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Rodrigo Moya <rodrigo gnome-db org>
  *      Tim Coleman <tim timcoleman com>
  *      Vivien Malerba <malerba gnome-db org>
  *      Bas Driessen <bas driessen xobas com>
+ *      Andrea Zagli <azagli libero it>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -452,7 +453,7 @@ gda_oracle_provider_open_connection (GdaServerProvider *provider, GdaConnection
 	}
 
 	/* Check for connection parameters */
-	const gchar *tnsname, *username, *password;
+	const gchar *tnsname, *username, *password, *schema;
 	gchar *easy = NULL;
  	tnsname = gda_quark_list_find (params, "TNSNAME");
 	if (!tnsname) {
@@ -479,6 +480,7 @@ gda_oracle_provider_open_connection (GdaServerProvider *provider, GdaConnection
 	if (!username)
 		username = g_get_user_name ();
 	password = gda_quark_list_find (auth, "PASSWORD");
+	schema = gda_quark_list_find (params, "SCHEMA");
 	
 	/* open the real connection to the database */
 	gint result;
@@ -670,7 +672,11 @@ gda_oracle_provider_open_connection (GdaServerProvider *provider, GdaConnection
 
 	/* Create a new instance of the provider specific data associated to a connection (OracleConnectionData),
 	 * and set its contents */
-	cdata->schema = g_ascii_strup (username, -1);
+	if (schema)
+		cdata->schema = g_ascii_strup (schema, -1);
+	else
+		cdata->schema = g_ascii_strup (username, -1);
+
 	gda_connection_internal_set_provider_data (cnc, cdata, (GDestroyNotify) gda_oracle_free_cnc_data);
 
 	/* get version */
@@ -704,7 +710,8 @@ gda_oracle_provider_open_connection (GdaServerProvider *provider, GdaConnection
 
 	/* Optionnally set some attributes for the newly opened connection (encoding to UTF-8 for example )*/
 	if (! execute_raw_command (cnc, "ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY'") ||
-	    ! execute_raw_command (cnc, "ALTER SESSION SET NLS_NUMERIC_CHARACTERS = \". \"")) {
+	    ! execute_raw_command (cnc, "ALTER SESSION SET NLS_NUMERIC_CHARACTERS = \". \"") ||
+		(schema && ! execute_raw_command (cnc, g_strdup_printf ("ALTER SESSION SET CURRENT_SCHEMA = \"%s\"", schema)))) {
 		gda_connection_internal_set_provider_data (cnc, NULL, NULL);
 		gda_oracle_free_cnc_data (cdata);
 		return FALSE;
diff --git a/providers/oracle/oracle_specs_dsn.xml.in b/providers/oracle/oracle_specs_dsn.xml.in
index 4059f84..e62c643 100644
--- a/providers/oracle/oracle_specs_dsn.xml.in
+++ b/providers/oracle/oracle_specs_dsn.xml.in
@@ -4,5 +4,6 @@
     <parameter id="DB_NAME" _name="Service name" _descr="Global database name entered during database creation (it combines a database name with a domain name)" gdatype="gchararray" nullok="FALSE"/>
     <parameter id="HOST" _name="Database server" _descr="Host on which the database server is running" gdatype="gchararray"/>
     <parameter id="PORT" _name="Port" _descr="Database server port (leave this field empty for the default 1521 port)" gdatype="gint"/>
+    <parameter id="SCHEMA" _name="Schema" _descr="Name of the schema to use. If not specified, the schema defaults to that of the connected user." gdatype="gchararray"/>
   </parameters>
 </data-set-spec>



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