本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataReader.NextResult方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataReader.NextResult方法的具体用法?C# MySqlDataReader.NextResult怎么用?C# MySqlDataReader.NextResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlDataReader
的用法示例。
在下文中一共展示了MySqlDataReader.NextResult方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteReader
//.........这里部分代码省略.........
{
sql = "call " + sql;
}
}
// if we are on a replicated connection, we are only allow readonly statements
if (connection.Settings.Replication && !InternallyCreated)
EnsureCommandIsReadOnly(sql);
if (statement == null || !statement.IsPrepared)
{
if (CommandType == CommandType.StoredProcedure)
statement = new StoredProcedure(this, sql);
else
statement = new PreparableStatement(this, sql);
}
// stored procs are the only statement type that need do anything during resolve
statement.Resolve(false);
// Now that we have completed our resolve step, we can handle our
// command behaviors
HandleCommandBehaviors(behavior);
updatedRowCount = -1;
try
{
MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
connection.Reader = reader;
canceled = false;
// execute the statement
statement.Execute();
// wait for data to return
reader.NextResult();
success = true;
return reader;
}
catch (TimeoutException tex)
{
connection.HandleTimeoutOrThreadAbort(tex);
throw; //unreached
}
catch (ThreadAbortException taex)
{
connection.HandleTimeoutOrThreadAbort(taex);
throw;
}
catch (IOException ioex)
{
connection.Abort(); // Closes connection without returning it to the pool
throw new MySqlException(Resources.FatalErrorDuringExecute, ioex);
}
catch (MySqlException ex)
{
if (ex.InnerException is TimeoutException)
throw; // already handled
try
{
ResetReader();
ResetSqlSelectLimit();
}
catch (Exception)
{
// Reset SqlLimit did not work, connection is hosed.
示例2: ExecuteReader
/// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
public new MySqlDataReader ExecuteReader(CommandBehavior behavior)
{
// interceptors didn't handle this so we fall through
bool success = false;
CheckState();
Driver driver = connection.driver;
cmdText = cmdText.Trim();
string sql = cmdText.Trim(';');
lock (driver)
{
// We have to recheck that there is no reader, after we got the lock
if (connection.Reader != null)
{
throw (new MySqlException("Resources.DataReaderOpen"));
}
commandTimer = new CommandTimer(connection, CommandTimeout);
lastInsertedId = -1;
if (CommandType == CommandType.TableDirect)
sql = "SELECT * FROM " + sql;
else if (CommandType == CommandType.Text)
{
// validates single word statetment (maybe is a stored procedure call)
if (sql.IndexOf(" ") == -1)
{
if (AddCallStatement(sql))
sql = "call " + sql;
}
}
// if we are on a replicated connection, we are only allow readonly statements
if (connection.Settings.Replication && !InternallyCreated)
EnsureCommandIsReadOnly(sql);
if (statement == null || !statement.IsPrepared)
{
if (CommandType == CommandType.StoredProcedure)
statement = new StoredProcedure(this, sql);
else
statement = new PreparableStatement(this, sql);
}
// stored procs are the only statement type that need do anything during resolve
statement.Resolve(false);
// Now that we have completed our resolve step, we can handle our
// command behaviors
HandleCommandBehaviors(behavior);
updatedRowCount = -1;
try
{
MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
connection.Reader = reader;
canceled = false;
// execute the statement
statement.Execute();
// wait for data to return
reader.NextResult();
success = true;
return reader;
}
catch (TimeoutException tex)
{
connection.HandleTimeoutOrThreadAbort(tex);
throw; //unreached
}
catch (ThreadAbortException taex)
{
connection.HandleTimeoutOrThreadAbort(taex);
throw;
}
catch (IOException ioex)
{
connection.Abort(); // Closes connection without returning it to the pool
throw new MySqlException("Resources.FatalErrorDuringExecute", ioex);
}
catch (MySqlException ex)
{
if (ex.InnerException is TimeoutException)
throw; // already handled
try
{
ResetReader();
ResetSqlSelectLimit();
}
catch (Exception)
{
// Reset SqlLimit did not work, connection is hosed.
Connection.Abort();
throw new MySqlException(ex.Message, true, ex);
//.........这里部分代码省略.........
示例3: ExecuteReader
/// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
public new MySqlDataReader ExecuteReader (CommandBehavior behavior)
{
CheckState();
Driver driver = connection.driver;
lock (driver)
{
// We have to recheck that there is no reader, after we got the lock
if (connection.Reader != null)
{
throw new MySqlException(Resources.DataReaderOpen);
}
#if !CF
System.Transactions.Transaction curTrans = System.Transactions.Transaction.Current;
if (curTrans != null)
{
TransactionStatus status = TransactionStatus.InDoubt;
try
{
// in some cases (during state transitions) this throws
// an exception. Ignore exceptions, we're only interested
// whether transaction was aborted or not.
status = curTrans.TransactionInformation.Status;
}
catch(TransactionException)
{
}
if (status == TransactionStatus.Aborted)
throw new TransactionAbortedException();
}
#endif
commandTimer = new CommandTimer(connection, CommandTimeout);
lastInsertedId = -1;
if (cmdText == null ||
cmdText.Trim().Length == 0)
throw new InvalidOperationException(Resources.CommandTextNotInitialized);
string sql = TrimSemicolons(cmdText);
if (CommandType == CommandType.TableDirect)
sql = "SELECT * FROM " + sql;
// now we check to see if we are executing a query that is buggy
// in 4.1
connection.driver.IsExecutingBuggyQuery = false;
if (!connection.driver.Version.isAtLeast(5, 0, 0) &&
connection.driver.Version.isAtLeast(4, 1, 0))
{
string snippet = sql;
if (snippet.Length > 17)
snippet = sql.Substring(0, 17);
snippet = snippet.ToUpper(CultureInfo.InvariantCulture);
connection.driver.IsExecutingBuggyQuery =
snippet.StartsWith("DESCRIBE") ||
snippet.StartsWith("SHOW TABLE STATUS");
}
if (statement == null || !statement.IsPrepared)
{
if (CommandType == CommandType.StoredProcedure)
statement = new StoredProcedure(this, sql);
else
statement = new PreparableStatement(this, sql);
}
// stored procs are the only statement type that need do anything during resolve
statement.Resolve(false);
// Now that we have completed our resolve step, we can handle our
// command behaviors
HandleCommandBehaviors(behavior);
updatedRowCount = -1;
try
{
MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
connection.Reader = reader;
// execute the statement
statement.Execute();
// wait for data to return
reader.NextResult();
return reader;
}
catch (TimeoutException tex)
{
connection.HandleTimeout(tex);
return null;
}
catch (MySqlException ex)
{
connection.Reader = null;
if (ex.InnerException is TimeoutException)
throw ex; // already handled
try
{
//.........这里部分代码省略.........
示例4: ExecuteReader
/// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
public new MySqlDataReader ExecuteReader(CommandBehavior behavior)
{
lastInsertedId = -1;
CheckState();
if (cmdText == null ||
cmdText.Trim().Length == 0)
throw new InvalidOperationException(Resources.CommandTextNotInitialized);
string sql = TrimSemicolons(cmdText);
// now we check to see if we are executing a query that is buggy
// in 4.1
connection.IsExecutingBuggyQuery = false;
if (!connection.driver.Version.isAtLeast(5, 0, 0) &&
connection.driver.Version.isAtLeast(4, 1, 0))
{
string snippet = sql;
if (snippet.Length > 17)
snippet = sql.Substring(0, 17);
snippet = snippet.ToLower(CultureInfo.InvariantCulture);
connection.IsExecutingBuggyQuery =
snippet.StartsWith("describe") ||
snippet.StartsWith("show table status");
}
if (statement == null || !statement.IsPrepared)
{
if (CommandType == CommandType.StoredProcedure)
statement = new StoredProcedure(this, sql);
else
statement = new PreparableStatement(this, sql);
}
// stored procs are the only statement type that need do anything during resolve
statement.Resolve();
// Now that we have completed our resolve step, we can handle our
// command behaviors
HandleCommandBehaviors(behavior);
updatedRowCount = -1;
Timer timer = null;
try
{
MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
// start a threading timer on our command timeout
timedOut = false;
canceled = false;
// execute the statement
statement.Execute();
// start a timeout timer
if (connection.driver.Version.isAtLeast(5, 0, 0) &&
commandTimeout > 0)
{
TimerCallback timerDelegate =
new TimerCallback(TimeoutExpired);
timer = new Timer(timerDelegate, this, this.CommandTimeout * 1000, Timeout.Infinite);
}
// wait for data to return
reader.NextResult();
connection.Reader = reader;
return reader;
}
catch (MySqlException ex)
{
// if we caught an exception because of a cancel, then just return null
if (ex.Number == 1317)
{
if (TimedOut)
throw new MySqlException(Resources.Timeout);
return null;
}
if (ex.IsFatal)
Connection.Close();
if (ex.Number == 0)
throw new MySqlException(Resources.FatalErrorDuringExecute, ex);
throw;
}
finally
{
if (timer != null)
timer.Dispose();
}
}
示例5: ExecuteReader
/// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
public new MySqlDataReader ExecuteReader (CommandBehavior behavior)
{
bool success = false;
CheckState();
Driver driver = connection.driver;
lock (driver)
{
// We have to recheck that there is no reader, after we got the lock
if (connection.Reader != null)
{
throw new MySqlException(Resources.DataReaderOpen);
}
#if !CF
System.Transactions.Transaction curTrans = System.Transactions.Transaction.Current;
if (curTrans != null)
{
bool inRollback = false;
if (driver.CurrentTransaction!= null)
inRollback = driver.CurrentTransaction.InRollback;
if (!inRollback)
{
TransactionStatus status = TransactionStatus.InDoubt;
try
{
// in some cases (during state transitions) this throws
// an exception. Ignore exceptions, we're only interested
// whether transaction was aborted or not.
status = curTrans.TransactionInformation.Status;
}
catch (TransactionException)
{
}
if (status == TransactionStatus.Aborted)
throw new TransactionAbortedException();
}
}
#endif
commandTimer = new CommandTimer(connection, CommandTimeout);
lastInsertedId = -1;
cmdText = cmdText.Trim();
if (String.IsNullOrEmpty(cmdText))
throw new InvalidOperationException(Resources.CommandTextNotInitialized);
string sql = cmdText.Trim(';');
if (CommandType == CommandType.TableDirect)
sql = "SELECT * FROM " + sql;
if (statement == null || !statement.IsPrepared)
{
if (CommandType == CommandType.StoredProcedure)
statement = new StoredProcedure(this, sql);
else
statement = new PreparableStatement(this, sql);
}
// stored procs are the only statement type that need do anything during resolve
statement.Resolve(false);
// Now that we have completed our resolve step, we can handle our
// command behaviors
HandleCommandBehaviors(behavior);
updatedRowCount = -1;
try
{
MySqlDataReader reader = new MySqlDataReader(this, statement, behavior);
connection.Reader = reader;
canceled = false;
// execute the statement
statement.Execute();
// wait for data to return
reader.NextResult();
success = true;
return reader;
}
catch (TimeoutException tex)
{
connection.HandleTimeoutOrThreadAbort(tex);
throw; //unreached
}
catch (ThreadAbortException taex)
{
connection.HandleTimeoutOrThreadAbort(taex);
throw;
}
catch (IOException ioex)
{
connection.Abort(); // Closes connection without returning it to the pool
throw new MySqlException(Resources.FatalErrorDuringExecute, ioex);
}
catch (MySqlException ex)
{
if (ex.InnerException is TimeoutException)
throw; // already handled
//.........这里部分代码省略.........
示例6: ConvertReaderToMultipleResultSet
private List<ResultSet> ConvertReaderToMultipleResultSet(MySqlDataReader reader)
{
var resultSets = new List<ResultSet>();
do {
var resultSet = new ResultSet();
resultSet.Columns = GetColumns(reader);
resultSet.Rows = GetRows(reader);
resultSets.Add(resultSet);
} while (reader.NextResult());
return resultSets;
}