2 // System.Data.Common.AbstractDBConnection
\r
5 // Konstantin Triger <kostat@mainsoft.com>
\r
6 // Boris Kirzner <borisk@mainsoft.com>
\r
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
\r
13 // a copy of this software and associated documentation files (the
\r
14 // "Software"), to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify, merge, publish,
\r
16 // distribute, sublicense, and/or sell copies of the Software, and to
\r
17 // permit persons to whom the Software is furnished to do so, subject to
\r
18 // the following conditions:
\r
20 // The above copyright notice and this permission notice shall be
\r
21 // included in all copies or substantial portions of the Software.
\r
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using System.Globalization;
\r
34 using System.Data.ProviderBase;
\r
35 using System.Data.Configuration;
\r
36 using System.Configuration;
\r
37 using System.Collections;
\r
38 using System.Collections.Specialized;
\r
40 using System.Text.RegularExpressions;
\r
41 using Mainsoft.Data.Jdbc.Providers;
\r
42 using System.Data.Common;
\r
48 using Mainsoft.Data.Configuration;
\r
50 namespace System.Data.ProviderBase
\r
52 public abstract class AbstractDBConnection : DbConnection, ICloneable
\r
54 #region ObjectNamesHelper
\r
56 private sealed class ObjectNamesHelper
\r
58 //static readonly Regex NameOrder = new Regex(@"^\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
59 static readonly Regex NameOrder = new Regex(@"^((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
61 //static readonly Regex SchemaNameOrder = new Regex(@"^\s*((\[(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
62 static readonly Regex SchemaNameOrder = new Regex(@"^((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
63 //static readonly Regex CatalogSchemaNameOrder = new Regex(@"^\s*((\[\s*(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
64 //static readonly Regex CatalogSchemaNameOrder = new Regex(@"^\s*((\[\s*(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<SCHEMA>(\s*[^\]\s])+)\s*\])|(?<SCHEMA>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
65 static readonly Regex CatalogSchemaNameOrder = new Regex(@"^((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
67 //static readonly Regex CatalogNameOrder = new Regex(@"^\s*((\[(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
68 //static readonly Regex CatalogNameOrder = new Regex(@"^\s*((\[(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
69 static readonly Regex CatalogNameOrder = new Regex(@"^((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
70 //static readonly Regex SchemaCatalogNameOrder = new Regex(@"^\s*((\[\s*(?<SCHEMA>(\s*[^\[\]\s])+)\s*\])|(?<SCHEMA>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<CATALOG>(\s*[^\[\]\s])+)\s*\])|(?<CATALOG>(\w|!|\#|\$)*(\s*(\w|!|\#|\$)+)*))\s*\.\s*((\[(?<NAME>(\s*[^\[\]\s])+)\s*\])|(?<NAME>(\w|!|\#|\$)+(\s*(\w|!|\#|\$)+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
71 //static readonly Regex SchemaCatalogNameOrder = new Regex(@"^\s*((\[\s*(?<SCHEMA>(\s*[^\]\s])+)\s*\])|(?<SCHEMA>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<CATALOG>(\s*[^\]\s])+)\s*\])|(?<CATALOG>([^\.\s])*(\s*([^\.\s])+)*))\s*\.\s*((\[(?<NAME>(\s*[^\]\s])+)\s*\])|(?<NAME>([^\.\s])+(\s*([^\.\s])+)*))\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
72 static readonly Regex SchemaCatalogNameOrder = new Regex(@"^((\[(?<SCHEMA>[^\]]+)\])|(?<SCHEMA>[^\.\[\]]+))\s*\.\s*((\[(?<CATALOG>[^\]]+)\])|(?<CATALOG>[^\.\[\]]+))\s*\.\s*((\[(?<NAME>[^\]]+)\])|(?<NAME>[^\.\[\]]+))$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
\r
74 internal static ObjectNameResolver[] GetSyntaxPatterns(AbstractDBConnection connection)
\r
76 ArrayList collection = new ArrayList();
\r
77 collection.Add(new ObjectNameResolver(NameOrder));
\r
79 ObjectNameResolversCollection basic = (ObjectNameResolversCollection) ConfigurationSettings.GetConfig ("Mainsoft.Data.Configuration/objectnameresolution");
\r
81 java.sql.DatabaseMetaData metaData = connection.JdbcConnection.getMetaData();
\r
82 string productName = metaData.getDatabaseProductName();
\r
84 foreach(ObjectNameResolver nameResolver in basic) {
\r
85 if (productName.IndexOf(nameResolver.DbName) != -1) {
\r
86 collection.Add(nameResolver);
\r
91 if (metaData.isCatalogAtStart()) {
\r
92 collection.Add(new ObjectNameResolver(SchemaNameOrder));
\r
93 collection.Add(new ObjectNameResolver(CatalogNameOrder));
\r
94 collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
\r
95 collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
\r
98 collection.Add(new ObjectNameResolver(CatalogNameOrder));
\r
99 collection.Add(new ObjectNameResolver(SchemaNameOrder));
\r
100 collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
\r
101 collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
\r
104 return (ObjectNameResolver[])collection.ToArray(typeof(ObjectNameResolver));
\r
108 #endregion // ObjectNamesHelper
\r
112 private const int DEFAULT_TIMEOUT = 15;
\r
114 private java.sql.Connection _jdbcConnnection;
\r
115 private ConnectionState _internalState;
\r
116 private object _internalStateSync = new object();
\r
118 private string _connectionString = String.Empty;
\r
119 IConnectionStringDictionary _connectionStringBuilder;
\r
120 IConnectionProvider _connectionProvider;
\r
122 private ArrayList _referencedObjects = new ArrayList();
\r
123 private ObjectNameResolver[] _syntaxPatterns;
\r
125 #endregion // Fields
\r
127 #region Constructors
\r
129 public AbstractDBConnection(string connectionString)
\r
131 _connectionString = connectionString;
\r
134 #endregion // Constructors
\r
138 public override String ConnectionString
\r
140 get { return _connectionString; }
\r
143 throw ExceptionHelper.NotAllowedWhileConnectionOpen("ConnectionString",_internalState);
\r
145 _connectionString = value;
\r
146 _connectionProvider = null;
\r
147 _connectionStringBuilder = null;
\r
151 public override int ConnectionTimeout
\r
154 string timeoutStr = (string)ConnectionStringBuilder["loginTimeout"];
\r
155 if (timeoutStr != null && timeoutStr.Length > 0) {
\r
157 return Convert.ToInt32(timeoutStr);
\r
159 catch(FormatException) {
\r
160 throw ExceptionHelper.InvalidValueForKey("connect timeout");
\r
162 catch (OverflowException) {
\r
163 throw ExceptionHelper.InvalidValueForKey("connect timeout");
\r
166 return DEFAULT_TIMEOUT;
\r
170 public override String Database
\r
173 if ((State & ConnectionState.Open) != 0)
\r
174 return JdbcConnection.getCatalog();
\r
176 return (string)ConnectionStringBuilder["DATABASE"];
\r
180 public override ConnectionState State
\r
184 if ((JdbcConnection == null) || JdbcConnection.isClosed()) {
\r
185 // jdbc connection not initialized or closed
\r
186 if (_internalState == ConnectionState.Closed ) {
\r
187 return ConnectionState.Closed;
\r
191 // jdbc connection is opened
\r
192 if ((_internalState & ConnectionState.Open) != 0) {
\r
193 return ConnectionState.Open;
\r
196 return ConnectionState.Broken;
\r
198 catch (SQLException) {
\r
199 return ConnectionState.Broken;
\r
204 internal bool IsExecuting
\r
207 return ((_internalState & ConnectionState.Executing) != 0);
\r
211 lock(_internalStateSync) {
\r
212 // to switch to executing, the connection must be in opened
\r
214 if (_internalState != ConnectionState.Open) {
\r
216 throw ExceptionHelper.OpenedReaderExists();
\r
218 throw ExceptionHelper.OpenConnectionRequired("",_internalState);
\r
220 _internalState |= ConnectionState.Executing;
\r
223 if (!IsExecuting) {
\r
224 throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Executing.ToString() + " while in state " + _internalState.ToString());
\r
226 _internalState &= ~ConnectionState.Executing;
\r
232 internal bool IsFetching
\r
235 return ((_internalState & ConnectionState.Fetching) != 0);
\r
239 lock(_internalStateSync) {
\r
241 // to switch to fetching connection must be in opened, executing
\r
242 if (((_internalState & ConnectionState.Open) == 0) || ((_internalState & ConnectionState.Executing) == 0)) {
\r
243 throw ExceptionHelper.OpenConnectionRequired("",_internalState);
\r
245 _internalState |= ConnectionState.Fetching;
\r
249 throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Fetching.ToString() + " while in state " + _internalState.ToString());
\r
251 _internalState &= ~ConnectionState.Fetching;
\r
257 internal bool IsOpened
\r
260 return ((_internalState & ConnectionState.Open) != 0);
\r
264 lock(_internalStateSync) {
\r
266 // only connecting connection can be opened
\r
267 if ((_internalState != ConnectionState.Connecting)) {
\r
268 throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
\r
270 _internalState |= ConnectionState.Open;
\r
274 throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Open.ToString() + " while in state " + _internalState.ToString());
\r
276 _internalState &= ~ConnectionState.Open;
\r
282 internal bool IsConnecting
\r
285 return ((_internalState & ConnectionState.Connecting) != 0);
\r
289 lock(_internalStateSync) {
\r
291 // to switch to connecting conection must be in closed or in opened
\r
292 if ((_internalState != ConnectionState.Closed) && (_internalState != ConnectionState.Open)) {
\r
293 throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
\r
295 _internalState |= ConnectionState.Connecting;
\r
298 if (!IsConnecting) {
\r
299 throw new InvalidOperationException("Connection : Impossible to tear down from state " + ConnectionState.Connecting.ToString() + " while in state " + _internalState.ToString());
\r
301 _internalState &= ~ConnectionState.Connecting;
\r
307 public override string DataSource
\r
310 return (string)ConnectionStringBuilder["SERVERNAME"];
\r
314 internal ConnectionState InternalState
\r
316 get { return _internalState; }
\r
320 protected internal java.sql.Connection JdbcConnection
\r
322 get { return _jdbcConnnection; }
\r
323 set { _jdbcConnnection = value; }
\r
326 internal ObjectNameResolver[] SyntaxPatterns
\r
329 if (_syntaxPatterns == null) {
\r
330 _syntaxPatterns = ObjectNamesHelper.GetSyntaxPatterns(this);
\r
332 return _syntaxPatterns;
\r
336 protected internal IConnectionProvider ConnectionProvider {
\r
339 if (_connectionProvider == null)
\r
340 _connectionProvider = GetConnectionProvider();
\r
342 return _connectionProvider;
\r
344 catch(SQLException exp) {
\r
345 throw CreateException(exp);
\r
349 protected internal IConnectionStringDictionary ConnectionStringBuilder {
\r
352 if (_connectionStringBuilder == null)
\r
353 _connectionStringBuilder = ConnectionProvider.GetConnectionStringBuilder(ConnectionString);
\r
355 return _connectionStringBuilder;
\r
357 catch(SQLException exp) {
\r
358 throw CreateException(exp);
\r
362 protected abstract IConnectionProvider GetConnectionProvider();
\r
364 static protected IConnectionProvider GetConnectionProvider(string sectionMame, string provider) {
\r
365 if (provider == null)
\r
366 throw new ArgumentNullException("provider");
\r
368 IList providers = (IList) ConfigurationSettings.GetConfig(sectionMame);
\r
369 if (providers.Count == 0)
\r
370 throw new ArgumentException("Configuration section is empty.", "sectionName");
\r
372 for (int i = 0; i < providers.Count; i++) {
\r
373 IDictionary providerInfo = (IDictionary) providers[i];
\r
375 string curProvider = (string)providerInfo[ConfigurationConsts.Name];
\r
376 if (String.Compare(provider, 0, curProvider, 0, provider.Length, StringComparison.OrdinalIgnoreCase) == 0) {
\r
377 string providerType = (string) providerInfo [ConfigurationConsts.ProviderType];
\r
378 if (providerType == null || providerType.Length == 0)
\r
379 return new GenericProvider (providerInfo);
\r
381 Type t = Type.GetType (providerType);
\r
382 return (IConnectionProvider) Activator.CreateInstance (t , new object[] {providerInfo});
\r
387 throw new ArgumentException(
\r
388 String.Format("Unknown provider name '{0}'", provider), "ConnectionString");
\r
391 #endregion // Properties
\r
394 // since WS also does not permits dynamically change of login timeout and tomcat does no implements - do not do it at all
\r
395 //ds.setLoginTimeout(ConnectionTimeout);
\r
397 protected internal abstract void OnSqlWarning(SQLWarning warning);
\r
399 protected abstract SystemException CreateException(SQLException e);
\r
401 protected abstract SystemException CreateException(string message);
\r
403 public override void Close()
\r
405 ConnectionState orig = State;
\r
408 if (JdbcConnection != null && !JdbcConnection.isClosed()) {
\r
409 if (!JdbcConnection.getAutoCommit())
\r
410 JdbcConnection.rollback();
\r
411 JdbcConnection.close();
\r
414 catch (Exception e) {
\r
415 // suppress exception
\r
417 Console.WriteLine("Exception catched at Conection.Close() : {0}\n{1}\n{2}",e.GetType().FullName,e.Message,e.StackTrace);
\r
421 JdbcConnection = null;
\r
422 lock(_internalStateSync) {
\r
423 _internalState = ConnectionState.Closed;
\r
427 ConnectionState current = State;
\r
428 if (current != orig)
\r
429 OnStateChange (new StateChangeEventArgs (orig, current));
\r
432 internal protected virtual void OnSqlException(SQLException exp)
\r
434 throw CreateException(exp);
\r
437 internal void AddReference(object referencedObject)
\r
438 { lock(_referencedObjects.SyncRoot) {
\r
439 _referencedObjects.Add(new WeakReference(referencedObject));
\r
443 internal void RemoveReference(object referencedObject)
\r
445 lock(_referencedObjects.SyncRoot) {
\r
446 for(int i = 0; i < _referencedObjects.Count; i++) {
\r
447 WeakReference wr = (WeakReference) _referencedObjects[i];
\r
448 if (wr.IsAlive && (wr.Target == referencedObject)) {
\r
449 _referencedObjects.RemoveAt(i);
\r
455 private void ClearReferences()
\r
457 ArrayList oldList = _referencedObjects;
\r
458 _referencedObjects = new ArrayList();
\r
460 for(int i = 0; i < oldList.Count; i++) {
\r
461 WeakReference wr = (WeakReference) oldList[i];
\r
463 ClearReference(wr.Target);
\r
468 private void ClearReference(object referencedObject)
\r
471 if (referencedObject is AbstractDbCommand) {
\r
472 ((AbstractDbCommand)referencedObject).CloseInternal();
\r
474 else if (referencedObject is AbstractDataReader) {
\r
475 ((AbstractDataReader)referencedObject).CloseInternal();
\r
478 catch (SQLException) {
\r
479 // suppress exception since it's possible that command or reader are in inconsistent state
\r
483 public override void Open()
\r
485 if (_connectionString == null || _connectionString.Length == 0) {
\r
486 throw ExceptionHelper.ConnectionStringNotInitialized();
\r
489 IsConnecting = true;
\r
491 if (JdbcConnection != null && !JdbcConnection.isClosed()) {
\r
492 throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
\r
495 JdbcConnection = ConnectionProvider.GetConnection (ConnectionStringBuilder);
\r
499 OnStateChange (new StateChangeEventArgs (ConnectionState.Closed, ConnectionState.Open));
\r
501 catch (SQLWarning warning) {
\r
502 OnSqlWarning(warning);
\r
504 catch (SQLException exp) {
\r
505 OnSqlException(exp);
\r
508 IsConnecting = false;
\r
512 public override void ChangeDatabase(String database)
\r
514 IsConnecting = true;
\r
517 java.sql.Connection con = JdbcConnection;
\r
518 con.setCatalog(database);
\r
519 // ConnectionStringHelper.UpdateValue(UserParameters,StringManager.GetStringArray("CON_DATABASE"),database);
\r
521 catch (SQLWarning warning) {
\r
522 OnSqlWarning(warning);
\r
524 catch (SQLException exp) {
\r
525 throw CreateException(exp);
\r
528 IsConnecting = false;
\r
532 public override string ServerVersion {
\r
534 // only if the driver support this methods
\r
536 if (JdbcConnection == null)
\r
537 return String.Empty;
\r
539 java.sql.DatabaseMetaData metaData = JdbcConnection.getMetaData();
\r
540 return metaData.getDatabaseProductVersion();
\r
542 catch (SQLException exp) {
\r
543 throw CreateException(exp);
\r
548 internal string JdbcProvider {
\r
550 // only if the driver support this methods
\r
552 if (JdbcConnection == null)
\r
553 return String.Empty;
\r
555 java.sql.DatabaseMetaData metaData = JdbcConnection.getMetaData();
\r
556 return metaData.getDriverName() + " " + metaData.getDriverVersion();
\r
558 catch (SQLException exp) {
\r
559 return String.Empty; //suppress
\r
564 protected override void Dispose(bool disposing)
\r
568 if (JdbcConnection != null && !JdbcConnection.isClosed()) {
\r
569 JdbcConnection.close();
\r
571 JdbcConnection = null;
\r
573 catch (java.sql.SQLException exp) {
\r
574 throw CreateException(exp);
\r
577 base.Dispose(disposing);
\r
580 internal void ValidateBeginTransaction()
\r
582 if (State != ConnectionState.Open) {
\r
583 throw new InvalidOperationException(String.Format("{0} requires an open and available Connection. The connection's current state is {1}.", new object[] {"BeginTransaction", State}));
\r
586 if (!JdbcConnection.getAutoCommit()) {
\r
587 throw new System.InvalidOperationException("Parallel transactions are not supported.");
\r
591 internal ArrayList GetProcedureColumns(String procedureString, AbstractDbCommand command)
\r
593 ArrayList col = new ArrayList();
\r
595 ObjectNameResolver[] nameResolvers = SyntaxPatterns;
\r
596 java.sql.ResultSet res = null;
\r
597 string catalog = null;
\r
598 string schema = null;
\r
599 string spname = null;
\r
601 java.sql.DatabaseMetaData metadata = JdbcConnection.getMetaData();
\r
602 bool storesUpperCaseIdentifiers = false;
\r
603 bool storesLowerCaseIdentifiers = false;
\r
605 storesUpperCaseIdentifiers = metadata.storesUpperCaseIdentifiers();
\r
606 storesLowerCaseIdentifiers = metadata.storesLowerCaseIdentifiers();
\r
608 catch (SQLException e) {
\r
612 for(int i=0; i < nameResolvers.Length; i++) {
\r
613 ObjectNameResolver nameResolver = nameResolvers[i];
\r
614 Match match = nameResolver.Match(procedureString);
\r
616 if (match.Success) {
\r
617 spname = ObjectNameResolver.GetName(match);
\r
618 schema = ObjectNameResolver.GetSchema(match);
\r
619 catalog = ObjectNameResolver.GetCatalog(match);
\r
621 // make all identifiers uppercase or lowercase according to database metadata
\r
622 if (storesUpperCaseIdentifiers) {
\r
623 spname = (spname.Length > 0) ? spname.ToUpper() : null;
\r
624 schema = (schema.Length > 0) ? schema.ToUpper() : null;
\r
625 catalog = (catalog.Length > 0) ? catalog.ToUpper() : null;
\r
627 else if (storesLowerCaseIdentifiers) {
\r
628 spname = (spname.Length > 0) ? spname.ToLower() : null;
\r
629 schema = (schema.Length > 0) ? schema.ToLower() : null;
\r
630 catalog = (catalog.Length > 0) ? catalog.ToLower() : null;
\r
633 spname = (spname.Length > 0) ? spname : null;
\r
634 schema = (schema.Length > 0) ? schema : null;
\r
635 catalog = (catalog.Length > 0) ? catalog : null;
\r
638 // catalog from db is always in correct caps
\r
639 if (catalog == null) {
\r
640 catalog = JdbcConnection.getCatalog();
\r
644 // always get the first procedure that db returns
\r
645 res = metadata.getProcedures(catalog, schema, spname);
\r
647 catalog = res.getString(1);
\r
648 schema = res.getString(2);
\r
649 spname = res.getString(3);
\r
655 catch { // suppress exception
\r
666 if (spname == null || spname.Length == 0) {
\r
671 // get procedure columns based o procedure metadata
\r
672 res = metadata.getProcedureColumns(catalog, schema, spname, null);
\r
673 while (res.next()) {
\r
674 // since there is still a possibility that some of the parameters to getProcedureColumn were nulls,
\r
675 // we need to filter the results with strict matching
\r
676 if ((res.getString(1) != catalog ) || (res.getString(2) != schema) || (res.getString(3) != spname)) {
\r
680 AbstractDbParameter parameter = (AbstractDbParameter)command.CreateParameter();
\r
682 parameter.SetParameterName(res);
\r
683 parameter.SetParameterDbType(res);
\r
684 parameter.SetSpecialFeatures(res);
\r
686 //get parameter direction
\r
687 short direction = res.getShort("COLUMN_TYPE");
\r
688 if(direction == 1) //DatabaseMetaData.procedureColumnIn
\r
689 parameter.Direction = ParameterDirection.Input;
\r
690 else if(direction == 2) //DatabaseMetaData.procedureColumnInOut
\r
691 parameter.Direction = ParameterDirection.InputOutput;
\r
692 else if(direction == 4) //DatabaseMetaData.procedureColumnOut
\r
693 parameter.Direction = ParameterDirection.Output;
\r
694 else if(direction == 5) //DatabaseMetaData.procedureColumnReturn
\r
695 parameter.Direction = ParameterDirection.ReturnValue;
\r
697 //get parameter precision and scale
\r
698 parameter.SetParameterPrecisionAndScale(res);
\r
700 parameter.SetParameterSize(res);
\r
701 parameter.SetParameterIsNullable(res);
\r
703 col.Add(parameter);
\r
712 catch(Exception e) {
\r
715 Console.WriteLine("Exception catched at AbstractDBConnection.GetProcedureColumns() : {0}\n{1}\n{2}",e.GetType().FullName,e.Message,e.StackTrace);
\r
721 #endregion // Methods
\r
723 #region ICloneable Members
\r
725 public virtual object Clone() {
\r
726 AbstractDBConnection con = (AbstractDBConnection)MemberwiseClone();
\r
727 con._internalState = ConnectionState.Closed;
\r
728 con._internalStateSync = new object();
\r
729 con._jdbcConnnection = null;
\r
730 con._referencedObjects = new ArrayList();
\r
731 con._syntaxPatterns = null;
\r