//public virtual void Visit(WCreateProcedureStatement node) //{ // node.AcceptChildren(this); //} public virtual void Visit(WWhileStatement node) { node.AcceptChildren(this); }
private WSqlStatement ParseStatement(TSqlStatement tsqlStat) { WSqlStatement wstat; switch (tsqlStat.GetType().Name) { case "SelectStatement": { var sel = tsqlStat as SelectStatement; wstat = ParseSelectQueryStatement(sel.QueryExpression); break; } case "CreateFunctionStatement": { var creat = tsqlStat as CreateFunctionStatement; var wcreat = new WCreateFunctionStatement { Parameters = creat.Parameters, ReturnType = creat.ReturnType, StatementList = new List<WSqlStatement>(creat.StatementList.Statements.Count), FirstTokenIndex = creat.FirstTokenIndex, LastTokenIndex = creat.LastTokenIndex, Name = ParseSchemaObjectName(creat.Name) }; foreach (var stat in creat.StatementList.Statements) { wcreat.StatementList.Add(ParseStatement(stat)); } wstat = wcreat; break; } case "BeginEndBlockStatement": { var bestat = tsqlStat as BeginEndBlockStatement; var wbestat = new WBeginEndBlockStatement { StatementList = new List<WSqlStatement>(bestat.StatementList.Statements.Count), FirstTokenIndex = bestat.FirstTokenIndex, LastTokenIndex = bestat.LastTokenIndex }; foreach (var pstat in bestat.StatementList.Statements.Select(ParseStatement)) { wbestat.StatementList.Add(pstat); } wstat = wbestat; break; } case "UpdateStatement": { var upd = tsqlStat as UpdateStatement; wstat = ParseUpdateStatement(upd.UpdateSpecification); break; } case "DeleteStatement": { var del = tsqlStat as DeleteStatement; wstat = ParseDeleteStatement(del.DeleteSpecification); break; } case "InsertStatement": { var ins = tsqlStat as InsertStatement; wstat = ParseInsertStatement(ins.InsertSpecification); break; } case "CreateTableStatement": { var cts = tsqlStat as CreateTableStatement; var wcstat = new WCreateTableStatement { FirstTokenIndex = cts.FirstTokenIndex, LastTokenIndex = cts.LastTokenIndex, Definition = ParseTableDefinition(cts.Definition), SchemaObjectName = ParseSchemaObjectName(cts.SchemaObjectName), }; wstat = wcstat; break; } case "DropTableStatement": { var dts = tsqlStat as DropTableStatement; var wdstat = new WDropTableStatement { FirstTokenIndex = dts.FirstTokenIndex, LastTokenIndex = dts.LastTokenIndex, }; if (dts.Objects != null) { wdstat.Objects = new List<WSchemaObjectName>(); foreach (var obj in dts.Objects) { wdstat.Objects.Add(ParseSchemaObjectName(obj)); } } wstat = wdstat; break; } case "CreateViewStatement": { var cvs = tsqlStat as CreateViewStatement; var wcvs = new WCreateViewStatement { Columns = cvs.Columns, FirstTokenIndex = cvs.FirstTokenIndex, LastTokenIndex = cvs.LastTokenIndex, SchemaObjectName = ParseSchemaObjectName(cvs.SchemaObjectName), SelectStatement = ParseSelectQueryStatement(cvs.SelectStatement.QueryExpression), ViewOptions = cvs.ViewOptions, WithCheckOption = cvs.WithCheckOption }; wstat = wcvs; break; } case "BeginTransactionStatement": { var beginTranStat = tsqlStat as BeginTransactionStatement; wstat = new WBeginTransactionStatement { Name = ParseIdentifierOrValueExpression(beginTranStat.Name), Distributed = beginTranStat.Distributed, FirstTokenIndex = beginTranStat.FirstTokenIndex, LastTokenIndex = beginTranStat.LastTokenIndex }; break; } case "CommitTransactionStatement": { var commitTranStat = tsqlStat as CommitTransactionStatement; wstat = new WCommitTransactionStatement { Name = ParseIdentifierOrValueExpression(commitTranStat.Name), FirstTokenIndex = commitTranStat.FirstTokenIndex, LastTokenIndex = commitTranStat.LastTokenIndex }; break; } case "RollbackTransactionStatement": { var rollbackTranStat = tsqlStat as RollbackTransactionStatement; wstat = new WRollbackTransactionStatement { Name = ParseIdentifierOrValueExpression(rollbackTranStat.Name), FirstTokenIndex = rollbackTranStat.FirstTokenIndex, LastTokenIndex = rollbackTranStat.LastTokenIndex }; break; } case "SaveTransactionStatement": { var saveTranStat = tsqlStat as SaveTransactionStatement; wstat = new WSaveTransactionStatement { Name = ParseIdentifierOrValueExpression(saveTranStat.Name), FirstTokenIndex = saveTranStat.FirstTokenIndex, LastTokenIndex = saveTranStat.LastTokenIndex }; break; } case "CreateProcedureStatement": { var creat = tsqlStat as CreateProcedureStatement; var wcreat = new WCreateProcedureStatement { IsForReplication = creat.IsForReplication, Parameters = creat.Parameters, StatementList = new List<WSqlStatement>(creat.StatementList.Statements.Count), FirstTokenIndex = creat.FirstTokenIndex, LastTokenIndex = creat.LastTokenIndex, ProcedureReference = new WProcedureReference { Name = ParseSchemaObjectName(creat.ProcedureReference.Name), Number = creat.ProcedureReference.Number } }; foreach (var stat in creat.StatementList.Statements) { wcreat.StatementList.Add(ParseStatement(stat)); } wstat = wcreat; break; } case "DropProcedureStatement": { var dts = tsqlStat as DropProcedureStatement; var wdstat = new WDropProcedureStatement { FirstTokenIndex = dts.FirstTokenIndex, LastTokenIndex = dts.LastTokenIndex, }; if (dts.Objects != null) { wdstat.Objects = new List<WSchemaObjectName>(); foreach (var obj in dts.Objects) { wdstat.Objects.Add(ParseSchemaObjectName(obj)); } } wstat = wdstat; break; } case "WhileStatement": { var bestat = tsqlStat as WhileStatement; var wbestat = new WWhileStatement() { Predicate = ParseBooleanExpression(bestat.Predicate), Statement = ParseStatement(bestat.Statement), FirstTokenIndex = bestat.FirstTokenIndex, LastTokenIndex = bestat.LastTokenIndex }; wstat = wbestat; break; } case "DeclareVariableStatement": { var dvstat = tsqlStat as DeclareVariableStatement; wstat = new WDeclareVariableStatement { Statement = dvstat }; break; } default: { wstat = new WSqlUnknownStatement(tsqlStat) { FirstTokenIndex = tsqlStat.FirstTokenIndex, LastTokenIndex = tsqlStat.LastTokenIndex }; break; } } return wstat; }