Exemplo n.º 1
0
        private static void ParseColumn(Parser parser, PgDatabase database)
        {
            var columnName = parser.ParseIdentifier();
            var objectName = ParserUtils.GetObjectName(columnName);
            var tableName  = ParserUtils.GetSecondObjectName(columnName);
            var schemaName = ParserUtils.GetThirdObjectName(columnName);
            var schema     = database.GetSchema(schemaName);

            var table = schema.GetTable(tableName);

            if (table == null)
            {
                var view = schema.GetView(tableName);
                parser.Expect("IS");

                var comment = GetComment(parser);

                if (comment == null)
                {
                    view.RemoveColumnComment(objectName);
                }
                else
                {
                    view.AddColumnComment(objectName, comment);
                }
                parser.Expect(";");
            }
            else
            {
                var column = table.GetColumn(objectName);

                if (column == null)
                {
                    throw new ParserException(string.Format(Resources.CannotFindColumnInTable, columnName, table.Name));
                }

                parser.Expect("IS");
                column.Comment = GetComment(parser);
                parser.Expect(";");
            }
        }