4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
11 // Daniel Morgan <danmorg@sc.rr.com>
12 // Tim Coleman <tim@timcoleman.com>
14 // Copyright (C) Daniel Morgan, 2002
15 // Copyright (C) Tim Coleman, 2003
17 // Original source code for setting ConnectionString
18 // by Tim Coleman <tim@timcoleman.com>
20 // Copyright (C) Tim Coleman, 2002
22 // Licensed under the MIT/X11 License.
26 using System.Collections;
27 using System.Collections.Specialized;
28 using System.ComponentModel;
30 using System.Data.OracleClient.Oci;
33 namespace System.Data.OracleClient
35 internal struct OracleConnectionInfo
37 public string Username;
38 public string Password;
39 public string Database;
42 public class OracleConnection : Component, ICloneable, IDbConnection
47 ConnectionState state;
48 OracleConnectionInfo conInfo;
49 OracleTransaction transaction = null;
50 string connectionString = "";
51 OracleDataReader dataReader = null;
57 public OracleConnection ()
59 state = ConnectionState.Closed;
63 public OracleConnection (string connectionString)
66 this.connectionString = connectionString;
69 #endregion // Constructors
73 // only for DEBUG purposes - not part of MS.NET 1.1 OracleClient
74 public static uint ConnectionCount {
76 uint count = 0; // OciGlue.OciGlue_ConnectionCount();
81 int IDbConnection.ConnectionTimeout {
86 string IDbConnection.Database {
88 get { return String.Empty; }
91 internal OracleDataReader DataReader {
92 get { return dataReader; }
93 set { dataReader = value; }
96 public ConnectionState State {
100 public string ConnectionString {
101 get { return connectionString; }
102 set { SetConnectionString (value); }
105 internal OciGlue Oci {
109 internal OracleTransaction Transaction {
110 get { return transaction; }
111 set { transaction = value; }
114 #endregion // Properties
118 public OracleTransaction BeginTransaction ()
120 return BeginTransaction (IsolationLevel.ReadCommitted);
123 public OracleTransaction BeginTransaction (IsolationLevel il)
125 if (state == ConnectionState.Closed)
126 throw new InvalidOperationException ("The connection is not open.");
127 if (transaction != null)
128 throw new InvalidOperationException ("OracleConnection does not support parallel transactions.");
130 OciTransactionHandle transactionHandle = oci.CreateTransaction ();
131 if (transactionHandle == null)
132 throw new Exception("Error: Unable to start transaction");
134 transactionHandle.Begin ();
135 transaction = new OracleTransaction (this, il, transactionHandle);
142 void IDbConnection.ChangeDatabase (string databaseName)
144 throw new NotImplementedException ();
147 public OracleCommand CreateCommand ()
149 OracleCommand command = new OracleCommand ();
150 command.Connection = this;
155 object ICloneable.Clone ()
157 throw new NotImplementedException ();
160 IDbTransaction IDbConnection.BeginTransaction ()
162 return BeginTransaction ();
165 IDbTransaction IDbConnection.BeginTransaction (IsolationLevel iso)
167 return BeginTransaction (iso);
170 IDbCommand IDbConnection.CreateCommand ()
172 return CreateCommand ();
175 void IDisposable.Dispose ()
178 GC.SuppressFinalize (this);
183 oci.CreateConnection (conInfo);
184 state = ConnectionState.Open;
190 state = ConnectionState.Closed;
194 void SetConnectionString (string connectionString)
196 this.connectionString = connectionString;
197 conInfo.Username = "";
198 conInfo.Database = "";
199 conInfo.Password = "";
201 if (connectionString == String.Empty)
204 connectionString += ";";
205 NameValueCollection parameters = new NameValueCollection ();
207 bool inQuote = false;
208 bool inDQuote = false;
210 string name = String.Empty;
211 string value = String.Empty;
212 StringBuilder sb = new StringBuilder ();
214 foreach (char c in connectionString) {
220 inDQuote = !inDQuote;
223 if (!inDQuote && !inQuote) {
224 if (name != String.Empty && name != null) {
225 value = sb.ToString ();
226 parameters [name.ToUpper ().Trim ()] = value.Trim ();
229 value = String.Empty;
230 sb = new StringBuilder ();
236 if (!inDQuote && !inQuote) {
237 name = sb.ToString ();
238 sb = new StringBuilder ();
249 SetProperties (parameters);
252 private void SetProperties (NameValueCollection parameters)
255 foreach (string name in parameters) {
256 value = parameters[name];
261 // set Database property
262 conInfo.Database = value;
266 conInfo.Password = value;
270 conInfo.Username = value;
273 throw new Exception("Connection parameter not supported." + name);
278 #endregion // Methods