/// <summary> /// Executes the database data reader. /// </summary> /// <param name="behavior">The behavior.</param> /// <returns></returns> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (Connection == null) { throw new InvalidOperationException(Messages.PropertyNotInitialized(nameof(Connection))); } if (Connection.State != ConnectionState.Open) { throw new InvalidOperationException(Messages.CannotCallMethodInThisConnectionState("ExecuteReader", ConnectionState.Open, Connection.State)); } _WrappedCommand.Connection = _Connection.InnerConnection; _WrappedCommand.Transaction = _Transaction == null ? null : _Transaction.WrappedTransaction; LogHelper.ShowCommandText("ExecuteDbDataReader", _WrappedCommand); DbDataReader dataReader; if (JetStoreSchemaDefinitionRetrieve.TryGetDataReaderFromShowCommand(_WrappedCommand, out dataReader)) { // Retrieve of store schema definition return(dataReader); } if (_WrappedCommand.CommandType != CommandType.Text) { return(new JetDataReader(_WrappedCommand.ExecuteReader(behavior))); } string[] commandTextList = SplitCommands(_WrappedCommand.CommandText); dataReader = null; for (int i = 0; i < commandTextList.Length; i++) { string commandText = commandTextList[i]; if ((dataReader = TryGetDataReaderForSelectRowCount(commandText)) != null) { continue; } commandText = ParseIdentity(commandText); commandText = ParseGuid(commandText); dataReader = InternalExecuteDbDataReader(commandText, behavior); } return(dataReader); }
/// <summary> /// Executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored /// </summary> /// <returns></returns> public override object ExecuteScalar() { if (Connection == null) { throw new InvalidOperationException(Messages.PropertyNotInitialized(nameof(Connection))); } if (Connection.State != ConnectionState.Open) { throw new InvalidOperationException(Messages.CannotCallMethodInThisConnectionState(nameof(ExecuteScalar), ConnectionState.Open, Connection.State)); } _WrappedCommand.Connection = _Connection.InnerConnection; _WrappedCommand.Transaction = _Transaction == null ? null : _Transaction.WrappedTransaction; LogHelper.ShowCommandText("ExecuteScalar", _WrappedCommand); DbDataReader dataReader; if (JetStoreSchemaDefinitionRetrieve.TryGetDataReaderFromShowCommand(_WrappedCommand, out dataReader)) { // Retrieve of store schema definition if (dataReader.HasRows) { dataReader.Read(); return(dataReader[0]); } else { return(DBNull.Value); } } return(this._WrappedCommand.ExecuteScalar()); }