/// <summary> /// 取得關連明細資料表使用欄位集合。 /// </summary> /// <param name="useFields">取得使用的欄位集合。</param> /// <param name="detailTableName">傳回明細資料表名稱。</param> private GStringHashSet GetUseDetailTableFields(GStringHashSet useFields, out string detailTableName) { GStringHashSet oUseFields; string sDetailTableName; string sTableName; string sFieldName; sDetailTableName = string.Empty; oUseFields = new GStringHashSet(); foreach (string fieldName in useFields) { if (StrFunc.StrContains(fieldName, ".")) { // 折解資料表及欄位名稱 StrFunc.StrSplitFieldName(fieldName, out sTableName, out sFieldName); // 主檔不能同時 Join 多個明細資料表 if (StrFunc.StrIsNotEmpty(sDetailTableName) && !StrFunc.SameText(sDetailTableName, sTableName)) { throw new GException("Master Table can't Join multi Detail Table"); } sDetailTableName = sTableName; oUseFields.Add(sFieldName); } } detailTableName = sDetailTableName; return(oUseFields); }
/// <summary> /// 取得 SELECT 欄位的語法。 /// </summary> /// <param name="helper">資料庫命令輔助類別。</param> /// <param name="provider">資料表關連資訊提供者。</param> /// <param name="tableName">資料表名稱。</param> /// <param name="selectFields">選取得欄位集合字串。</param> /// <param name="selectCount">取得筆數。</param> /// <param name="selectSection">查詢區間</param> private string GetSelectFieldsCommandText(IDbCommandHelper helper, GTableJoinProvider provider, string tableName, string selectFields) { GTableDefine oTableDefine; GFieldDefine oFieldDefine; StringBuilder oBuffer; string[] oSelectFields; string sCommandText; oTableDefine = this.ProgramDefine.Tables[tableName]; oBuffer = new StringBuilder(); if (StrFunc.StrIsEmpty(selectFields)) { foreach (GFieldDefine fieldDefine in oTableDefine.Fields) { if (fieldDefine.FieldType != EFieldType.VirtualField) { if (oBuffer.Length > 0) { oBuffer.AppendLine(","); } sCommandText = provider.GetSelectField(helper, fieldDefine); oBuffer.Append(sCommandText); } } } else { oSelectFields = StrFunc.StrSplit(selectFields, ","); foreach (string fieldName in oSelectFields) { oFieldDefine = this.ProgramDefine.FindField(fieldName); if (oFieldDefine.FieldType != EFieldType.VirtualField) { if (oBuffer.Length > 0) { oBuffer.AppendLine(","); } if (StrFunc.StrContains(fieldName, ".")) { sCommandText = provider.GetDetailSelectField(helper, oFieldDefine); } else { sCommandText = provider.GetSelectField(helper, oFieldDefine); } oBuffer.Append(sCommandText); } } } return(StrFunc.StrFormat("Select \n") + oBuffer.ToString()); }
/// <summary> /// 取得主要資料表使用欄位集合。 /// </summary> /// <param name="useFields">使用欄位集合。</param> private GStringHashSet GetUseTableFields(GStringHashSet useFields) { var useFieldSet = new GStringHashSet(); foreach (string fieldName in useFields) { if (!StrFunc.StrContains(fieldName, ".")) { useFieldSet.Add(fieldName); } } return(useFieldSet); }
/// <summary> /// 設定資料庫命令字串,並用命令參數集合做格式化字串。 /// </summary> /// <param name="commandText">命令字串。</param> public void SetCommandFormatText(string commandText) { StringBuilder oBuffer; if (StrFunc.StrContains(commandText, CommandTextVariable.Parameters)) { oBuffer = new StringBuilder(); for (int N1 = 0; N1 < this.DbCommand.Parameters.Count; N1++) { StrFunc.StrMerge(oBuffer, "{" + N1 + "}", ","); } commandText = StrFunc.StrReplace(commandText, CommandTextVariable.Parameters, oBuffer.ToString()); } commandText = StrFunc.StrUpper(commandText); this.DbCommand.CommandText = StrFunc.SQLFormat(commandText, this.DbCommand.Parameters); }