Example #1
0
        /// <summary>
        /// Gets the name of the trace file.
        /// </summary>
        /// <returns>The name name fo the trace file</returns>
        internal async Task <String> GetTraceFileName()
        {
            if (file == null)
            {
                file = await AceQLCommandUtil.GetTraceFileAsync().ConfigureAwait(false);
            }

            return(file.Name);
        }
Example #2
0
        /// <summary>
        /// Gets the name of the trace filePath.
        /// </summary>
        /// <returns>The name name fo the trace filePath</returns>
        internal string GetTraceFileName()
        {
            if (filePath == null)
            {
                filePath = AceQLCommandUtil.GetTraceFile();
            }

            return(filePath);
        }
Example #3
0
 /// <summary>
 /// Traces the specified string.
 /// </summary>
 /// <param name="contents">The string to trace</param>
 internal async Task TraceAsync(String contents)
 {
     if (traceOn)
     {
         if (file == null)
         {
             file = await AceQLCommandUtil.GetTraceFileAsync().ConfigureAwait(false);
         }
         contents = DateTime.Now + " " + contents;
         await PortableFile.AppendAllTextAsync(file, "\r\n" + contents).ConfigureAwait(false);
     }
 }
Example #4
0
 /// <summary>
 /// Traces the specified string.
 /// </summary>
 /// <param name="contents">The string to trace</param>
 internal void Trace(String contents)
 {
     if (traceOn)
     {
         if (filePath == null)
         {
             AceQLCommandUtil.GetTraceFile();
         }
         contents = DateTime.Now + " " + contents;
         using (StreamWriter sw = File.AppendText(filePath))
         {
             sw.WriteLine(contents);
         }
     }
 }
Example #5
0
        /// <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);
                }
            }
        }
Example #6
0
        /// <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);
                }
            }
        }
Example #7
0
        /// <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);
                }
            }
        }