本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommand.ExecuteHasRows方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommand.ExecuteHasRows方法的具体用法?C# MySqlCommand.ExecuteHasRows怎么用?C# MySqlCommand.ExecuteHasRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlCommand
的用法示例。
在下文中一共展示了MySqlCommand.ExecuteHasRows方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteHasRows
public static bool ExecuteHasRows(this MySqlConnection dbConnection, string commandString, string parameterName1, object parameterValue1, string parameterName2, object parameterValue2)
{
MySqlCommand command = new MySqlCommand(commandString, dbConnection);
command.Parameters.AddWithValue(parameterName1, parameterValue1);
command.Parameters.AddWithValue(parameterName2, parameterValue2);
return command.ExecuteHasRows();
}
示例2: GetSignatureResponseStatus
/// <summary>
/// Get the status and perhaps response regarding as signature request.
/// </summary>
/// <param name="certificateId">Id of the certificate.</param>
/// <param name="signatureResponse">Signed signature response.</param>
/// <returns>Status of the signature response.</returns>
public SignatureResponseStatus GetSignatureResponseStatus(Guid certificateId, out Signed<SignatureResponse> signatureResponse)
{
MySqlCommand selectResponseCommand = new MySqlCommand("SELECT Value FROM signatureresponse WHERE Id = @Id", DbConnection);
selectResponseCommand.Parameters.AddWithValue("@Id", certificateId.ToByteArray());
MySqlDataReader selectResponseReader = selectResponseCommand.ExecuteReader();
if (selectResponseReader.Read())
{
byte[] signatureResponseData = selectResponseReader.GetBlob(0);
selectResponseReader.Close();
signatureResponse = Serializable.FromBinary<Signed<SignatureResponse>>(signatureResponseData);
return signatureResponse.Value.Status;
}
else
{
selectResponseReader.Close();
MySqlCommand selectRequestCommand = new MySqlCommand("SELECT count(*) FROM signaturerequest WHERE Id = @Id", DbConnection);
selectRequestCommand.Parameters.AddWithValue("@Id", certificateId.ToByteArray());
if (selectRequestCommand.ExecuteHasRows())
{
signatureResponse = null;
return SignatureResponseStatus.Pending;
}
else
{
signatureResponse = null;
return SignatureResponseStatus.Unknown;
}
}
}
示例3: AddAuthority
/// <summary>
/// Add an authority.
/// </summary>
/// <param name="certificate">Authority to be added.</param>
/// <returns>Index of the authority.</returns>
public int AddAuthority(
IRpcConnection connection,
Certificate certificate)
{
if (certificate == null)
throw new ArgumentNullException("certificate");
if (certificate.Validate(this.certificateStorage) != CertificateValidationResult.Valid)
throw new PiSecurityException(ExceptionCode.InvalidCertificate, "Authority certificate not valid.");
if (!(certificate is AuthorityCertificate))
throw new PiSecurityException(ExceptionCode.NoAuthorizedAuthority, "No an authority certificate.");
MySqlTransaction transaction = DbConnection.BeginTransaction();
MySqlCommand countCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
countCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
if ((long)countCommand.ExecuteScalar() >= this.parameters.AuthorityCount)
throw new PiArgumentException(ExceptionCode.AlreadyEnoughAuthorities, "Already enough authorities.");
MySqlCommand addedCommand = new MySqlCommand("SELECT count(*) FROM authority WHERE VotingId = @VotingId AND AuthorityId = @AuthorityId", DbConnection, transaction);
addedCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
addedCommand.Add("@AuthorityId", certificate.Id.ToByteArray());
if (addedCommand.ExecuteHasRows())
throw new PiArgumentException(ExceptionCode.AuthorityAlreadyInVoting, "Already an authority of the voting.");
MySqlCommand indexCommand = new MySqlCommand("SELECT max(AuthorityIndex) + 1 FROM authority WHERE VotingId = @VotingId", DbConnection, transaction);
indexCommand.Add("@VotingId", this.parameters.VotingId.ToByteArray());
object authorityIndexNull = indexCommand.ExecuteScalar();
int authorityIndex = authorityIndexNull == DBNull.Value ? 1 : Convert.ToInt32((long)authorityIndexNull);
MySqlCommand insertCommand = new MySqlCommand("INSERT INTO authority (VotingId, AuthorityIndex, AuthorityId, Certificate) VALUES (@VotingId, @AuthorityIndex, @AuthorityId, @Certificate)", DbConnection, transaction);
insertCommand.Parameters.AddWithValue("@VotingId", this.parameters.VotingId.ToByteArray());
insertCommand.Parameters.AddWithValue("@AuthorityIndex", authorityIndex);
insertCommand.Parameters.AddWithValue("@AuthorityId", certificate.Id.ToByteArray());
insertCommand.Parameters.AddWithValue("@Certificate", certificate.ToBinary());
insertCommand.ExecuteNonQuery();
Logger.Log(LogLevel.Info, "Connection {0}: Authority id {1} added to voting id {2}", connection.Id, certificate.Id.ToString(), Id.ToString());
transaction.Commit();
return authorityIndex;
}