예제 #1
0
        public void TestCreateSelectStatementSuccessfully(bool wherePresent, bool orderByPresent, bool groupByPresent, string tableName, string expectedSelectStatement)
        {
            ViewParameters viewParams            = GetTestParameters(wherePresent, orderByPresent, groupByPresent);
            string         actualSelectStatement = SqlStatmentsGenerator.CreateSelectStatement(null, tableName, viewParams);

            Assert.Equal(expectedSelectStatement, actualSelectStatement);
        }
예제 #2
0
        public async Task <DbData> ExtractAsync(string viewName, ViewParameters parameters)
        {
            using (DbConnection connection = DbConnectionFactory.Create(_dbEngine, _connectionString))
            {
                try
                {
                    _logger.LogDebug("Extract db data async via \"View\" started");
                    DbData result = null;
                    await connection.OpenAsync().ConfigureAwait(false);

                    string cmdText = SqlStatmentsGenerator.CreateSelectStatement(SqlStatmentsGenerator.SelectAllColumns, viewName, parameters);
                    using (IDbCommand command = DbCommandFactory.Create(_dbEngine, connection, cmdText))
                    {
                        command.CommandType = CommandType.Text;
                        result = await ReadDataImplAsync((DbCommand)command);
                    }

                    connection.Close();
                    _logger.LogDebug("Extract db data async via \"View\" completed");
                    return(result);
                }
                catch (Exception e)
                {
                    _logger.LogError($"An error occured during async data extraction via \"View\", exception: {e}");
                    return(null);
                }
            }
        }
예제 #3
0
        public void TestCreateSelectStatementMultiple()
        {
            ViewParameters          parameters  = new ViewParameters();
            List <DbQueryParameter> whereParams = new List <DbQueryParameter>();

            whereParams.Add(new DbQueryParameter(null, "Age", ">", "18"));
            whereParams.Add(new DbQueryParameter(new[] { JoinCondition.And, JoinCondition.Not }, "FirstName", "IS NOT", "'John'"));
            whereParams.Add(new DbQueryParameter(new[] { JoinCondition.Or }, "LastName", "=", "'Smith'"));
            parameters.WhereParameters = whereParams;
            string expectedSelectStatement = "SELECT * FROM Person  WHERE Age > 18 AND  NOT FirstName IS NOT 'John' OR LastName = 'Smith'";
            string actualSelectStatement   = SqlStatmentsGenerator.CreateSelectStatement(null, "Person", parameters);

            Assert.Equal(expectedSelectStatement, actualSelectStatement);
        }