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



commit f754f9f4af7140b0a8150c5acd620d2784b863b7
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Mar 30 15:55:48 2011 +0200

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

 doc/C/prov-notes.xml                     |    5 +++++
 providers/oracle/gda-oracle-provider.c   |   13 ++++++++++---
 providers/oracle/oracle_specs_dsn.xml.in |    1 +
 3 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/doc/C/prov-notes.xml b/doc/C/prov-notes.xml
index 6888d76..e4afc67 100644
--- a/doc/C/prov-notes.xml
+++ b/doc/C/prov-notes.xml
@@ -34,6 +34,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 52c9c4c..f50e5c7 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -6,6 +6,7 @@
  *      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]