Make @@ROWCOUNT connection global.

pull/48/head
Lau 6 years ago
parent 1066d34e5b
commit e0db14ee1f

@ -16,7 +16,6 @@ namespace System.Data.Jet
private JetTransaction _transaction;
private Guid? _lastGuid;
private int? _rowCount;
private static readonly Regex _createProcedureExpression = new Regex(@"^\s*create\s*procedure\b", RegexOptions.IgnoreCase);
private static readonly Regex _topParameterRegularExpression = new Regex(@"(?<=(?:^|\s)select\s+top\s+)(?:@\w+|\?)(?=\s)", RegexOptions.IgnoreCase);
@ -213,7 +212,7 @@ namespace System.Data.Jet
dataReader = new JetDataReader(InnerCommand.ExecuteReader(behavior));
_rowCount = dataReader.RecordsAffected;
_connection.RowCount = dataReader.RecordsAffected;
}
return dataReader;
@ -261,11 +260,7 @@ namespace System.Data.Jet
if (_selectRowCountRegularExpression.Match(InnerCommand.CommandText)
.Success)
{
// TODO: Fix exception message.
if (_rowCount == null)
throw new InvalidOperationException("Invalid " + InnerCommand.CommandText + ". Run a DataReader before.");
return _rowCount.Value;
return _connection.RowCount;
}
InnerCommand.CommandText = ParseIdentity(InnerCommand.CommandText);
@ -279,9 +274,7 @@ namespace System.Data.Jet
InlineTopParameters();
FixParameters();
_rowCount = InnerCommand.ExecuteNonQuery();
return _rowCount.Value;
return _connection.RowCount = InnerCommand.ExecuteNonQuery();
}
/// <summary>
@ -401,12 +394,9 @@ namespace System.Data.Jet
if (_selectRowCountRegularExpression.Match(commandText)
.Success)
{
if (_rowCount == null)
throw new InvalidOperationException("Invalid " + commandText + ". Run a DataReader before.");
var dataTable = new DataTable("Rowcount");
dataTable.Columns.Add("ROWCOUNT", typeof(int));
dataTable.Rows.Add(_rowCount.Value);
dataTable.Rows.Add(_connection.RowCount);
return new DataTableReader(dataTable);
}

@ -18,6 +18,8 @@ namespace System.Data.Jet
internal DbConnection InnerConnection { get; private set; }
internal JetTransaction ActiveTransaction { get; set; }
internal int RowCount { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="JetConnection"/> class.
@ -371,6 +373,7 @@ namespace System.Data.Jet
JetFactory.InnerFactory);
InnerConnection.StateChange += WrappedConnection_StateChange;
RowCount = 0;
_state = ConnectionState.Open;
OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
}

Loading…
Cancel
Save