From 121b1eb497d62afb995a083a6a872545cedbca75 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 29 Jun 2024 18:55:11 +0800 Subject: [PATCH] Update odbc --- .../GBase/SqlBuilder/GBaseQueryBuilder.cs | 14 +++++++++++++- Src/Asp.NetCore2/SqlSugar.OdbcCore/OdbcConfig.cs | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Src/Asp.NetCore2/SqlSugar.OdbcCore/GBase/SqlBuilder/GBaseQueryBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OdbcCore/GBase/SqlBuilder/GBaseQueryBuilder.cs index 68eec6ecc..e482f7fab 100644 --- a/Src/Asp.NetCore2/SqlSugar.OdbcCore/GBase/SqlBuilder/GBaseQueryBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar.OdbcCore/GBase/SqlBuilder/GBaseQueryBuilder.cs @@ -61,8 +61,20 @@ namespace SqlSugar.Odbc this.OrderByValue = null; } if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0]; - if (this.Context.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer) + if (OdbcConfig.IsCompatibleWithOldDatabaseVersion&&this.Context.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer) { + //SqlServer2008 + var orderby = GetOrderByString; + if (string.IsNullOrEmpty(orderby)) + { + orderby = "ORDER BY GETDATE()"; + } + var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", orderby); + result = string.Format("SELECT * FROM ( SELECT {0}{7} FROM {1} {2} {3} {4} ) t WHERE t.RowIndex BETWEEN {5} AND {6}", GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, null, Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt(),rowNumberString); + } + else if (this.Context.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.SqlServer) + { + //SqlServer2012+ var orderby = GetOrderByString; if (string.IsNullOrEmpty(orderby)) { diff --git a/Src/Asp.NetCore2/SqlSugar.OdbcCore/OdbcConfig.cs b/Src/Asp.NetCore2/SqlSugar.OdbcCore/OdbcConfig.cs index 4f384e9de..81743efd8 100644 --- a/Src/Asp.NetCore2/SqlSugar.OdbcCore/OdbcConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar.OdbcCore/OdbcConfig.cs @@ -8,5 +8,6 @@ namespace SqlSugar.Odbc { public static string SqlTranslationLeft =""; public static string SqlTranslationRight=""; + public static bool IsCompatibleWithOldDatabaseVersion = false; } }