/// <summary> /// Helper to check the join /// </summary> public void CheckJoin() { Error = ""; Information = ""; try { if (LeftTable == null) { throw new Exception("Please select a Left table for the join"); } if (RightTable == null) { throw new Exception("Please select a Right table for the join"); } if (_joinType != JoinType.Cross && string.IsNullOrEmpty(Clause.Trim())) { throw new Exception("Please enter a SQL statement for the join"); } string CTE1 = "", name1 = "", CTE2 = "", name2 = ""; LeftTable.GetExecSQLName(ref CTE1, ref name1); RightTable.GetExecSQLName(ref CTE2, ref name2); string CTE = Helper.AddCTE(CTE1, CTE2); string sql = string.Format("{0}SELECT * FROM {1}\r\n", CTE, name1); if (_joinType != JoinType.Cross) { sql += string.Format("{0} {1} ON {2}\r\n", SQLJoinType, name2, Clause.Trim()); } else { sql += string.Format("{0} {1}\r\n", SQLJoinType, name2); } sql += "WHERE 0=1"; Error = Source.CheckSQL(sql, new List <MetaTable>() { LeftTable, RightTable }, null, false); if (!string.IsNullOrEmpty(Error)) { Information = "Error got when checking join. Please check the SQL:\r\n" + sql; } else { Information = "Join checked successfully."; } } catch (Exception ex) { Error = ex.Message; Information = "Error got when checking the join."; } Information = Helper.FormatMessage(Information); UpdateEditorAttributes(); }
/// <summary> /// Helper to check the join /// </summary> public void CheckJoin() { Error = ""; Information = ""; try { if (LeftTable == null) { throw new Exception("Please select a Left table for the join"); } if (RightTable == null) { throw new Exception("Please select a Right table for the join"); } if (_joinType != JoinType.Cross && string.IsNullOrEmpty(Clause.Trim())) { throw new Exception("Please enter a Statement for the join"); } if (Source.IsSQL) { string CTE1 = "", name1 = "", CTE2 = "", name2 = ""; LeftTable.GetExecSQLName(ref CTE1, ref name1); RightTable.GetExecSQLName(ref CTE2, ref name2); string CTE = Helper.AddCTE(CTE1, CTE2); string sql = string.Format("{0}SELECT * FROM {1}\r\n", CTE, name1); if (_joinType != JoinType.Cross) { sql += string.Format("{0} {1} ON {2}\r\n", SQLJoinType, name2, Clause.Trim()); } else { sql += string.Format("{0} {1}\r\n", SQLJoinType, name2); } sql += "WHERE 0=1"; Error = Source.CheckSQL(sql, new List <MetaTable>() { LeftTable, RightTable }, null, false); if (!string.IsNullOrEmpty(Error)) { Information = "Error got when checking join. Please check the SQL:\r\n" + sql; } else { Information = "Join checked successfully."; } } else { var linq = string.Format(@"@using System.Data @{{ DataTable aDataTable = new DataTable(); var query = from {0} in aDataTable.AsEnumerable() join {1} in aDataTable.AsEnumerable() on {2} select {0}; }}", LeftTable.AliasName, RightTable.AliasName, Clause); try { RazorHelper.Compile(linq, typeof(MetaJoin), Helper.NewGUID()); Information = "Join checked successfully."; } catch (Exception ex) { Error = ex.Message; Information = "Error got when checking join. Please check the LINQ:\r\n" + linq; } } } catch (Exception ex) { Error = ex.Message; Information = "Error got when checking the join."; } Information = Helper.FormatMessage(Information); }