public void TestOraclePage1() { var sql = "select id,a.name as fullname,a.city address from person a order by a.name"; var parser = new OracleParser(); var result = parser.ParserPage(sql, 1, 10); Assert.Equal("select * from (select row_number() over (order by fullname) pageNo, sbInner.* FROM (select id,a.name as fullname,a.city address from person a order by a.name) sbInner) sbOuter where pageNo > :sbPageSkip and pageNo <= :sbPageSkip + :sbPageSize", result.PageSql); Assert.Equal("select count(1) from (select id,a.name as fullname,a.city address from person a order by a.name) sbCount", result.CountSql); Assert.Equal(2, result.SqlParameters.Count); Assert.Equal(10, result.SqlParameters.FirstOrDefault(it => it.ParameterName == "sbPageSize")?.Value); Assert.Equal(0, result.SqlParameters.FirstOrDefault(it => it.ParameterName == "sbPageSkip")?.Value); }
public Class ClassFromScript(string script) { var results = new List <Class>(); MsSqlParser msSqlParser = new MsSqlParser(); results.Add(msSqlParser.ClassFromScript(script)); OracleParser oracleParser = new OracleParser(); results.Add(oracleParser.ClassFromScript(script)); ClassParser classParser = new ClassParser(); results.Add(classParser.ClassFromScript(script)); return(results .Where(c => !string.IsNullOrEmpty(c.Name)) .OrderByDescending(c => c.Properties?.Count()) .FirstOrDefault()); }
public Page <T> PageBaseExecute <T>(MethodInfo method, object[] args, IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; Init(); //处理select逻辑 var selectAttribute = method.GetCustomAttribute <SelectAttribute>(); if (selectAttribute != null) { var repositoryOption = serviceProvider.GetService <RepositoryOption>(); //获得动态参数 var dbArgs = GetParameters(method, args); if (pageable == null) { throw new Exception("method argument must have pageable"); } OpenDb(); var sql = selectAttribute.Sql; if (!sql.Contains("order by", StringComparison.OrdinalIgnoreCase)) { throw new NotSupportedException("sql must contain order by clause"); } sql = ReplaceSqlBindWhereCondition(sql); var result = new Page <T>() { }; SqlParser.SqlParser parser; if (repositoryOption.IsOracle) { parser = new OracleParser(); } else if (repositoryOption.IsSqlServer) { parser = new SqlServerParser(); } else if (repositoryOption.IsMysql) { parser = new MysqlParser(); } else { parser = new SqliteParser(); } var parseResult = parser.ParserPage(sql, pageable.PageNumber, pageable.PageSize); ChangeDynamicParameters(parseResult.SqlParameters, dbArgs); var count = dbConnection.QueryFirst <int>(parseResult.CountSql, dbArgs, transaction: dbTransaction); var resultList = dbConnection.Query <T>(parseResult.PageSql, dbArgs, transaction: dbTransaction).ToList(); result.TotalPages = count; result.Data = resultList; result.PageSize = pageable.PageSize; result.PageNumber = pageable.PageNumber; CloseDb(); return(result); } throw new Exception("can not process method name:" + method.Name); }