Skip to content
27 changes: 18 additions & 9 deletions SQL/Schema/CrossDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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) // 总是包含空格的select * from xxx
{
Expand All @@ -282,17 +282,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;
}
}
}
Expand Down