From 74142741109c32180f2e73c18e5ba1d202d76ff1 Mon Sep 17 00:00:00 2001 From: hujy Date: Sat, 27 Apr 2019 18:07:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Maction=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQL/SqlFormat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/SqlFormat.cs b/SQL/SqlFormat.cs index 3fe5d33c..2db23457 100644 --- a/SQL/SqlFormat.cs +++ b/SQL/SqlFormat.cs @@ -147,7 +147,7 @@ internal static string BuildSqlWithWhereOneEqualsTow(string tableName) { //分成两半 string partA = "", partB = "";//分成两半是为了兼容子查询语句 - int fromIndex = tableName.Replace("\n", " ").Replace("\r", " ").LastIndexOf(" from "); + int fromIndex = tableName.Replace("\n", " ").Replace("\r", " ").ToLower().LastIndexOf(" from "); if (fromIndex > -1) { partA = tableName.Substring(0, fromIndex); From d00adb7ea33d91695fa30693453adcb9bc944ae5 Mon Sep 17 00:00:00 2001 From: hujy Date: Mon, 6 May 2019 18:17:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89sql=E5=8F=96=E8=A1=A8=E5=90=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A(SELECT=20*=20FROM=20(SELECT=20*=20FROM=20tab?= =?UTF-8?q?leName)a)v?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQL/Schema/CrossDB.cs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/SQL/Schema/CrossDB.cs b/SQL/Schema/CrossDB.cs index 25c1c3f3..b0d1c899 100644 --- a/SQL/Schema/CrossDB.cs +++ b/SQL/Schema/CrossDB.cs @@ -262,7 +262,7 @@ public static bool Add(string name, string type, string conn) private static string GetFirstTableNameFromSql(string sql) { //鑾峰彇鍘熷琛ㄥ悕 - string[] items = sql.Replace("\r\n", " ").Split(' '); + string[] items = sql.Replace("\r\n", " ").Replace("\t", " ").Split(' '); if (items.Length == 1) { return sql; }//鍗曡〃鍚 if (items.Length > 3) // 鎬绘槸鍖呭惈绌烘牸鐨剆elect * from xxx { @@ -281,17 +281,26 @@ private static string GetFirstTableNameFromSql(string sql) { startFrom = false; } - else if (item.IndexOf('.') > -1) + else { - if (item.ToLower().StartsWith("dbo.")) + string tableName = item; + if (item.IndexOf(')') > -1) { - return item.Substring(4); + tableName = item.Substring(0, item.IndexOf(')')); + } + + if (tableName.IndexOf('.') > -1) + { + if (tableName.ToLower().StartsWith("dbo.")) + { + return tableName.Substring(4); + } + startFrom = false; + } + else + { + return tableName; } - startFrom = false; - } - else - { - return item; } } }