Beispiel #1
0
 private NrdoResult(DbDriver dbDriver, IDataReader reader, RowCounter rowCounter)
 {
     this.dbDriver   = dbDriver;
     this.reader     = reader;
     this.rowCounter = rowCounter;
     this.rowNum     = rowCounter.currentRowNum;
 }
Beispiel #2
0
        internal static IEnumerable <NrdoResult> Get(DbDriver dbDriver, IDataReader reader)
        {
            var counter = new RowCounter();

            while (reader.Read())
            {
                yield return(new NrdoResult(dbDriver, reader, counter));

                counter.advance();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Calculate a Hash for a DataView and the calculates the size of the DataView, too.
        /// </summary>
        /// <remarks><em>Do not use for creation of a password hash</em> - this Method uses the SHA1 algorithm
        /// for speed reasons but this is not deemed safe enough for password hashing! --> Use
        /// PasswordHelper.GetPasswordHash() for this instead!!!</remarks>
        /// <param name="AHashDV">The DataView to be analysed.</param>
        /// <param name="AHash">Returns the Hash value of the DataView.</param>
        /// <param name="ASize">Returns the size of the DataView.</param>
        public static void CalculateHashAndSize(DataView AHashDV, out String AHash, out Int32 ASize)
        {
            StringBuilder             HashStringBuilder;
            SHA1CryptoServiceProvider HashingProvider;
            Int32 RowCounter;
            Int32 ColumnCounter;
            Int32 TmpSize = 0;

            ASize = 0;

            /*
             * Build a string that contains all values of all rows in the DataView, using
             * a StringBuilder for efficiency.
             */
            HashStringBuilder = new StringBuilder();

            for (RowCounter = 0; RowCounter <= AHashDV.Count - 1; RowCounter += 1)
            {
                for (ColumnCounter = 0; ColumnCounter <= AHashDV.Table.Columns.Count - 1; ColumnCounter += 1)
                {
                    if (AHashDV.Table.Columns[ColumnCounter].DataType != System.Type.GetType("System.DateTime"))
                    {
                        HashStringBuilder.Append(
                            RowCounter.ToString() + '/' + ColumnCounter.ToString() + ':' + AHashDV[RowCounter][ColumnCounter].ToString());
                    }
                    else
                    {
                        HashStringBuilder.Append(RowCounter.ToString() + '/' + ColumnCounter.ToString() + ':' +
                                                 TSaveConvert.DateColumnToDate(AHashDV.Table.Columns[ColumnCounter], AHashDV[RowCounter].Row).ToString("dd-MM-yy HH:MM"));
                    }

                    // Increment the size
                    TmpSize = AHashDV[RowCounter][ColumnCounter].ToString().Length;
                    ASize   = ASize + TmpSize;
                }
            }

            /*
             * Calculate the hash of the string containing all values of all rows
             */
            HashingProvider = new SHA1CryptoServiceProvider();
            AHash           = Convert.ToBase64String(HashingProvider.ComputeHash(Encoding.UTF8.GetBytes(HashStringBuilder.ToString())));
        }
Beispiel #4
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);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Executes the query as statement.
        /// </summary>
        /// <returns>An <see cref="AceQLDataReader"/>object.</returns>
        /// <exception cref="AceQL.Client.Api.AceQLException">If any Exception occurs.</exception>
        private async Task <AceQLDataReader> ExecuteQueryAsStatementAsync()
        {
            try
            {
                IFile file = await GetUniqueResultSetFileAsync().ConfigureAwait(false);

                bool    isStoredProcedure   = (commandType == CommandType.StoredProcedure ? true : false);
                Boolean isPreparedStatement = false;
                Dictionary <string, string> parametersMap = null;

                using (Stream input = await aceQLHttpApi.ExecuteQueryAsync(cmdText, Parameters, isStoredProcedure, isPreparedStatement, parametersMap).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 ExecuteQueryAsStatementAsync().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);
                }
            }
        }
Beispiel #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();

                // 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);
                }
            }
        }