Inheritance: System.Data.Common.DbConnection, ICloneable
Ejemplo n.º 1
0
		string CreateTableDirectCommandText(string tableNames) {
			string forBrowse = String.Empty;
			if ((Behavior & CommandBehavior.KeyInfo) != 0) {
				AbstractDBConnection connection = (AbstractDBConnection)Connection;
				if (connection != null) {
					string dbname = connection.JdbcConnection.getMetaData().getDatabaseProductName();
					if (dbname == "Microsoft SQL Server")	//must add "FOR BROWSE" for selects
						forBrowse = " FOR BROWSE";
				}
			}

			string[] names = tableNames.Split(',');
			StringBuilder sb = new StringBuilder();

			for(int i = 0; i < names.Length; i++) {
				sb.Append("SELECT * FROM ");
				sb.Append(names[i]);
				sb.Append(forBrowse);
				sb.Append(';');
			}
				
			if(names.Length <= 1) {
				sb.Remove(sb.Length - 1,1);
			}
			return sb.ToString();
		}
Ejemplo n.º 2
0
			internal static ObjectNameResolver[] GetSyntaxPatterns(AbstractDBConnection connection)
			{
				ArrayList collection = new ArrayList();
				collection.Add(new ObjectNameResolver(NameOrder));

				ObjectNameResolversCollection basic = (ObjectNameResolversCollection) ConfigurationSettings.GetConfig ("Mainsoft.Data.Configuration/objectnameresolution");
				
				java.sql.DatabaseMetaData metaData = connection.JdbcConnection.getMetaData();
				string productName = metaData.getDatabaseProductName();

				foreach(ObjectNameResolver nameResolver in basic) {
					if (productName.IndexOf(nameResolver.DbName) != -1) {
						collection.Add(nameResolver);
					}
				}

				//defaults
				if (metaData.isCatalogAtStart()) {
					collection.Add(new ObjectNameResolver(SchemaNameOrder));
					collection.Add(new ObjectNameResolver(CatalogNameOrder));
					collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
					collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
				}
				else {
					collection.Add(new ObjectNameResolver(CatalogNameOrder));
					collection.Add(new ObjectNameResolver(SchemaNameOrder));
					collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
					collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
				}

				return (ObjectNameResolver[])collection.ToArray(typeof(ObjectNameResolver));				
			}
Ejemplo n.º 3
0
		protected AbstractDbErrorCollection(SQLException e, AbstractDBConnection connection) {
			_list = new ArrayList();

			while(e != null) {
				_list.Add(CreateDbError(e, connection));
				e = e.getNextException();
			}
		}
Ejemplo n.º 4
0
 protected AbstractDbError(SQLException e, AbstractDBConnection connection)
 {
     _e = e;
     if (connection != null)
     {
         _jdbcProvider = connection.JdbcProvider;
     }
 }
Ejemplo n.º 5
0
		int PrepareSimpleQuery(StringBuilder sb, string query, IList userParametersList, int userParametersListStart)
		{
			int queryCurrentPosition = 0;
			int userParametersListPosition = userParametersListStart;

			if (userParametersList.Count > 0) {
				for (SimpleMatch m = ParameterRegExp.Match(query);
					m.Success;m = m.NextMatch()) {

					SimpleCapture parameterCapture = m;
					sb.Append(query,queryCurrentPosition,parameterCapture.Index - queryCurrentPosition);

					// advance in query
					queryCurrentPosition = parameterCapture.Index + parameterCapture.Length;	

					AbstractDbParameter userParameter = GetUserParameter(parameterCapture.Value, userParametersList, userParametersListPosition);

					if (userParameter != null) {
						if (IsNullParameter(userParameter)) {
							sb.Append("null");
							NullParametersInPrepare = true;
						}
						else {
							sb.Append('?');
							InternalParameters.Add(userParameter);	
						}	
						// advance in user parameters
						userParametersListPosition++;				
					}
					else {
						sb.Append(parameterCapture.Value);
					}
				}
			}

			sb.Append(query,queryCurrentPosition,query.Length - queryCurrentPosition);
			int userParamsConsumed = userParametersListPosition - userParametersListStart;

			if ((Behavior & CommandBehavior.KeyInfo) == 0)
				return userParamsConsumed;

			AbstractDBConnection connection = (AbstractDBConnection)Connection;
			if (connection == null)
				return userParamsConsumed;

			string dbname = connection.JdbcConnection.getMetaData().getDatabaseProductName();
			if (dbname == "Microsoft SQL Server") {	//must add "FOR BROWSE" for selects
#if USE_DOTNET_REGEX
					if (!SqlStatementsHelper.ForBrowseStatementReqExp.IsMatch(query))
						sb.Append(" FOR BROWSE");
#else
					if (!SqlStatementsHelper.ForBrowseStatementReqExp.matcher ((java.lang.CharSequence)(object)query).find ())
						sb.Append (" FOR BROWSE");
#endif
			}

			return userParamsConsumed;
		}
Ejemplo n.º 6
0
        protected AbstractDbErrorCollection(SQLException e, AbstractDBConnection connection)
        {
            _list = new ArrayList();

            while (e != null)
            {
                _list.Add(CreateDbError(e, connection));
                e = e.getNextException();
            }
        }
        public virtual object Clone()
        {
            AbstractDBConnection con = (AbstractDBConnection)MemberwiseClone();

            con._internalState     = ConnectionState.Closed;
            con._internalStateSync = new object();
            con._jdbcConnnection   = null;
            con._referencedObjects = new ArrayList();
            con._syntaxPatterns    = null;
            return(con);
        }
Ejemplo n.º 8
0
			internal ArrayList GetProcedureColumns(AbstractDBConnection connection, String commandText,AbstractDbCommand command) 
			{
				string connectionCatalog = connection.JdbcConnection.getCatalog();
				string key = String.Concat(connection.ConnectionString, connectionCatalog, commandText);
				System.Collections.Hashtable cache = Cache;

				ArrayList col = cache[key] as ArrayList;

				if (null != col) {
					return col;
				}
	
				col = connection.GetProcedureColumns(commandText,command);
				if (col != null)
					cache[key] = col;
				return col;				
			}
Ejemplo n.º 9
0
        /**
         * @see System.Data.IDbTransaction#Commit()
         */
        public override void Commit()
        {
            if (_connection == null)
            {
                return;
            }

            try
            {
                _connection.JdbcConnection.commit();
                _connection.JdbcConnection.setAutoCommit(true);
                _connection = null;
            }
            catch (SQLException exp)
            {
                throw new SystemException(exp.Message, exp);
            }
        }
Ejemplo n.º 10
0
 public AbstractTransaction(
     IsolationLevel isolationLevel,
     AbstractDBConnection connection,
     String transactionName)
 {
     connection.ValidateBeginTransaction();
     _transactionName = transactionName;
     _connection      = connection;
     _isolationLevel  = isolationLevel;
     try
     {
         _connection.JdbcConnection.setAutoCommit(false);
         _connection.JdbcConnection.setTransactionIsolation(
             convertIsolationLevel(isolationLevel));
     }
     catch (SQLException exp)
     {
         throw new System.InvalidOperationException(exp.Message, exp);
     }
 }
Ejemplo n.º 11
0
        public AbstractTransaction(
            IsolationLevel isolationLevel,
            AbstractDBConnection connection,
            String transactionName)
        {
			connection.ValidateBeginTransaction();
            _transactionName = transactionName;
            _connection = connection;
            _isolationLevel = isolationLevel;
            try
            {
                _connection.JdbcConnection.setAutoCommit(false);
                _connection.JdbcConnection.setTransactionIsolation(
                convertIsolationLevel(isolationLevel));
            }
            catch (SQLException exp)
            {
                throw new System.InvalidOperationException(exp.Message, exp);
            }
        }
Ejemplo n.º 12
0
		public AbstractDbCommand(
			String cmdText,
			AbstractDBConnection connection,
			AbstractTransaction transaction)
		{
			_connection = connection;
			_commandText = cmdText;
			_transaction = transaction;

			_commandTimeout = 30;
			_commandType = CommandType.Text;
			_designTimeVisible = true;
			_updatedRowSource = UpdateRowSource.Both;

			_isCommandPrepared = false;
			_explicitPrepare = false;
			_recordsAffected = -1;
			if (connection != null) {
				connection.AddReference(this);
			}
		}
            internal static ObjectNameResolver[] GetSyntaxPatterns(AbstractDBConnection connection)
            {
                ArrayList collection = new ArrayList();

                collection.Add(new ObjectNameResolver(NameOrder));

                ObjectNameResolversCollection basic = (ObjectNameResolversCollection)ConfigurationSettings.GetConfig("Mainsoft.Data.Configuration/objectnameresolution");

                java.sql.DatabaseMetaData metaData = connection.JdbcConnection.getMetaData();
                string productName = metaData.getDatabaseProductName();

                foreach (ObjectNameResolver nameResolver in basic)
                {
                    if (productName.IndexOf(nameResolver.DbName) != -1)
                    {
                        collection.Add(nameResolver);
                    }
                }

                //defaults
                if (metaData.isCatalogAtStart())
                {
                    collection.Add(new ObjectNameResolver(SchemaNameOrder));
                    collection.Add(new ObjectNameResolver(CatalogNameOrder));
                    collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
                    collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
                }
                else
                {
                    collection.Add(new ObjectNameResolver(CatalogNameOrder));
                    collection.Add(new ObjectNameResolver(SchemaNameOrder));
                    collection.Add(new ObjectNameResolver(SchemaCatalogNameOrder));
                    collection.Add(new ObjectNameResolver(CatalogSchemaNameOrder));
                }

                return((ObjectNameResolver[])collection.ToArray(typeof(ObjectNameResolver)));
            }
		protected AbstractDbException(string message, SQLException cause, AbstractDBConnection connection) : base(message, cause) {
			_connection = connection;
			_cause = cause;
		}
		protected AbstractDbException(SQLException cause, AbstractDBConnection connection) : this(String.Empty, cause, connection) {}
		protected AbstractDbException(Exception cause, AbstractDBConnection connection) : base(cause.Message, cause) {
			_connection = connection;
		}
		protected override AbstractDbError CreateDbError(SQLException e, AbstractDBConnection connection) {
			return new OracleError(e, connection);
		}
		internal OracleErrorCollection(SQLException e, AbstractDBConnection connection) : base(e, connection) {
		}
Ejemplo n.º 19
0
		protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
		{
			AbstractDBConnection connection = (AbstractDBConnection)Connection;
			if (connection == null) {
				throw ExceptionHelper.ConnectionNotInitialized("ExecuteReader");
			}

			connection.IsExecuting = true;

			try {
				IDbTransaction transaction = Transaction;
				if ((transaction != null && transaction.Connection != connection) ||
					(transaction == null && !connection.JdbcConnection.getAutoCommit ())) {
					throw ExceptionHelper.TransactionNotInitialized ();
				}

				Behavior = behavior;

				PrepareInternalParameters();			
				PrepareInternal();

				// For SchemaOnly there is no need for statement execution
				if (Behavior != CommandBehavior.SchemaOnly) {
					_recordsAffected = -1;

					// FIXME: this causes SP in MS Sql Server to create no mor than one row.
					if ((Behavior & CommandBehavior.SingleRow) != 0) {
						_statement.setMaxRows (1);
					}
				
					if(_statement is PreparedStatement) {
						BindParameters(InternalParameters);
						_hasResultSet = ((PreparedStatement)_statement).execute();
					}
					else {
						_hasResultSet =_statement.execute(_javaCommandText);					
					}
		
					if (!_hasResultSet) {
						int updateCount = _statement.getUpdateCount();
						if (updateCount >= 0) {
							AccumulateRecordsAffected(updateCount);
							_hasResultSet = true; //play as if we have resultset
							NextResultSet();
						}
					}					
				}
				connection.IsFetching = true;
				try {
					_currentReader = CreateReader();
				}
				catch(Exception e) {
					connection.IsFetching = false;
					throw e;
				}
				return _currentReader;
			}
			catch(SQLException e) {				
				throw CreateException(e);
			}
			finally {
				connection.IsExecuting = false;
				NullParametersInPrepare = false;
			}
		}
Ejemplo n.º 20
0
 protected AbstractDbException(string message, SQLException cause, AbstractDBConnection connection) : base(message, cause)
 {
     _connection = connection;
     _cause      = cause;
 }
		protected override AbstractDbError CreateDbError(java.sql.SQLException e, AbstractDBConnection connection) {
			return new SqlError(e, connection);
		}
Ejemplo n.º 22
0
 protected AbstractDbException(SQLException cause, AbstractDBConnection connection) : this(String.Empty, cause, connection)
 {
 }
		protected AbstractDbError(SQLException e, AbstractDBConnection connection) {
			_e = e;
			if (connection != null)
				_jdbcProvider = connection.JdbcProvider;
		}
Ejemplo n.º 24
0
		internal OleDbError(SQLException e, AbstractDBConnection connection) : base(e, connection) {
		}
Ejemplo n.º 25
0
		protected abstract AbstractDbError CreateDbError(SQLException e, AbstractDBConnection connection);
Ejemplo n.º 26
0
 protected abstract AbstractDbError CreateDbError(SQLException e, AbstractDBConnection connection);
Ejemplo n.º 27
0
        /**
         * @see System.Data.IDbTransaction#Commit()
         */
        public override void Commit()
        {
			if (_connection == null)
				return;

            try
            {
                _connection.JdbcConnection.commit();
				_connection.JdbcConnection.setAutoCommit(true);
				_connection = null;
            }
            catch (SQLException exp)
            {
                throw new SystemException(exp.Message, exp);
            }
        }
Ejemplo n.º 28
0
        /**
         * Initialize SqlError object
         * */
        internal SqlError(SQLException e, AbstractDBConnection connection) : base(e, connection)
        {
			if (connection != null)
				_serverVersion = connection.ServerVersion;
        }
Ejemplo n.º 29
0
 protected AbstractDbException(Exception cause, AbstractDBConnection connection) : base(cause.Message, cause)
 {
     _connection = connection;
 }