public void Set(string query, SqlStatement[] statements) { if (String.IsNullOrEmpty(query)) return; SetObject(query, statements); }
public static void RegisterQuery(this IQueryContext context, SqlStatement statement) { if (statement == null) throw new ArgumentNullException("statement"); context.RegisterQuery(statement.SourceQuery, statement.ToString()); }
public PlSqlProcedureInfo(ObjectName procedureName, RoutineParameter[] parameters, SqlStatement body) : base(procedureName, parameters) { if (body == null) throw new ArgumentNullException("body"); Body = body; }
public StatementEvent(SqlStatement statement, StatementEventType eventType) { if (statement == null) throw new ArgumentNullException("statement"); Statement = statement; EventType = eventType; }
public void AddStatement(SqlStatement statement) { if (statement == null) throw new ArgumentNullException("statement"); AssertIsUserDefined(); statements.Add(statement); }
public CreateProcedureStatement(ObjectName procedureName, RoutineParameter[] parameters, SqlStatement body) { if (procedureName == null) throw new ArgumentNullException("procedureName"); if (body == null) throw new ArgumentNullException("body"); ProcedureName = procedureName; Parameters = parameters; Body = body; }
public ConditionStatement(SqlExpression condition, SqlStatement[] trueStatements, SqlStatement[] falseStatements) { if (condition == null) throw new ArgumentNullException("condition"); if (trueStatements == null) throw new ArgumentNullException("trueStatements"); ConditionExpression = condition; TrueStatements = trueStatements; FalseStatements = falseStatements; }
private ExecutionContext(ExecutionContext parent, IRequest request, SqlStatement statement) { if (request == null) throw new ArgumentNullException("request"); Parent = parent; Request = request; Statement = statement; Assertions = new SecurityAssertionRegistrar(parent != null ? parent.Assertions : null); Actions = new SecurityActionRegistrar(); }
public void SimpleConditional() { var condition = SqlExpression.Equal(SqlExpression.VariableReference("a"), SqlExpression.Constant(34)); var ifTrue = new SqlStatement[] { new DeclareVariableStatement("b", PrimitiveTypes.String()), new AssignVariableStatement(SqlExpression.VariableReference("b"), SqlExpression.Constant(21)), }; var result = AdminQuery.If(condition, ifTrue); Assert.IsNotNull(result); }
public void AddStatement(SqlStatement statement) { if (statement == null) throw new ArgumentNullException("statement"); if (TriggerInfo.TriggerType != TriggerType.Procedure) throw new ArgumentException(String.Format("The trigger '{0}' is not a PROCEDURE TRIGGER and cannot have any body.", TriggerInfo.TriggerName)); AssertStatementIsAllowed(statement); statements.Add(statement); }
public CreateFunctionStatement(ObjectName functionName, SqlType returnType, RoutineParameter[] parameters, SqlStatement body) { if (functionName == null) throw new ArgumentNullException("functionName"); if (returnType == null) throw new ArgumentNullException("returnType"); if (body == null) throw new ArgumentNullException("body"); FunctionName = functionName; ReturnType = returnType; Parameters = parameters; Body = body; }
public PlSqlFunctionInfo(ObjectName functionName, RoutineParameter[] parameters, SqlType returnType, SqlStatement body) : base(functionName, parameters,returnType, FunctionType.Static) { if (body == null) throw new ArgumentNullException("body"); // TODO: in case of RETURNS TABLE verify a select is there if (!(returnType is TabularType)) { if (!ReturnChecker.HasReturn(body)) throw new ArgumentException("The function body has no return"); } Body = body; }
protected virtual SqlStatement VisitCondition(ConditionStatement statement) { var trueStatements = new SqlStatement[statement.TrueStatements.Length]; for (int i = 0; i < trueStatements.Length; i++) { trueStatements[i] = VisitStatement(statement.TrueStatements[i]); } var falseStatements = statement.FalseStatements; if (falseStatements != null) { for (int i = 0; i < falseStatements.Length; i++) { falseStatements[i] = VisitStatement(falseStatements[i]); } } return new ConditionStatement(statement.ConditionExpression, trueStatements); }
public bool TryGet(string query, out SqlStatement[] statements) { if (String.IsNullOrEmpty(query)) { statements = null; return false; } object obj; if (!TryGetObject(query, out obj)) { statements = null; return false; } statements = (SqlStatement[]) obj; return true; }
public ConditionalStatement(SqlExpression condition, SqlStatement @else) : this(condition, null, @else) { }
private void AssertAllowedObject(SqlStatement obj) { AssertPlSqlStatement(obj); AssertNotLoopControl(obj); }
public void AddStatement(SqlStatement statement) { // TODO: make further checks, such as if a labeled statement with // the same label already exists statements.Add(statement); }
private StatementContext NewBlock(SqlStatement statement) { return(new StatementContext(this, statement.StatementName, statement)); }
public StatementContext(IContext parent, SqlStatement statement) : base(parent, KnownScopes.Statement) { Statement = statement ?? throw new ArgumentNullException(nameof(statement)); Result = new EmptyStatementResult(); }
public CreateProcedureStatement(ObjectName procedureName, SqlStatement body) : this(procedureName, null, body) { }
protected virtual SqlStatement VisitStatement(SqlStatement statement) { if (statement == null) return null; // CREATE if (statement is CreateTableStatement) return VisitCreateTable((CreateTableStatement) statement); if (statement is CreateViewStatement) return VisitCreateView((CreateViewStatement) statement); if (statement is CreateSchemaStatement) return VisitCreateSchema((CreateSchemaStatement) statement); if (statement is CreateSequenceStatement) return VisitCreateSequence((CreateSequenceStatement) statement); if (statement is CreateTriggerStatement) return VisitCreateTrigger((CreateTriggerStatement) statement); if (statement is CreateCallbackTriggerStatement) return VisitCreateCallbackTrigger((CreateCallbackTriggerStatement) statement); if (statement is CreateProcedureTriggerStatement) return VisitCreateProcedureTrigger((CreateProcedureTriggerStatement) statement); if (statement is CreateUserStatement) return VisitCreateUser((CreateUserStatement) statement); if (statement is CreateRoleStatement) return VisitCreateRole((CreateRoleStatement) statement); if (statement is CreateProcedureStatement) return VisitCreateProcedure((CreateProcedureStatement) statement); if (statement is CreateExternalProcedureStatement) return VisitCreateExternProcedure((CreateExternalProcedureStatement) statement); if (statement is CreateFunctionStatement) return VisitCreateFunction((CreateFunctionStatement) statement); if (statement is CreateExternalFunctionStatement) return VisitCreateExternFunction((CreateExternalFunctionStatement) statement); // DROP if (statement is DropViewStatement) return VisitDropView((DropViewStatement) statement); if (statement is DropTableStatement) return VisitDropTable((DropTableStatement) statement); if (statement is DropCallbackTriggersStatement) return VisitDropCallbackTrigger((DropCallbackTriggersStatement) statement); if (statement is DropSequenceStatement) return VisitDropSequence((DropSequenceStatement) statement); if (statement is DropProcedureStatement) return VisitDropProcedure((DropProcedureStatement) statement); if (statement is DropFunctionStatement) return VisitDropFunction((DropFunctionStatement) statement); if (statement is DropRoleStatement) return VisitDropRole((DropRoleStatement) statement); if (statement is DropUserStatement) return VisitDropUser((DropUserStatement) statement); if (statement is DropTriggerStatement) return VisitDropTrigger((DropTriggerStatement) statement); if (statement is DropTypeStatement) return VisitDropType((DropTypeStatement) statement); // ALTER if (statement is AlterTableStatement) return VisitAlterTable((AlterTableStatement) statement); if (statement is AlterUserStatement) return VisitAlterUser((AlterUserStatement) statement); if (statement is GrantPrivilegesStatement) return VisitGrantPrivilege((GrantPrivilegesStatement) statement); if (statement is GrantRoleStatement) return VisitGrantRole((GrantRoleStatement) statement); if (statement is RevokePrivilegesStatement) return VisitRevokePrivilege((RevokePrivilegesStatement) statement); // TODO: Revoke role statement // DECLARE if (statement is DeclareCursorStatement) return VisitDeclareCursor((DeclareCursorStatement) statement); if (statement is DeclareVariableStatement) return VisitDeclareVariable((DeclareVariableStatement) statement); if (statement is DeclareExceptionStatement) return VisitDeclareException((DeclareExceptionStatement) statement); if (statement is CallStatement) return VisitCall((CallStatement) statement); if (statement is InsertStatement) return VisitInsert((InsertStatement) statement); if (statement is InsertSelectStatement) return VisitInsertSelect((InsertSelectStatement) statement); if (statement is SelectStatement) return VisitSelect((SelectStatement) statement); if (statement is SelectIntoStatement) return VisitSelectInto((SelectIntoStatement) statement); if (statement is DeleteStatement) return VisitDelete((DeleteStatement) statement); if (statement is UpdateStatement) return VisitUpdate((UpdateStatement) statement); if (statement is UpdateFromCursorStatement) return VisitUpdateFromCursor((UpdateFromCursorStatement) statement); if (statement is ShowStatement) return VisitShow((ShowStatement) statement); // Cursors if (statement is OpenStatement) return VisitOpen((OpenStatement) statement); if (statement is FetchStatement) return VisitFetch((FetchStatement) statement); if (statement is CloseStatement) return VisitClose((CloseStatement) statement); // Session Commands if (statement is CommitStatement) return VisitCommit((CommitStatement) statement); if (statement is RollbackStatement) return VisitRollback((RollbackStatement) statement); if (statement is SetStatement) return VisitSet((SetStatement) statement); if (statement is AssignVariableStatement) return VisitAssignVariable((AssignVariableStatement) statement); // Blocks if (statement is CodeBlockStatement) return VisitCodeBlock((CodeBlockStatement) statement); // In-Block if (statement is LoopControlStatement) return VisitLoopControl((LoopControlStatement) statement); if (statement is ReturnStatement) return VisitReturn((ReturnStatement) statement); if (statement is GoToStatement) return VisitGoTo((GoToStatement) statement); if (statement is RaiseStatement) return VisitRaise((RaiseStatement) statement); if (statement is ConditionStatement) return VisitCondition((ConditionStatement) statement); if (statement is IVisitableStatement) return ((IVisitableStatement) statement).Accept(this); return statement; }
public ExecutionContext(IRequest request, SqlStatement statement) : this(null, request, statement) { }
private void AssertStatementIsAllowed(SqlStatement statement) { // TODO: validate this statement }
public bool Verify(SqlStatement statement) { VisitStatement(statement); return returnFound; }
public BlockStatementContext(IContext parent, string name, SqlStatement statement) : base(parent, name, statement) { Init(); }
public ExecutionContext NewBlock(SqlStatement statement) { return new ExecutionContext(this, Request.CreateBlock(), statement); }
public ConditionStatement(SqlExpression condition, SqlStatement[] trueStatements) : this(condition, trueStatements, new SqlStatement[0]) { }
public string Format(SqlStatement statement) { VisitStatement(statement); return builder.ToString(); }
protected virtual SqlStatement VisitStatement(SqlStatement statement) { if (statement == null) { return(null); } // CREATE if (statement is CreateTableStatement) { return(VisitCreateTable((CreateTableStatement)statement)); } if (statement is CreateViewStatement) { return(VisitCreateView((CreateViewStatement)statement)); } if (statement is CreateSchemaStatement) { return(VisitCreateSchema((CreateSchemaStatement)statement)); } if (statement is CreateSequenceStatement) { return(VisitCreateSequence((CreateSequenceStatement)statement)); } if (statement is CreateTriggerStatement) { return(VisitCreateTrigger((CreateTriggerStatement)statement)); } if (statement is CreateCallbackTriggerStatement) { return(VisitCreateCallbackTrigger((CreateCallbackTriggerStatement)statement)); } if (statement is CreateProcedureTriggerStatement) { return(VisitCreateProcedureTrigger((CreateProcedureTriggerStatement)statement)); } if (statement is CreateUserStatement) { return(VisitCreateUser((CreateUserStatement)statement)); } if (statement is CreateRoleStatement) { return(VisitCreateRole((CreateRoleStatement)statement)); } if (statement is CreateProcedureStatement) { return(VisitCreateProcedure((CreateProcedureStatement)statement)); } if (statement is CreateExternalProcedureStatement) { return(VisitCreateExternProcedure((CreateExternalProcedureStatement)statement)); } if (statement is CreateFunctionStatement) { return(VisitCreateFunction((CreateFunctionStatement)statement)); } if (statement is CreateExternalFunctionStatement) { return(VisitCreateExternFunction((CreateExternalFunctionStatement)statement)); } // DROP if (statement is DropViewStatement) { return(VisitDropView((DropViewStatement)statement)); } if (statement is DropTableStatement) { return(VisitDropTable((DropTableStatement)statement)); } if (statement is DropCallbackTriggersStatement) { return(VisitDropCallbackTrigger((DropCallbackTriggersStatement)statement)); } if (statement is DropSequenceStatement) { return(VisitDropSequence((DropSequenceStatement)statement)); } if (statement is DropProcedureStatement) { return(VisitDropProcedure((DropProcedureStatement)statement)); } if (statement is DropFunctionStatement) { return(VisitDropFunction((DropFunctionStatement)statement)); } if (statement is DropRoleStatement) { return(VisitDropRole((DropRoleStatement)statement)); } if (statement is DropUserStatement) { return(VisitDropUser((DropUserStatement)statement)); } if (statement is DropTriggerStatement) { return(VisitDropTrigger((DropTriggerStatement)statement)); } if (statement is DropTypeStatement) { return(VisitDropType((DropTypeStatement)statement)); } // ALTER if (statement is AlterTableStatement) { return(VisitAlterTable((AlterTableStatement)statement)); } if (statement is AlterUserStatement) { return(VisitAlterUser((AlterUserStatement)statement)); } if (statement is GrantPrivilegesStatement) { return(VisitGrantPrivilege((GrantPrivilegesStatement)statement)); } if (statement is GrantRoleStatement) { return(VisitGrantRole((GrantRoleStatement)statement)); } if (statement is RevokePrivilegesStatement) { return(VisitRevokePrivilege((RevokePrivilegesStatement)statement)); } // TODO: Revoke role statement // DECLARE if (statement is DeclareCursorStatement) { return(VisitDeclareCursor((DeclareCursorStatement)statement)); } if (statement is DeclareVariableStatement) { return(VisitDeclareVariable((DeclareVariableStatement)statement)); } if (statement is DeclareExceptionStatement) { return(VisitDeclareException((DeclareExceptionStatement)statement)); } if (statement is CallStatement) { return(VisitCall((CallStatement)statement)); } if (statement is InsertStatement) { return(VisitInsert((InsertStatement)statement)); } if (statement is InsertSelectStatement) { return(VisitInsertSelect((InsertSelectStatement)statement)); } if (statement is SelectStatement) { return(VisitSelect((SelectStatement)statement)); } if (statement is SelectIntoStatement) { return(VisitSelectInto((SelectIntoStatement)statement)); } if (statement is DeleteStatement) { return(VisitDelete((DeleteStatement)statement)); } if (statement is UpdateStatement) { return(VisitUpdate((UpdateStatement)statement)); } if (statement is UpdateFromCursorStatement) { return(VisitUpdateFromCursor((UpdateFromCursorStatement)statement)); } if (statement is ShowStatement) { return(VisitShow((ShowStatement)statement)); } // Cursors if (statement is OpenStatement) { return(VisitOpen((OpenStatement)statement)); } if (statement is FetchStatement) { return(VisitFetch((FetchStatement)statement)); } if (statement is CloseStatement) { return(VisitClose((CloseStatement)statement)); } // Session Commands if (statement is CommitStatement) { return(VisitCommit((CommitStatement)statement)); } if (statement is RollbackStatement) { return(VisitRollback((RollbackStatement)statement)); } if (statement is SetStatement) { return(VisitSet((SetStatement)statement)); } if (statement is AssignVariableStatement) { return(VisitAssignVariable((AssignVariableStatement)statement)); } // Blocks if (statement is CodeBlockStatement) { return(VisitCodeBlock((CodeBlockStatement)statement)); } // In-Block if (statement is LoopControlStatement) { return(VisitLoopControl((LoopControlStatement)statement)); } if (statement is ReturnStatement) { return(VisitReturn((ReturnStatement)statement)); } if (statement is GoToStatement) { return(VisitGoTo((GoToStatement)statement)); } if (statement is RaiseStatement) { return(VisitRaise((RaiseStatement)statement)); } if (statement is ConditionStatement) { return(VisitCondition((ConditionStatement)statement)); } if (statement is IVisitableStatement) { return(((IVisitableStatement)statement).Accept(this)); } return(statement); }
public CreateFunctionStatement(ObjectName functionName, SqlType returnType, SqlStatement body) : this(functionName, returnType, null, body) { }
private void Dispose(bool disposing) { if (disposing) { if (Assertions != null) Assertions.Dispose(); if (Actions != null) (Actions as IDisposable).Dispose(); } Statement = null; Parent = null; Request = null; Result = null; Cursor = null; Assertions = null; Actions = null; }
public StatementContext(IContext parent, SqlStatement statement) : this(parent, statement.StatementName, statement) { }
private SqlStatement FindInTree(SqlStatement root, string label) { var statement = root; while (statement != null) { if (statement is CodeBlockStatement) { var block = (CodeBlockStatement) statement; if (String.Equals(label, block.Label)) return statement; foreach (var child in block.Statements) { var found = FindInTree(child, label); if (found != null) return found; } } statement = statement.Parent; } return null; }
public static bool HasReturn(SqlStatement statement) { var visitor = new ReturnChecker(); return visitor.Verify(statement); }