示例#1
0
        }       //	generateTable

        /// <summary>
        /// Generate Delta View
        /// </summary>
        /// <returns>true, if created</returns>
        private bool GenerateView()
        {
            //	View
            m_viewTable = MTable.Get(m_ctx, m_vTableName);
            if (m_viewTable == null)
            {
                m_viewTable = new MTable(m_ctx, 0, null);
            }

            PO.CopyValues(m_baseTable, m_viewTable);
            m_viewTable.SetTableName(m_vTableName);
            m_viewTable.SetName(m_baseTable.GetName() + " View");
            m_viewTable.SetIsView(true);
            if (!m_viewTable.Save())
            {
                throw new Exception("Cannot save " + m_vTableName);
            }

            MColumn[] vCols = SyncMColumns(false);

            //ColumnSync
            //	Create View
            StringBuilder sql = new StringBuilder("CREATE OR REPLACE VIEW ")
                                .Append(m_vTableName)
                                .Append(" AS SELECT ");

            for (int i = 0; i < vCols.Length; i++)
            {
                if (i > 0)
                {
                    sql.Append(",");
                }
                MColumn column     = vCols[i];
                String  columnName = column.GetColumnName();
                if (column.IsStandardColumn() ||
                    column.IsKey())
                {
                    sql.Append("b.").Append(columnName);
                }
                else
                {
                    sql.Append(",COALESCE(b.").Append(columnName)
                    .Append("d.").Append(columnName).Append(") AS ").Append(columnName);
                }
            }
            //	From
            String keyColumnName = m_baseTable.GetTableName() + "_ID";

            sql.Append(" FROM ").Append(m_baseTable.GetTableName())
            .Append(" b LEFT OUTER JOIN ").Append(m_dTableName)
            .Append(" d ON (b.").Append(keyColumnName)
            .Append("=d.").Append(keyColumnName).Append(")");
            //
            log.Info(sql.ToString());
            if (DataBase.DB.ExecuteQuery(sql.ToString(), null) < 0)
            {
                return(false);
            }
            return(true);
        }       //	generateView
示例#2
0
        /// <summary>
        ///Add Translation Columns
        /// </summary>
        private void InitColumns()
        {
            //MTable table = null;
            //MTable table = MTable.get(Env.getCtx(), m_trlTableName);
            MTable table = MTable.Get(Utility.Env.GetContext(), _trlTableName);

            if (table == null)
            {
                throw new ArgumentException("Table Not found=" + _trlTableName);
            }
            MColumn[] columns = table.GetColumns(false);
            for (int i = 0; i < columns.Length; i++)
            {
                MColumn column = columns[i];
                if (column.IsStandardColumn())
                {
                    continue;
                }
                String columnName = column.GetColumnName();
                if (columnName.EndsWith("_ID") ||
                    columnName.StartsWith("AD_Language") ||
                    columnName.Equals("IsTranslated"))
                {
                    continue;
                }
                //
                _columns.Add(columnName);
            }
            if (_columns.Count == 0)
            {
                throw new ArgumentException("No Columns found=" + _trlTableName);
            }
        }