示例#1
0
        /// <summary>
        /// This request is used as short-hand to create a Statement and execute a batch of updates against that Statement.
        /// </summary>
        public async Task <ExecuteBatchResponse> PrepareAndExecuteBatchRequestAsync(string connectionId, uint statementId, pbc::RepeatedField <string> sqlCommands)
        {
            PrepareAndExecuteBatchRequest req = new PrepareAndExecuteBatchRequest
            {
                ConnectionId = connectionId,
                StatementId  = statementId
            };

            req.SqlCommands.AddRange(sqlCommands);

            WireMessage msg = new WireMessage
            {
                Name           = Constants.WireMessagePrefix + "PrepareAndExecuteBatchRequest",
                WrappedMessage = req.ToByteString()
            };

            using (Response webResponse = await PostRequestAsync(msg.ToByteArray()))
            {
                if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK)
                {
                    WireMessage   output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ErrorResponse res    = ErrorResponse.Parser.ParseFrom(output.WrappedMessage);
                    throw new WebException(
                              string.Format(
                                  "PrepareAndExecuteBatchRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}",
                                  connectionId,
                                  webResponse.WebResponse.StatusCode,
                                  res.ToString()));
                }
                else
                {
                    WireMessage          output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ExecuteBatchResponse res    = ExecuteBatchResponse.Parser.ParseFrom(output.WrappedMessage);
                    return(res);
                }
            }
        }
        /// <summary>
        /// This request is used as short-hand to create a Statement and execute a batch of updates against that Statement.
        /// </summary>
        public async Task<ExecuteBatchResponse> PrepareAndExecuteBatchRequestAsync(string connectionId, uint statementId, pbc::RepeatedField<string> sqlCommands, RequestOptions options)
        {
            PrepareAndExecuteBatchRequest req = new PrepareAndExecuteBatchRequest
            {
                ConnectionId = connectionId,
                StatementId = statementId,
                SqlCommands = sqlCommands
            };

            WireMessage msg = new WireMessage
            {
                Name = Constants.WireMessagePrefix + "PrepareAndExecuteBatchRequest",
                WrappedMessage = req.ToByteString()
            };

            using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options))
            {
                if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK)
                {
                    WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage);
                    throw new WebException(
                        string.Format(
                            "PrepareAndExecuteBatchRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}",
                            connectionId,
                            webResponse.WebResponse.StatusCode,
                            res.ToString()));
                }
                else
                {
                    WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ExecuteBatchResponse res = ExecuteBatchResponse.Parser.ParseFrom(output.WrappedMessage);
                    return res;
                }
            }
        }