当前位置: 首页>>代码示例>>C#>>正文


C# MySqlCommand.ExecuteHasRows方法代码示例

本文整理汇总了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();
 }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:7,代码来源:MySqlExtensions.cs

示例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;
            }
              }
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:38,代码来源:VotingRpcServer.cs

示例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;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:47,代码来源:VotingServerEntity.cs


注:本文中的MySql.Data.MySqlClient.MySqlCommand.ExecuteHasRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。