//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// フィールドから値を取得。 /// /// TODO:セルタイプ以外にも対応したい。 /// </summary> /// <param name="RecordSet_toSave">ヌル不可</param> /// <param name="eSelectedFldName">選択フィールド</param> /// <param name="RecordSetSaveTo_or_null"></param> /// <param name="log_Reports"></param> /// <returns>行リスト<列リスト></returns> public List <List <string> > P5_Select_CellType( RecordSet dst_Rs_toSave, Selectstatement selectSt_ToSave, Expressionv_4ASelectRecord ecv_selRec_OrNull, //where Configuration_Node parent_Cf_Query, //this Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static); log_Method.BeginMethod(Info_Expr.Name_Library, this, "P5_Select", log_Reports); // // List <List <string> > reslt_sFieldListList = new List <List <string> >(); // // (1)テーブル Table_Humaninput o_Table; { o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName( selectSt_ToSave.Expression_From, true, log_Reports); if (null == o_Table) { // エラー。 goto gt_Error_NullTable; } } if (!log_Reports.Successful) { // // エラーが出ていたら、さっさと抜ける。 goto gt_EndMethod; } // // // // // 条件 // // // // Fielddefinition keyFldDefinition = null; string err_SSelectedFldName = null; Exception err_Exception = null; Recordcondition err_Recordcondition = null; foreach (Recordcondition recCond in selectSt_ToSave.List_Recordcondition) { err_Recordcondition = recCond; // // (2)検索のキーフィールドの定義を調べます。 // キーフィールド定義 { List <string> sList_KeyFldName; { // 要素数1個。 sList_KeyFldName = new List <string>(); sList_KeyFldName.Add(recCond.Name_Field); } RecordFielddefinition recordFielddefinition; bool bHit = o_Table.TryGetFieldDefinitionByName( out recordFielddefinition, sList_KeyFldName, false, log_Reports ); if (!log_Reports.Successful || !bHit) { // エラー goto gt_EndMethod; } keyFldDefinition = recordFielddefinition.ValueAt(0); } // // (3)選択対象のフィールドの定義を調べます。 RecordFielddefinition recordFieldDefinition_Selected; { bool bHit = o_Table.TryGetFieldDefinitionByName( out recordFieldDefinition_Selected, selectSt_ToSave.List_SName_SelectField, true, log_Reports ); if (!log_Reports.Successful) { // エラー goto gt_EndMethod; } } // // (4) if (null == keyFldDefinition) { // エラー。 goto gt_Error_NullKeyFldDefinition; } List <string> list_FldImpl3 = new List <string>(); recordFieldDefinition_Selected.ForEach(delegate(Fielddefinition fielddefinition_Selected, ref bool isBreak2, Log_Reports log_Reports2) { string sSelectField = fielddefinition_Selected.Name_Trimupper; // // (5) if (null == fielddefinition_Selected) { // エラー。 isBreak2 = true; goto gt_Error_NullSelectedFldDefinition; } // // (6)欠番 // // (7) if (null == dst_Rs_toSave || dst_Rs_toSave.List_Field.Count < 1) { bool bExpectedValueRequired; { bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired); } // // 条件 // string name_KeyField; Fielddefinition fielddefinition_Key; string value_Expected; P2_ReccondImpl sel2 = new P2_ReccondImpl(); sel2.GetFirstAwhrReccond( out name_KeyField, out fielddefinition_Key, out value_Expected, selectSt_ToSave.List_Recordcondition, o_Table, log_Reports ); List <DataRow> dst_Row = new List <DataRow>(); SelectPerformerImpl sp = new SelectPerformerImpl(); sp.Select( out dst_Row, name_KeyField, value_Expected, bExpectedValueRequired, fielddefinition_Key, o_Table.DataTable, parent_Cf_Query, log_Reports ); dst_Rs_toSave.AddList(dst_Row, log_Reports); if (!log_Reports.Successful) { // 既エラー。 isBreak2 = true; goto gt_EndInnermethod; } if (null == dst_Rs_toSave) { // (7-2) isBreak2 = true; goto gt_Error_UndefinedPrimitiveType; } } else { // レコードセットは、一時記憶から取得済み。 } // (8) if (log_Reports.Successful) { // キー_フィールドの型別に、処理。 switch (keyFldDefinition.Type_Field) { case EnumTypeFielddefinition.String: { // (8-1)キーが string型フィールドなら // この行の、選択対象のフィールドの値。 foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // 値。 Value_Humaninput selectedCellData; try { selectedCellData = (Value_Humaninput)record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } break; case EnumTypeFielddefinition.Int: { // // (8-2) キー・フィールドが int型の場合。 foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // この行の、選択対象のフィールドの値。 if (null != log_Reports && !log_Reports.Successful) //無限ループ防止 { // エラー発生時は無視。 } else { Value_Humaninput selectedCellData; try { selectedCellData = record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } { // 値。 Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } } } break; case EnumTypeFielddefinition.Bool: { // (8-3) キーが、bool型フィールド // 値。 foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // この行の、選択対象のフィールドの値。 Value_Humaninput selectedCellData; try { selectedCellData = (Value_Humaninput)record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } break; default: { // // (8-4) // // 既にエラー対策済み。 if (null != log_Reports) //無限ループ防止 { // // エラー。 isBreak2 = true; goto gt_Error_UndefinedPrimitiveType; } // // 非エラー中断。 isBreak2 = true; goto gt_EndInnermethod; } break; } } goto gt_EndInnermethod; // #region 異常系 //──────────────────────────────────────── gt_Error_NullSelectedFldDefinition: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, o_Table.Name, log_Reports); //テーブル名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6026;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── gt_Error_UndefinedPrimitiveType: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, keyFldDefinition.ToString_Type(), log_Reports); //キー・フィールド定義型名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6027;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── gt_Error_NotFoundFld: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, err_SSelectedFldName, log_Reports); //選択フィールド名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト tmpl.SetParameter(3, Log_RecordReportsImpl.ToText_Exception(err_Exception), log_Reports); //例外メッセージ this.Owner_MemoryApplication.CreateErrorReport("Er:6028;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── #endregion // gt_EndInnermethod: ; }, log_Reports);//select列1つ if (0 < list_FldImpl3.Count) { // フィールドがあれば追加。 reslt_sFieldListList.Add(list_FldImpl3); } } goto gt_EndMethod; // #region 異常系 //──────────────────────────────────────── gt_Error_NullTable: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); this.Owner_MemoryApplication.CreateErrorReport("Er:6024;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_NullKeyFldDefinition: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6025;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // gt_EndMethod: log_Method.EndMethod(log_Reports); return(reslt_sFieldListList); }
/// <summary> /// セレクト文を指定することで、レコードセットを取得。 /// </summary> /// <param name="log_Reports"></param> /// <returns>該当がなければヌル。</returns> private RecordSet E_Execute_P2_Select( bool isExists_Awhr, Selectstatement selectSt, Configuration_Node parent_Conf_Query, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static); log_Method.BeginMethod(Info_Expr.Name_Library, this, "E_Execute_P2_Select",log_Reports); // // RecordSet reslt_Rs; bool bLoad = false; // 一時記憶から、レコードセットのロードをするか否か。 { { Expression_Node_String ec_Awhr_RecordSetLoadFrom;//ソース情報利用 bool bHit = this.TrySelectAttribute( out ec_Awhr_RecordSetLoadFrom, NamesNode.S_RECORD_SET_LOAD_FROM, EnumHitcount.One_Or_Zero, log_Reports //null ); selectSt.Expression_Where_RecordSetLoadFrom = ec_Awhr_RecordSetLoadFrom; } if ("" != selectSt.Expression_Where_RecordSetLoadFrom.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim()) { bLoad = true; } } // レコードセットの取得。 if (bLoad) { // 一時記憶からロード。 P1_RecordSetLoader sel1 = new P1_RecordSetLoader(this.Owner_MemoryApplication); reslt_Rs = sel1.P1_Load( selectSt.Expression_Where_RecordSetLoadFrom, this.Cur_Configuration, log_Reports ); // ★空になってる。一時記憶から取り出したい。★★★★★★★★★★★★★★★★★★★★ //p3_Selectstatement = recordSet.Selectstatement; // new SelectStateImpl(s_ParentNode); // // データベースからレコード検索。 //p3_Selectstatement = this.E_Execute_P0( // nWhere_recordSetLoadFrom, // s_ParentNode, // log_Reports // ); // debug: 一時記憶から読み取った、レコードセットの内容。 //if (false) //{ // StringBuilder txt = new StringBuilder(); // txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute: (30_<f-cell>)【一時記憶から読み取った、レコードセットの内容(A)】"); // txt.Append(" fld=[" + recordSet.Selectstatement.E_Field.E_Execute( log_Reports) + "]"); // txt.Append(" lookup-value=[" + recordSet.Selectstatement.E_Value.E_Execute( log_Reports) + "]"); // txt.Append(" required=[" + recordSet.Selectstatement.E_Required.E_Execute( log_Reports) + "]"); // txt.Append(" from=[" + recordSet.Selectstatement.Expression_From.E_Execute( log_Reports) + "]"); // txt.Append(" description=[" + recordSet.Selectstatement.Expression_Description.E_Execute( log_Reports) + "]"); // txt.Append(" Storage=[" + recordSet.Selectstatement.Expression_Storage.E_Execute( log_Reports) + "]"); // txt.Append(" ヒット件数=[" + recordSet.O_Items.Count + "]"); // // レコードの内容 // foreach (Dictionary<string, Value_Humaninput> oRecord in recordSet.O_Items) // { // txt.Append(" フィールド数=[" + oRecord.Count + "]"); // foreach (string sKey in oRecord.Keys) // { // Value_Humaninput oValue = oRecord[sKey]; // txt.Append(" 要素=[" + sKey + ":"+ oValue.Humaninput + "]"); // } // } // //ystem.Console.WriteLine( txt.ToString() ); //} } else { Table_Humaninput tableH = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt.Expression_From, true, log_Reports); if (null == tableH) { // エラー。 reslt_Rs = null; goto gt_Error_NullTable; } // レコードセットを用意。 reslt_Rs = new RecordSetImpl(tableH); bool isRequired_ExpectedValue; { bool parseSuccessful = bool.TryParse(selectSt.Required, out isRequired_ExpectedValue); } // // 検索実行。 { List<DataRow> dst_Row = new List<DataRow>(); // // 条件 // if (0 < selectSt.List_Recordcondition.Count) { // 条件が指定されている場合。 string name_KeyField; Fielddefinition fielddefinition_Key; string value_Expected; P2_ReccondImpl sel2 = new P2_ReccondImpl(); sel2.GetFirstAwhrReccond( out name_KeyField, out fielddefinition_Key, out value_Expected, selectSt.List_Recordcondition, tableH, log_Reports ); if (log_Reports.Successful) { // TODO:セル型でない場合、キーフィールド名がないこともある。 SelectPerformerImpl sp = new SelectPerformerImpl(); sp.Select( out dst_Row, name_KeyField, value_Expected, isRequired_ExpectedValue, fielddefinition_Key, tableH.DataTable, parent_Conf_Query, log_Reports ); } } else { // 条件が指定されていない場合。 SelectPerformerImpl sp = new SelectPerformerImpl(); sp.Select( out dst_Row, isRequired_ExpectedValue, tableH.DataTable, parent_Conf_Query, log_Reports ); } if (log_Reports.Successful) { reslt_Rs.AddList(dst_Row, log_Reports); } if (!log_Reports.Successful) { // 既エラー。 goto gt_EndMethod; } } } goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_NullTable: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Conf_Query), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6019;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); return reslt_Rs; }
/// <summary> /// セレクト文を作成します。 /// </summary> /// <param name="out_bOneCellSelectCondition"></param> /// <param name="selectSt"></param> /// <param name="out_bExists_Awhr"></param> /// <param name="s_Fcell"></param> /// <param name="log_Reports"></param> private void E_Execute_P1_CleateSelect( out bool bOneCellSelectCondition_Out,//「フィールド名 = 値」の形のみ true。 エラー時もfalse。 out Selectstatement selectSt, out bool bExists_Awhr_Out,//@whereの有無を返します。エラー時はfalse。 Configuration_Node cf_Fcell,//「S■f-cell」。 Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static); log_Method.BeginMethod(Info_Expr.Name_Library, this, "E_Execute_P1_CleateSelect",log_Reports); // // // // 空っぽのセレクト文。 // bExists_Awhr_Out = false; bOneCellSelectCondition_Out = false; selectSt = new SelectstatementImpl(this, cf_Fcell); Expression_Node_StringImpl ec_Awhr_Src = null;//子「E■where」 // // (1)select=”☆” // 抽出する列名のリスト。 // Expression_Node_String ec_Aselect = null;//ソース情報利用のE if (log_Reports.Successful) { this.TrySelectAttribute(out ec_Aselect, PmNames.S_SELECT.Name_Pm, EnumHitcount.One, log_Reports); } if (log_Reports.Successful) { selectSt.List_SName_SelectField = new CsvTo_ListImpl().Read(ec_Aselect.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } // // (2)into 属性 // if (log_Reports.Successful) { Expression_Node_String ec_Into;//ソース情報利用のE bool bHit = this.TrySelectAttribute(out ec_Into, "into", EnumHitcount.One_Or_Zero, log_Reports); if (bHit) { selectSt.Expression_Into = ec_Into; } } // // (3)「E■@where」。無いものもある。 // if (log_Reports.Successful) { Expression_Node_String ec_Awhr1_Src; this.List_Expression_Child.ForEach(delegate(Expression_Node_String e_Child, ref bool bRemove, ref bool bBreak) { string sValue; e_Child.TrySelectAttribute(out sValue, PmNames.S_NAME.Name_Pm, EnumHitcount.One, log_Reports); if (NamesNode.S_FNC == e_Child.Cur_Configuration.Name && NamesFnc.S_WHERE == sValue) { ec_Awhr1_Src = e_Child;// Expression_Node_StringImpl である必要がある。E_String_AtomImplではダメ。 if (ec_Awhr1_Src is Expression_Node_StringImpl) { ec_Awhr_Src = (Expression_Node_StringImpl)ec_Awhr1_Src; } else { // エラー。 goto gt_Error_AtomWhr2; } bBreak = true; } goto gt_EndMethod2; // エラー。 gt_Error_AtomWhr2: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); Expression_Leaf_StringImpl ec_Leaf = (Expression_Leaf_StringImpl)ec_Awhr1_Src; tmpl.SetParameter(1, ec_Leaf.List_Expression_Child.Count.ToString(), log_Reports);//子要素の数 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6015;", tmpl, log_Reports); } goto gt_EndMethod2; // gt_EndMethod2: ; }); if (null != ec_Awhr_Src) { // 子「E■where」あり。 bExists_Awhr_Out = true; } else { // 正常。無いこともあります。 bExists_Awhr_Out = false; Configurationtree_Node cf_Node = new Configurationtree_NodeImpl(this + ":Where属性該当なし", null); ec_Awhr_Src = new Expression_Node_StringImpl(this, cf_Node); } } else { // エラーがあるのでさっさと抜ける。 bOneCellSelectCondition_Out = false; bExists_Awhr_Out = false; goto gt_EndMethod; } // // (3)required=”★” // レコードが1件以上ヒットすることが必須か。"true","TRUE"等。 // if (log_Reports.Successful) { // <f-cell required=”☆”>を使う。 // // <f-cell>は required属性を持たないはず。 // <fnc name=”Sf:where;”>のrequired引数が登録される? // // string sRequired; bool bHit = this.TrySelectAttribute(out sRequired, PmNames.S_REQUIRED.Name_Pm, EnumHitcount.One_Or_Zero, log_Reports); if (bHit) { selectSt.Required = sRequired; } else { // // <f-cell>が required属性を持っていないとき。 // //ystem.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect: <f-cell>が required属性を持っていないとき。"); // // where属性で「E■where」(fnc)を持っているはず。(無条件のときは持っていない) // Expression_Node_String ec_Whr;//属性利用 bool bHit2 = this.TrySelectAttribute(out ec_Whr, PmNames.S_WHERE.Name_Pm, EnumHitcount.One_Or_Zero, log_Reports); if (bHit2) { bool bHit3 = ec_Whr.TrySelectAttribute(out sRequired, PmNames.S_REQUIRED.Name_Pm, EnumHitcount.One_Or_Zero, log_Reports); if (bHit3) { selectSt.Required = sRequired; //ystem.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect: <f-cell>が required属性を持っていなかったので、whereのrequired属性から取得した。[" + selectSt.Required + "]"); } else { // whereのrequired設定が未指定。 // #エラー System.Console.WriteLine(Info_Expr.Name_Library + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect: <f-cell>が required属性を持っていなかったので、whereのrequired属性から取得しようとしたが、whereのrequiredは未設定だった。[" + selectSt.Required + "]"); } } else { // // <f-cell>が、where属性を持っていない。 【正常】 // //// required設定が未指定。 //// #エラー //System.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect: <f-cell>が required属性を持っていなかったので、whereのrequired属性から取得しようとしたが、whereは未設定だった。[" + selectSt.Required + "]"); //if (bDbg1) //{ // System.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect:┌────────┐this.E_AttrDic.Count=[" + this.E_AttrDic.Count + "]"); // this.E_AttrDic.Each_E_Nodes(delegate(string sName, Expression_Node_String e_Child, ref bool bBreak) // { // System.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect: [" + sName + "]=[" + e_Child.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports) + "]"); // }); // System.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_CleateSelect:└────────┘"); //} } } } // // (4)テーブル名。"Ut:モンスター表"等。 // if (log_Reports.Successful) { // <f-cell from=”☆”>を使う。 Expression_Node_String ec_From;//ソース情報利用 bool bHit = this.TrySelectAttribute(out ec_From, PmNames.S_FROM.Name_Pm, EnumHitcount.One, log_Reports); if (bHit) { selectSt.Expression_From = ec_From; } // テーブル名は必須。 if ("" == selectSt.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim()) { // // エラー。 //dst_Rs = null; goto gt_Error_EmptyTableName; } } // // 「E■f-cell」は、子要素を持たない。 // // 「E■f-cell」には、次の属性がある。 // (1)「E■@where」 // // // 「E■@where」は、次の子要素のリストがある。 // ・「E■fnc name=”Sf:rec-cond;”」 // // // f-cellの子要素の数は、where要素1つ、または 0 が正しい。 // if (log_Reports.Successful) { // 子要素。 List<Expression_Node_String> ecList = this.List_Expression_Child.SelectList(EnumHitcount.Unconstraint, log_Reports); //if (0 < e_List.Count) if (1 < ecList.Count) { goto gt_Error_ExistsFcellChild; } } // // (2)探したいキー値の有無。"1000"等。 if (log_Reports.Successful) { // key属性(@where)、record-set-load-from属性のどちらかが書かれているはず。 if ( bExists_Awhr_Out || "" != selectSt.Expression_Where_RecordSetLoadFrom.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim() ) { //ystem.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_PP1_FcellToSelectSt: 「E■a-where keyField=”☆”」は無かったが、「子E■rec-cond」要素はあった場合。"); // 次へ進む。 } else { // エラー。key値(@where)も、record-set-load-from属性もない。 goto gt_Error_EmptyKey; } } // // <f-cell>が、keyField=”★”属性("ID"などの値)を持つのは、R4-100版で廃止されました。 // // // (5)あれば、「E■@where」の解析。(2012-02-07) // if (log_Reports.Successful) { if (bExists_Awhr_Out) { // 「E■@where」条件が付いているとき。 // 「E■@where」の logic属性を取得しておく。 { string sLogic; bool bHit = ec_Awhr_Src.TrySelectAttribute(out sLogic, PmNames.S_LOGIC.Name_Pm, EnumHitcount.One_Or_Zero, log_Reports); if (bHit) { selectSt.EnumWherelogic = Utility_Table.LogicStringToEnum(sLogic); //ystem.Console.WriteLine(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute_P1_SelectSt: where要素のlogic属性もきちんと読み取り。[" + sAwhrLogic + "]"); } } this.Execute_ParseChildRecordconditionList( selectSt.List_Recordcondition, ec_Awhr_Src, log_Reports ); } else { // 「E■@where」条件が無い場合。 // #警告。正常。 System.Console.WriteLine(Info_Expr.Name_Library + ":" + this.GetType().Name + "#E_Execute_P1_SelectSt: 条件がないタイプ(whereを持たない)です。親ノード=" + this.Cur_Configuration.Parent); } } // // 「E■@where」は、2種類に判別。 // (1)「E■rec-cond」が1つだけ入っている形式 // (2)「E■rec-cond」が1つ以上入っている形式 // if (log_Reports.Successful) { if (0 == selectSt.List_Recordcondition.Count()) { // // 0個なら、無条件。 // } else if (1 == selectSt.List_Recordcondition.Count()) { // // 「フィールド値=値」の形の条件式かどうかを調べます。 // // ・<rec-cond>が1つ Recordcondition firstReccond = selectSt.List_Recordcondition[0]; if (null == firstReccond) { // #エラー? TODO:エラー? System.Console.WriteLine(Info_Expr.Name_Library + ":" + this.GetType().Name + "#E_Execute_P1_SelectSt: rec-condリストにヌルが入っていた。エラー?"); // 条件ハズレ。 goto end_conditionSpec; } // ・その<rec-cond>は logic属性を持たない。 if (EnumLogic.None != firstReccond.EnumLogic) { // 条件ハズレ。 goto end_conditionSpec; } // field属性には1つのフィールド名が書かれている。(selectではないので、そうでなければエラー) List<string> sList_FieldName = new CsvTo_ListImpl().Read(firstReccond.Name_Field); if (1 != sList_FieldName.Count) { // 条件ハズレ。 goto end_conditionSpec; } // valueを持つ。 if ("" == firstReccond.Value.Trim()) { // 条件ハズレ。 goto end_conditionSpec; } //「=」で結ばれている条件のもの。 if (EnumOpe.Eq != firstReccond.EnumOpe) { // 条件ハズレ。 goto end_conditionSpec; } // 適合。「フィールド名=値」の形の条件式。セル1つが選ばれる。 bOneCellSelectCondition_Out = true; } else { // 条件ハズレ。 } } end_conditionSpec: goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_ExistsFcellChild: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, this.Cur_Configuration.Name, log_Reports);//設定ノード名 List<Expression_Node_String> e_List = this.List_Expression_Child.SelectList(EnumHitcount.Unconstraint, log_Reports); tmpl.SetParameter(2, e_List.Count.ToString(), log_Reports);//子要素の数 Log_TextIndented s = new Log_TextIndentedImpl(); foreach (Expression_Node_String ec_Child in e_List) { s.Append("Expr[" + ec_Child.Cur_Configuration.Name + "]"); s.Newline(); } tmpl.SetParameter(3, s.ToString(), log_Reports);//要素のリスト tmpl.SetParameter(4, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6016;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_EmptyKey: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, bExists_Awhr_Out.ToString(), log_Reports);//Where句の有無 tmpl.SetParameter(2, selectSt.Expression_Where_RecordSetLoadFrom.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim(), log_Reports);//RecordSetLoadFrom属性 tmpl.SetParameter(3, this.Dictionary_Expression_Attribute.Count.ToString(), log_Reports);//属性の数 Log_TextIndented s1 = new Log_TextIndentedImpl(); this.Dictionary_Expression_Attribute.ForEach(delegate(string sName3, Expression_Node_String e_Attr3, ref bool bBreak) { s1.Append("Attribute[" + sName3 + "]=Expr[" + e_Attr3.Cur_Configuration.Name + "] 値=[" + e_Attr3.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports) + "]"); s1.Newline(); }); tmpl.SetParameter(4, s1.ToString(), log_Reports);//属性リスト tmpl.SetParameter(5, this.Dictionary_Expression_Attribute.Count.ToString(), log_Reports);//子要素の数 Log_TextIndented s2 = new Log_TextIndentedImpl(); this.List_Expression_Child.ForEach(delegate(Expression_Node_String e_Child, ref bool bRemove, ref bool bBreak) { s2.Append("子 [" + e_Child.Cur_Configuration.Name + "]=[" + e_Child.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports) + "]"); s2.Newline(); }); tmpl.SetParameter(6, s2.ToString(), log_Reports);//子要素リスト tmpl.SetParameter(7, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6017;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_EmptyTableName: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(cf_Fcell), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6018;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); }
//──────────────────────────────────────── /// <summary> /// フィールドから値を取得。 /// /// TODO:セルタイプ以外にも対応したい。 /// </summary> /// <param name="RecordSet_toSave">ヌル不可</param> /// <param name="eSelectedFldName">選択フィールド</param> /// <param name="RecordSetSaveTo_or_null"></param> /// <param name="log_Reports"></param> /// <returns>行リスト<列リスト></returns> public List<List<string>> P5_Select_CellType( RecordSet dst_Rs_toSave, Selectstatement selectSt_ToSave, Expressionv_4ASelectRecord ecv_selRec_OrNull,//where Configuration_Node parent_Cf_Query,//this Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static); log_Method.BeginMethod(Info_Expr.Name_Library, this, "P5_Select",log_Reports); // // List<List<string>> reslt_sFieldListList = new List<List<string>>(); // // (1)テーブル Table_Humaninput o_Table; { o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName( selectSt_ToSave.Expression_From, true, log_Reports); if (null == o_Table) { // エラー。 goto gt_Error_NullTable; } } if (!log_Reports.Successful) { // // エラーが出ていたら、さっさと抜ける。 goto gt_EndMethod; } // // // // // 条件 // // // // Fielddefinition keyFldDefinition = null; string err_SSelectedFldName = null; Exception err_Exception = null; Recordcondition err_Recordcondition = null; foreach (Recordcondition recCond in selectSt_ToSave.List_Recordcondition) { err_Recordcondition = recCond; // // (2)検索のキーフィールドの定義を調べます。 // キーフィールド定義 { List<string> sList_KeyFldName; { // 要素数1個。 sList_KeyFldName = new List<string>(); sList_KeyFldName.Add(recCond.Name_Field); } RecordFielddefinition recordFielddefinition; bool bHit = o_Table.TryGetFieldDefinitionByName( out recordFielddefinition, sList_KeyFldName, false, log_Reports ); if (!log_Reports.Successful || !bHit) { // エラー goto gt_EndMethod; } keyFldDefinition = recordFielddefinition.ValueAt(0); } // // (3)選択対象のフィールドの定義を調べます。 RecordFielddefinition recordFieldDefinition_Selected; { bool bHit = o_Table.TryGetFieldDefinitionByName( out recordFieldDefinition_Selected, selectSt_ToSave.List_SName_SelectField, true, log_Reports ); if (!log_Reports.Successful) { // エラー goto gt_EndMethod; } } // // (4) if (null == keyFldDefinition) { // エラー。 goto gt_Error_NullKeyFldDefinition; } List<string> list_FldImpl3 = new List<string>(); recordFieldDefinition_Selected.ForEach(delegate(Fielddefinition fielddefinition_Selected,ref bool isBreak2,Log_Reports log_Reports2) { string sSelectField = fielddefinition_Selected.Name_Trimupper; // // (5) if (null == fielddefinition_Selected) { // エラー。 isBreak2 = true; goto gt_Error_NullSelectedFldDefinition; } // // (6)欠番 // // (7) if (null == dst_Rs_toSave || dst_Rs_toSave.List_Field.Count < 1) { bool bExpectedValueRequired; { bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired); } // // 条件 // string name_KeyField; Fielddefinition fielddefinition_Key; string value_Expected; P2_ReccondImpl sel2 = new P2_ReccondImpl(); sel2.GetFirstAwhrReccond( out name_KeyField, out fielddefinition_Key, out value_Expected, selectSt_ToSave.List_Recordcondition, o_Table, log_Reports ); List<DataRow> dst_Row = new List<DataRow>(); SelectPerformerImpl sp = new SelectPerformerImpl(); sp.Select( out dst_Row, name_KeyField, value_Expected, bExpectedValueRequired, fielddefinition_Key, o_Table.DataTable, parent_Cf_Query, log_Reports ); dst_Rs_toSave.AddList(dst_Row, log_Reports); if (!log_Reports.Successful) { // 既エラー。 isBreak2 = true; goto gt_EndInnermethod; } if (null == dst_Rs_toSave) { // (7-2) isBreak2 = true; goto gt_Error_UndefinedPrimitiveType; } } else { // レコードセットは、一時記憶から取得済み。 } // (8) if (log_Reports.Successful) { // キー_フィールドの型別に、処理。 switch (keyFldDefinition.Type_Field) { case EnumTypeFielddefinition.String: { // (8-1)キーが string型フィールドなら // この行の、選択対象のフィールドの値。 foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // 値。 Value_Humaninput selectedCellData; try { selectedCellData = (Value_Humaninput)record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } break; case EnumTypeFielddefinition.Int: { // // (8-2) キー・フィールドが int型の場合。 foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // この行の、選択対象のフィールドの値。 if (null != log_Reports && !log_Reports.Successful)//無限ループ防止 { // エラー発生時は無視。 } else { Value_Humaninput selectedCellData; try { selectedCellData = record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } { // 値。 Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } } } break; case EnumTypeFielddefinition.Bool: { // (8-3) キーが、bool型フィールド // 値。 foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field) { // この行の、選択対象のフィールドの値。 Value_Humaninput selectedCellData; try { selectedCellData = (Value_Humaninput)record[sSelectField]; } catch (KeyNotFoundException ex) { selectedCellData = null; err_SSelectedFldName = sSelectField; err_Exception = ex; isBreak2 = true; goto gt_Error_NotFoundFld; } Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue( fielddefinition_Selected, selectedCellData, parent_Cf_Query, log_Reports ); list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports)); } } break; default: { // // (8-4) // // 既にエラー対策済み。 if (null != log_Reports)//無限ループ防止 { // // エラー。 isBreak2 = true; goto gt_Error_UndefinedPrimitiveType; } // // 非エラー中断。 isBreak2 = true; goto gt_EndInnermethod; } break; } } goto gt_EndInnermethod; // #region 異常系 //──────────────────────────────────────── gt_Error_NullSelectedFldDefinition: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, o_Table.Name, log_Reports);//テーブル名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6026;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── gt_Error_UndefinedPrimitiveType: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, keyFldDefinition.ToString_Type(), log_Reports);//キー・フィールド定義型名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6027;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── gt_Error_NotFoundFld: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, err_SSelectedFldName, log_Reports);//選択フィールド名 tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト tmpl.SetParameter(3, Log_RecordReportsImpl.ToText_Exception(err_Exception), log_Reports);//例外メッセージ this.Owner_MemoryApplication.CreateErrorReport("Er:6028;", tmpl, log_Reports); } goto gt_EndInnermethod; //──────────────────────────────────────── #endregion // gt_EndInnermethod: ; }, log_Reports);//select列1つ if (0 < list_FldImpl3.Count) { // フィールドがあれば追加。 reslt_sFieldListList.Add(list_FldImpl3); } } goto gt_EndMethod; // #region 異常系 //──────────────────────────────────────── gt_Error_NullTable: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); this.Owner_MemoryApplication.CreateErrorReport("Er:6024;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_NullKeyFldDefinition: { Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl(); tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト this.Owner_MemoryApplication.CreateErrorReport("Er:6025;", tmpl, log_Reports); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // gt_EndMethod: log_Method.EndMethod(log_Reports); return reslt_sFieldListList; }