// 指定したResultInfoの抽出元のTableResultInfoを取得する private TableResultInfo GetSourceTableResultInfo(IResultInfo resultInfo) { if (resultInfo.Type == ResultInfoType.Query) { var queryInfo = (QueryResultInfo)resultInfo; if (queryInfo.SourceInfo == null) { return(null); } return(this.GetSourceTableResultInfo(queryInfo.SourceInfo)); } else if (resultInfo.Type == ResultInfoType.Compound) { var compoundQueryInfo = (CompoundQueryResultInfo)resultInfo; // LeftとRight(RightとLeft)がNullリテラルとテーブル参照列の組合わせの場合に // SourceTableプロパティに値が設定される if (compoundQueryInfo.SourceTable == null) { return(null); } if (compoundQueryInfo.LeftResultInfo.IsNullLiteral) { return(this.GetSourceTableResultInfo(compoundQueryInfo.RightResultInfo)); } else { return(this.GetSourceTableResultInfo(compoundQueryInfo.LeftResultInfo)); } } else if (resultInfo.Type == ResultInfoType.Count) { var countInfo = (CountQueryResultInfo)resultInfo; return(this.GetSourceTableResultInfo(countInfo.SourceInfo)); } else if (resultInfo.Type == ResultInfoType.Table) { return((TableResultInfo)resultInfo); } else { throw new InvalidEnumArgumentException("Undefined QueryType is used"); } }
private IResultInfo GetSourceInfoOfSingleQueryResultInfo(IResultInfo resultInfo) { if (resultInfo.Type == ResultInfoType.Query) { var sourceInfo = ((AbstractSingleQueryResultInfo)resultInfo).SourceInfo; if (sourceInfo == null) { return(null); } else { return(sourceInfo); } } else if (resultInfo.Type == ResultInfoType.Compound) { var compoundQueryInfo = (CompoundQueryResultInfo)resultInfo; var leftInfo = this.GetSourceInfoOfSingleQueryResultInfo(compoundQueryInfo.LeftResultInfo); if (leftInfo == null) { return(this.GetSourceInfoOfSingleQueryResultInfo(compoundQueryInfo.RightResultInfo)); } else { return(leftInfo); } } else if (resultInfo.Type == ResultInfoType.Count) { throw new ApplicationException(""); } else { throw new InvalidEnumArgumentException("Undefined ResultInfoType is used"); } }
// 結合条件を作成し付加する // 付加できた場合はtrueを返す private bool AddCorrelatedCondition(IQueryClause subQueryClause , IResultInfo subResultInfo , string tableAliasNameOfSub , IResultInfo mainResultInfo , string tableAliasNameOfMain) { if (subResultInfo.Type == ResultInfoType.Query) { var subQueryInfo = (QueryResultInfo)subResultInfo; //// SELECT句の抽出元テーブル情報を取得する // 結合条件を作成する string condition; string subTableAliasName = subQueryInfo.SourceInfo.TableAliasName; string primaryKeyOfSubTable = subQueryInfo.SourceInfo.ColumnAliasName; if (mainResultInfo == null) { var primaryKey = this.GetSourceTableResultInfo(subQueryInfo).ColumnAliasName; condition = tableAliasNameOfSub + "." + primaryKeyOfSubTable + " = " + tableAliasNameOfMain + "." + primaryKey; } else { string primaryKeyOfMainTable = mainResultInfo.ColumnAliasName; condition = tableAliasNameOfSub + "." + primaryKeyOfSubTable + " = " + tableAliasNameOfMain + "." + primaryKeyOfMainTable; } // 結合条件を追加する var visitor = new AddWherePredicateVisitor(condition, _dbmsType, _forSqlAccessor); subQueryClause.Accept(visitor); return(true); } else if (subResultInfo.Type == ResultInfoType.Compound) { var compoundQueryInfo = (CompoundQueryResultInfo)subResultInfo; if (subQueryClause.Type != QueryType.Compound) { return(false); } // 集合演算での抽出元の走査は左演算子を優先する var ret = this.AddCorrelatedCondition(((CompoundQuery)subQueryClause).Left , compoundQueryInfo.LeftResultInfo , tableAliasNameOfSub , mainResultInfo , tableAliasNameOfMain); if (!ret) { ret = this.AddCorrelatedCondition(((CompoundQuery)subQueryClause).Right , compoundQueryInfo.RightResultInfo , tableAliasNameOfSub , mainResultInfo , tableAliasNameOfMain); } return(ret); } else if (subResultInfo.Type == ResultInfoType.Count) { return(false); } else if (subResultInfo.Type == ResultInfoType.Table) { // selectItemがTableResultInfoの場合はない throw new ArgumentException( "GetCorrelatedCondition()にTableResultInfoは指定できません", "selectItem"); } else { throw new InvalidEnumArgumentException("Undefined ResultInfoType is used" , (int)subResultInfo.Type , typeof(ResultInfoType)); } }