Esempio n. 1
0
 public static TableColumn VisitAlterByAddColumnContext(UidContext uidContext, DataTypeContext dataTypeContext)
 {
     return(new TableColumn
     {
         ColumnName = GetSinglePartName(uidContext.GetText(), "Column"),
         DataType = dataTypeContext.GetText()
     });
 }
Esempio n. 2
0
        public override TableName ParseTableName(ParserRuleContext node, bool strict = false)
        {
            TableName tableName = null;

            if (node != null)
            {
                if (node is TableNameContext tn)
                {
                    tableName = new TableName(tn);
                    tableName.Tokens.Add(new TokenInfo(tn.fullId())
                    {
                        Type = TokenType.TableName
                    });
                }
                else if (node is AtomTableItemContext ati)
                {
                    tableName = new TableName(ati);

                    tableName.Name = new TokenInfo(ati.tableName());

                    UidContext alias = ati.uid();

                    if (alias != null)
                    {
                        tableName.Alias = new TokenInfo(alias);
                    }
                }
                else if (node is TableSourceBaseContext tsb)
                {
                    return(this.ParseTableName(tsb.tableSourceItem()));
                }
                else if (node is TableSourceContext ts)
                {
                    return(this.ParseTableName(ts.children.FirstOrDefault(item => item is TableSourceBaseContext) as ParserRuleContext));
                }
                else if (node is SingleUpdateStatementContext update)
                {
                    tableName = new TableName(update);

                    tableName.Name = new TokenInfo(update.tableName());

                    UidContext alias = update.uid();

                    if (alias != null)
                    {
                        tableName.Alias = new TokenInfo(alias);
                    }
                }

                if (!strict && tableName == null)
                {
                    tableName = new TableName(node);
                }
            }

            return(tableName);
        }
Esempio n. 3
0
        public static QsiAliasNode CreateAliasNode(UidContext context)
        {
            var node = new QsiAliasNode
            {
                Name = IdentifierVisitor.VisitUid(context)
            };

            PrimarSqlTree.PutContextSpan(node, context);

            return(node);
        }
Esempio n. 4
0
        public List <FromItem> ParseTableSources(TableSourcesContext node)
        {
            List <FromItem> fromItems = new List <FromItem>();

            TableSourceContext[] tables = node.tableSource();

            foreach (TableSourceContext table in tables)
            {
                if (table is TableSourceBaseContext tb)
                {
                    TableSourceItemContext tsi = tb.tableSourceItem();
                    FromItem fromItem          = new FromItem();

                    if (tsi is SubqueryTableItemContext subquery)
                    {
                        fromItem.SubSelectStatement = this.ParseSelectStatement(subquery.selectStatement());

                        UidContext uid = subquery.uid();

                        if (uid != null)
                        {
                            fromItem.Alias = new TokenInfo(uid)
                            {
                                Type = TokenType.Alias
                            };
                        }
                    }
                    else
                    {
                        TableName tableName = this.ParseTableName(tsi);

                        fromItem.TableName = tableName;

                        JoinPartContext[] joins = tb.joinPart();

                        if (joins != null && joins.Length > 0)
                        {
                            foreach (JoinPartContext join in joins)
                            {
                                JoinItem joinItem = this.ParseJoin(join);

                                fromItem.JoinItems.Add(joinItem);
                            }
                        }
                    }

                    fromItems.Add(fromItem);
                }
            }

            return(fromItems);
        }
Esempio n. 5
0
        public static QsiIdentifier VisitUid(UidContext context)
        {
            switch (context.children[0])
            {
            case SimpleIdContext simpleId:
                return(VisitSimpleId(simpleId));

            case ITerminalNode terminalNode:
                return(VisitTerminalNode(terminalNode));
            }

            return(new QsiIdentifier(context.GetText(), false));
        }
Esempio n. 6
0
        public override AnalyseResult AnalyseProcedure(string content)
        {
            SqlSyntaxError error = null;

            DdlStatementContext ddlStatement = this.GetDdlStatementContext(content, out error);

            AnalyseResult result = new AnalyseResult()
            {
                Error = error
            };

            if (!result.HasError && ddlStatement != null)
            {
                RoutineScript script = new RoutineScript()
                {
                    Type = RoutineType.PROCEDURE
                };

                CreateProcedureContext proc = ddlStatement.createProcedure();

                if (proc != null)
                {
                    #region Name
                    this.SetScriptName(script, proc.fullId());
                    #endregion

                    #region Parameters
                    ProcedureParameterContext[] parameters = proc.procedureParameter();

                    if (parameters != null)
                    {
                        foreach (ProcedureParameterContext parameter in parameters)
                        {
                            Parameter parameterInfo = new Parameter();

                            UidContext uid = parameter.uid();

                            parameterInfo.Name = new TokenInfo(uid)
                            {
                                Type = TokenType.ParameterName
                            };

                            parameterInfo.DataType = new TokenInfo(parameter.dataType().GetText())
                            {
                                Type = TokenType.DataType
                            };

                            this.SetParameterType(parameterInfo, parameter.children);

                            script.Parameters.Add(parameterInfo);
                        }
                    }
                    #endregion

                    #region Body

                    this.SetScriptBody(script, proc.routineBody());

                    #endregion
                }

                this.ExtractFunctions(script, ddlStatement);

                result.Script = script;
            }

            return(result);
        }
	public UidContext uid() {
		UidContext _localctx = new UidContext(Context, State);
		EnterRule(_localctx, 172, RULE_uid);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 1795; k_uid();
			State = 1800;
			ErrorHandler.Sync(this);
			_la = TokenStream.La(1);
			while (_la==SCOL) {
				{
				{
				State = 1796; Match(SCOL);
				State = 1797; other_param();
				}
				}
				State = 1802;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
			}
			State = 1803; Match(COL);
			State = 1804; text();
			State = 1805; Match(CRLF);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}