private IResult ExecuteQuery(DatabaseBase database, Transaction transaction) { if (database == null) { throw new NullReferenceException("database cannot be null"); } if (transaction != null && transaction.Database != database) { throw new ArgumentException("transaction is using a different database connection than database."); } DbConnection dbConnection = null; string pSql = string.Empty; DateTime? pStart = new DateTime?(); DateTime? pEnd = new DateTime?(); IsolationLevel pIsolationLevel = IsolationLevel.Unspecified; try { dbConnection = transaction != null?transaction.GetOrSetConnection(database) : database.GetConnection(true); } catch (Exception e) { throw new CooqDataException.DataAccessException("Cannot open connection." + e.Message, e); } try { using (DbCommand command = Transaction.CreateCommand(dbConnection, transaction)) { Parameters parameters = !this.mUseParameters.HasValue ? (!Settings.UseParameters ? (Parameters)null : new Parameters(command)) : (this.mUseParameters.Value ? new Parameters(command) : (Parameters)null); pSql = this.GetSql(database, parameters); command.CommandText = pSql; command.CommandType = CommandType.Text; command.CommandTimeout = this.mTimeout.HasValue ? this.mTimeout.Value : Settings.DefaultTimeout; if (transaction != null) { command.Transaction = transaction.GetOrSetDbTransaction(database); } if (command.Transaction != null) { pIsolationLevel = command.Transaction.IsolationLevel; } pStart = new DateTime?(DateTime.Now); Settings.FireQueryExecutingEvent(database, pSql, QueryType.Select, pStart, pIsolationLevel, transaction != null ? new ulong?(transaction.Id) : new ulong?()); using (DbDataReader dataReader = command.ExecuteReader()) { pEnd = new DateTime?(DateTime.Now); QueryResult queryResult = new QueryResult(database, (IList <ISelectable>) this.mColumns, dataReader, command.CommandText); if (transaction == null) { dbConnection.Close(); } Settings.FireQueryPerformedEvent(database, pSql, queryResult.Count, QueryType.Select, pStart, pEnd, (Exception)null, pIsolationLevel, (IResult)queryResult, transaction != null ? new ulong?(transaction.Id) : new ulong?()); return((IResult)queryResult); } } } catch (Exception ex) { if (dbConnection != null && dbConnection.State != ConnectionState.Closed) { dbConnection.Close(); } Settings.FireQueryPerformedEvent(database, pSql, 0, QueryType.Select, pStart, pEnd, ex, pIsolationLevel, (IResult)null, transaction != null ? new ulong?(transaction.Id) : new ulong?()); throw new CooqDataException.DataAccessException("Error while executing." + ex.Message, ex); } }
public DbTable GetTable(DatabaseBase database, TableBase table) { IList <DbTable> tables = GetDbTables(table.Name, database.GetConnection(false)); return(tables.Count > 0 ? tables[0] : (DbTable)null); }
public DbTable GetTable(DatabaseBase database, TableBase table) { IList <DbTable> tables = PostgresSchemaProvider.GetDbTables(table.Name, database.GetConnection(false)); return(tables.Count > 0 ? tables[0] : null); }