Exemplo n.º 1
0
 private void parseCreateView(TCreateViewSqlStatement createView)
 {
     if (createView.ViewName != null)
     {
         string        tableName    = createView.ViewName.TableString;
         string        tableSchema  = createView.ViewName.SchemaString;
         string        databaseName = createView.ViewName.DatabaseString;
         TableMetaData viewMetaData = new TableMetaData(vendor, strict);
         viewMetaData.Name       = tableName;
         viewMetaData.SchemaName = tableSchema;
         if (isNotEmpty(databaseName))
         {
             viewMetaData.CatalogName = databaseName;
         }
         else
         {
             viewMetaData.CatalogName = database;
         }
         viewMetaData.View = true;
         if (!tableColumns.ContainsKey(viewMetaData))
         {
             tableColumns[viewMetaData] = new List <ColumnMetaData>();
         }
         else
         {
             IList <TableMetaData> tables = new List <TableMetaData>(tableColumns.Keys);
             viewMetaData      = (TableMetaData)tables[tables.IndexOf(viewMetaData)];
             viewMetaData.View = true;
         }
         if (createView.Subquery != null)
         {
             ColumnImpact impact = new ColumnImpact(createView.Subquery.ToString(), createView.dbvendor, tableColumns, strict);
             impact.ignoreTopSelect(true);
             impact.Debug             = false;
             impact.ShowUIInfo        = true;
             impact.TraceErrorMessage = false;
             impact.impactSQL();
             ColumnImpactModel columnImpactModel = impact.generateModel();
             parseSubQueryColumnDefinition(createView, createView.Subquery, viewMetaData, columnImpactModel);
         }
     }
 }
Exemplo n.º 2
0
 private void parseInsertStmt(TInsertSqlStatement insert)
 {
     if (insert.TargetTable.TableName != null)
     {
         string        tableName     = insert.TargetTable.TableName.TableString;
         string        tableSchema   = insert.TargetTable.TableName.SchemaString;
         string        databaseName  = insert.TargetTable.TableName.DatabaseString;
         TableMetaData tableMetaData = new TableMetaData(vendor, strict);
         tableMetaData.Name       = tableName;
         tableMetaData.SchemaName = tableSchema;
         if (isNotEmpty(databaseName))
         {
             tableMetaData.CatalogName = databaseName;
         }
         else
         {
             tableMetaData.CatalogName = database;
         }
         tableMetaData.View = false;
         if (!tableColumns.ContainsKey(tableMetaData))
         {
             tableColumns[tableMetaData] = new List <ColumnMetaData>();
         }
         else
         {
             IList <TableMetaData> tables = new List <TableMetaData>(tableColumns.Keys);
             tableMetaData      = (TableMetaData)tables[tables.IndexOf(tableMetaData)];
             tableMetaData.View = false;
         }
         if (insert.SubQuery != null)
         {
             ColumnImpact impact = new ColumnImpact(insert.SubQuery.ToString(), insert.dbvendor, tableColumns, strict);
             impact.ignoreTopSelect(true);
             impact.Debug             = false;
             impact.ShowUIInfo        = true;
             impact.TraceErrorMessage = false;
             impact.impactSQL();
             ColumnImpactModel columnImpactModel = impact.generateModel();
             parseSubQueryColumnDefinition(insert, insert.SubQuery, tableMetaData, columnImpactModel);
         }
     }
 }
Exemplo n.º 3
0
        private ColumnMetaData[] getRefTableColumns(TResultColumn resultColumn, ColumnImpactModel columnImpactModel)
        {
            ReferenceModel[]      referenceModels = columnImpactModel.References;
            List <ColumnMetaData> columns         = new List <ColumnMetaData>();

            if (resultColumn.AliasClause != null)
            {
                for (int i = 0; i < referenceModels.Length; i++)
                {
                    ReferenceModel referModel = referenceModels[i];
                    // if ( referModel.getClause( ) != Clause.SELECT )
                    // continue;
                    if (referModel.Alias != null)
                    {
                        string aliasName = resultColumn.AliasClause.AliasName.ToString();
                        if (removeQuote(referModel.Alias.Name).Equals(removeQuote(aliasName), StringComparison.CurrentCultureIgnoreCase))
                        {
                            ColumnMetaData columnMetaData = getColumn(referModel.Column);
                            if (columnMetaData != null && !columns.Contains(columnMetaData))
                            {
                                columns.Add(columnMetaData);
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < referenceModels.Length; i++)
                {
                    ReferenceModel referModel = referenceModels[i];
                    // if ( referModel.getClause( ) != Clause.SELECT )
                    // continue;
                    if (referModel.Field != null)
                    {
                        if (resultColumn.FieldAttr != null)
                        {
                            if (removeQuote(resultColumn.FieldAttr.ToString()).Equals(removeQuote(referModel.Field.FullName), StringComparison.CurrentCultureIgnoreCase))
                            {
                                ColumnMetaData columnMetaData = getColumn(referModel.Column);
                                if (!columns.Contains(columnMetaData))
                                {
                                    columns.Add(columnMetaData);
                                }
                            }
                        }
                        else
                        {
                            if (removeQuote(resultColumn.ToString()).Equals(removeQuote(referModel.Field.FullName), StringComparison.CurrentCultureIgnoreCase))
                            {
                                ColumnMetaData columnMetaData = getColumn(referModel.Column);
                                if (!columns.Contains(columnMetaData))
                                {
                                    columns.Add(columnMetaData);
                                }
                            }
                        }
                    }
                }
            }
            return(columns.ToArray());
        }
Exemplo n.º 4
0
        private void parseColumnDefinition(TResultColumn resultColumn, TableMetaData viewMetaData, ColumnImpactModel columnImpactModel, string aliasName)
        {
            ColumnMetaData columnMetaData = new ColumnMetaData();

            columnMetaData.Table = viewMetaData;

            if (resultColumn != null)
            {
                if (resultColumn.AliasClause != null)
                {
                    columnMetaData.Name = resultColumn.AliasClause.AliasName.ToString();
                }
                else if (isNotEmpty(resultColumn.ColumnNameOnly))
                {
                    columnMetaData.Name = resultColumn.ColumnNameOnly;
                }
                else
                {
                    columnMetaData.Name = resultColumn.ToString();
                }
            }
            if (!string.ReferenceEquals(aliasName, null))
            {
                columnMetaData.DisplayName = aliasName;
            }

            if (tableColumns[viewMetaData] == null)
            {
                return;
            }

            int index = tableColumns[viewMetaData].IndexOf(columnMetaData);

            if (index != -1)
            {
                columnMetaData = tableColumns[viewMetaData][index];
            }
            else
            {
                tableColumns[viewMetaData].Add(columnMetaData);
            }

            if (resultColumn != null)
            {
                ColumnMetaData[] referColumns = getRefTableColumns(resultColumn, columnImpactModel);
                for (int i = 0; i < referColumns.Length; i++)
                {
                    columnMetaData.addReferColumn(referColumns[i]);
                }
            }
        }
Exemplo n.º 5
0
        private void parseSubQueryColumnDefinition(TInsertSqlStatement insert, TSelectSqlStatement stmt, TableMetaData tableMetaData, ColumnImpactModel columnImpactModel)
        {
            if (stmt.SetOperatorType != ESetOperatorType.none)
            {
                parseSubQueryColumnDefinition(insert, stmt.LeftStmt, tableMetaData, columnImpactModel);
                parseSubQueryColumnDefinition(insert, stmt.RightStmt, tableMetaData, columnImpactModel);
            }
            else
            {
                if (insert.ColumnList != null)
                {
                    TObjectNameList items       = insert.ColumnList;
                    int             columnCount = items.size();
                    string[]        aliasNames  = new string[columnCount];

                    for (int i = 0; i < items.size(); i++)
                    {
                        aliasNames[i] = items.getObjectName(i).ToString();
                    }

                    for (int i = 0; i < columnCount; i++)
                    {
                        TResultColumn resultColumn = null;
                        if (i < stmt.ResultColumnList.size())
                        {
                            resultColumn = stmt.ResultColumnList.getResultColumn(i);
                        }
                        else
                        {
                            resultColumn = stmt.ResultColumnList.getResultColumn(stmt.ResultColumnList.size() - 1);
                        }
                        parseInsertColumnDefinition(resultColumn, tableMetaData, columnImpactModel, aliasNames[i]);
                    }
                }
            }
        }
Exemplo n.º 6
0
 private void parseSubQueryColumnDefinition(TCreateTableSqlStatement createTable, TSelectSqlStatement stmt, TableMetaData tableMetaData, ColumnImpactModel columnImpactModel)
 {
     if (stmt.SetOperatorType != ESetOperatorType.none)
     {
         parseSubQueryColumnDefinition(createTable, stmt.LeftStmt, tableMetaData, columnImpactModel);
         parseSubQueryColumnDefinition(createTable, stmt.RightStmt, tableMetaData, columnImpactModel);
     }
     else
     {
         int      columnCount = stmt.ResultColumnList.size();
         string[] aliasNames  = new string[columnCount];
         if (createTable.ColumnList != null && createTable.ColumnList.size() > 0)
         {
             columnCount = createTable.ColumnList.size();
             aliasNames  = new string[columnCount];
             TColumnDefinitionList items = createTable.ColumnList;
             for (int i = 0; i < items.size(); i++)
             {
                 aliasNames[i] = items.getColumn(i).ToString();
             }
         }
         for (int i = 0; i < columnCount; i++)
         {
             TResultColumn resultColumn = stmt.ResultColumnList.getResultColumn(i);
             parseColumnDefinition(resultColumn, tableMetaData, columnImpactModel, aliasNames[i]);
         }
     }
 }
Exemplo n.º 7
0
 private void parseSubQueryColumnDefinition(TCreateViewSqlStatement createView, TSelectSqlStatement stmt, TableMetaData viewMetaData, ColumnImpactModel columnImpactModel)
 {
     if (stmt.SetOperatorType != ESetOperatorType.none)
     {
         parseSubQueryColumnDefinition(createView, stmt.LeftStmt, viewMetaData, columnImpactModel);
         parseSubQueryColumnDefinition(createView, stmt.RightStmt, viewMetaData, columnImpactModel);
     }
     else
     {
         int      columnCount = stmt.ResultColumnList.size();
         string[] aliasNames  = new string[columnCount];
         if (createView.ViewAliasClause != null)
         {
             columnCount = createView.ViewAliasClause.ViewAliasItemList.size();
             aliasNames  = new string[columnCount];
             TViewAliasItemList items = createView.ViewAliasClause.ViewAliasItemList;
             for (int i = 0; i < items.size(); i++)
             {
                 if (items.getViewAliasItem(i).Alias != null)
                 {
                     aliasNames[i] = items.getViewAliasItem(i).Alias.ToString();
                 }
             }
         }
         for (int i = 0; i < columnCount; i++)
         {
             TResultColumn resultColumn = stmt.ResultColumnList.getResultColumn(i);
             parseColumnDefinition(resultColumn, viewMetaData, columnImpactModel, aliasNames[i]);
         }
     }
 }