/// <summary> /// Executes the query as prepared statement. /// </summary> /// <returns>An <see cref="AceQLDataReader"/> object.</returns> /// <exception cref="AceQL.Client.Api.AceQLException">If any Exception occurs.</exception> private async Task <AceQLDataReader> ExecuteQueryAsPreparedStatementAsync() { try { AceQLCommandUtil aceQLCommandUtil = new AceQLCommandUtil(cmdText, Parameters); // Get the parameters and build the result set Dictionary <string, string> statementParameters = aceQLCommandUtil.GetPreparedStatementParameters(); foreach (string key in statementParameters.Keys) { Debug("key:==> " + key + " / " + statementParameters[key]); } // Replace all @parms with ? in sql command cmdText = aceQLCommandUtil.ReplaceParmsWithQuestionMarks(); IFile file = await GetUniqueResultSetFileAsync().ConfigureAwait(false); bool isStoredProcedure = (commandType == CommandType.StoredProcedure ? true : false); bool isPreparedStatement = true; using (Stream input = await aceQLHttpApi.ExecuteQueryAsync(cmdText, Parameters, isStoredProcedure, isPreparedStatement, statementParameters).ConfigureAwait(false)) { try { await CopyHttpStreamToFile(file, input).ConfigureAwait(false); } catch (Exception exception) { if (this.connection.RequestRetry && (this.executeQueryRetryCount < 1 || exception.Message.Contains("GZip"))) { this.executeQueryRetryCount++; Boolean saveGzipResultValue = this.aceQLHttpApi.GzipResult; this.aceQLHttpApi.GzipResult = false; AceQLDataReader dataReader = await ExecuteQueryAsPreparedStatementAsync().ConfigureAwait(false); this.aceQLHttpApi.GzipResult = saveGzipResultValue; return(dataReader); } else { throw; } } } this.executeQueryRetryCount = 0; StreamResultAnalyzer streamResultAnalyzer = new StreamResultAnalyzer(file, aceQLHttpApi.HttpStatusCode); if (!await streamResultAnalyzer.IsStatusOkAsync().ConfigureAwait(false)) { throw new AceQLException(streamResultAnalyzer.GetErrorMessage(), streamResultAnalyzer.GetErrorType(), streamResultAnalyzer.GetStackTrace(), aceQLHttpApi.HttpStatusCode); } int rowsCount = 0; using (Stream readStreamCout = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { RowCounter rowCounter = new RowCounter(readStreamCout); rowsCount = rowCounter.Count(); } if (isStoredProcedure) { using (Stream readStreamOutParms = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { UpdateOutParametersValues(readStreamOutParms, Parameters); } } Stream readStream = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false); AceQLDataReader aceQLDataReader = new AceQLDataReader(file, readStream, rowsCount, connection); return(aceQLDataReader); } catch (Exception exception) { await simpleTracer.TraceAsync(exception.ToString()).ConfigureAwait(false); if (exception.GetType() == typeof(AceQLException)) { throw; } else { throw new AceQLException(exception.Message, 0, exception, aceQLHttpApi.HttpStatusCode); } } }
/// <summary> /// Executes the update as prepared statement. /// </summary> /// <returns>System.Int32.</returns> /// <exception cref="AceQLException"> /// </exception> private async Task <int> ExecuteUpdateAsPreparedStatementAsync() { try { AceQLCommandUtil aceQLCommandUtil = new AceQLCommandUtil(cmdText, Parameters); // Get the parameters and build the result set Dictionary <string, string> statementParameters = aceQLCommandUtil.GetPreparedStatementParameters(); // Uploads Blobs List <string> blobIds = aceQLCommandUtil.BlobIds; List <Stream> blobStreams = aceQLCommandUtil.BlobStreams; List <long> blobLengths = aceQLCommandUtil.BlobLengths; long totalLength = 0; for (int i = 0; i < blobIds.Count; i++) { totalLength += blobLengths[i]; } for (int i = 0; i < blobIds.Count; i++) { await aceQLHttpApi.BlobUploadAsync(blobIds[i], blobStreams[i], totalLength).ConfigureAwait(false); } // Replace all @parms with ? in sql command cmdText = aceQLCommandUtil.ReplaceParmsWithQuestionMarks(); Dictionary <string, string> parametersMap = new Dictionary <string, string> { { "sql", cmdText }, { "prepared_statement", "true" } }; List <string> keyList = new List <string>(statementParameters.Keys); foreach (string key in keyList) { parametersMap.Add(key, statementParameters[key]); } bool isStoredProcedure = (commandType == CommandType.StoredProcedure ? true : false); bool isPreparedStatement = true; int result = await aceQLHttpApi.ExecuteUpdateAsync(cmdText, Parameters, isStoredProcedure, isPreparedStatement, statementParameters).ConfigureAwait(false); return(result); } catch (Exception exception) { await simpleTracer.TraceAsync(exception.ToString()).ConfigureAwait(false); if (exception.GetType() == typeof(AceQLException)) { throw; } else { throw new AceQLException(exception.Message, 0, exception, aceQLHttpApi.HttpStatusCode); } } }
/// <summary> /// Executes the query as prepared statement. /// </summary> /// <returns>An <see cref="AceQLDataReader"/> object.</returns> /// <exception cref="AceQL.Client.Api.AceQLException">If any Exception occurs.</exception> private async Task <AceQLDataReader> ExecuteQueryAsPreparedStatementAsync() { try { AceQLCommandUtil aceQLCommandUtil = new AceQLCommandUtil(cmdText, Parameters); // Get the parameters and build the result set Dictionary <string, string> statementParameters = aceQLCommandUtil.GetPreparedStatementParameters(); // Replace all @parms with ? in sql command cmdText = aceQLCommandUtil.ReplaceParmsWithQuestionMarks(); IFile file = await GetUniqueResultSetFileAsync().ConfigureAwait(false); bool isStoredProcedure = (commandType == CommandType.StoredProcedure ? true : false); bool isPreparedStatement = true; using (Stream input = await aceQLHttpApi.ExecuteQueryAsync(cmdText, Parameters, isStoredProcedure, isPreparedStatement, statementParameters).ConfigureAwait(false)) { if (input != null) { if (aceQLHttpApi.GzipResult) { using (GZipStream decompressionStream = new GZipStream(input, CompressionMode.Decompress)) { using (var stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite).ConfigureAwait(false)) { decompressionStream.CopyTo(stream); } } } else { using (var stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite).ConfigureAwait(false)) { input.CopyTo(stream); } } } } StreamResultAnalyzer streamResultAnalyzer = new StreamResultAnalyzer(file, aceQLHttpApi.HttpStatusCode); if (!await streamResultAnalyzer.IsStatusOkAsync().ConfigureAwait(false)) { throw new AceQLException(streamResultAnalyzer.GetErrorMessage(), streamResultAnalyzer.GetErrorType(), streamResultAnalyzer.GetStackTrace(), aceQLHttpApi.HttpStatusCode); } int rowsCount = 0; using (Stream readStreamCout = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { RowCounter rowCounter = new RowCounter(readStreamCout); rowsCount = rowCounter.Count(); } if (isStoredProcedure) { using (Stream readStreamOutParms = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { UpdateOutParametersValues(readStreamOutParms, Parameters); } } Stream readStream = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false); AceQLDataReader aceQLDataReader = new AceQLDataReader(file, readStream, rowsCount, connection); return(aceQLDataReader); } catch (Exception exception) { await simpleTracer.TraceAsync(exception.ToString()).ConfigureAwait(false); if (exception.GetType() == typeof(AceQLException)) { throw exception; } else { throw new AceQLException(exception.Message, 0, exception, aceQLHttpApi.HttpStatusCode); } } }