17 using System.ComponentModel;
21 namespace Deveel.Data.Sql.Parser {
23 public override string Dialect {
24 get {
return "SQL-99"; }
28 var root =
new NonTerminal(
"root");
36 var block = PlSqlBlock();
37 var blockList =
new NonTerminal(
"block_list");
38 blockList.Rule = MakePlusRule(blockList, block);
40 root.Rule = SqlStatementList() + Eof |
45 var statementEnd =
new NonTerminal(
"statement_end");
46 statementEnd.Rule = Empty |
";";
51 var orReplaceOpt =
new NonTerminal(
"or_replace_opt");
52 orReplaceOpt.Rule = Empty | OR + REPLACE;
59 commandList.Rule = MakePlusRule(commandList, SqlStatement());
65 var sqlStatement =
new NonTerminal(
"sql_statement");
67 var command =
new NonTerminal(
"command");
69 sqlStatement.Rule = command + StatementEnd();
72 VariableDeclaration() |
96 var command =
new NonTerminal(
"declare");
98 command.Rule = DeclareCursor() |
106 var declareCursor =
new NonTerminal(
"cursor_declaration", typeof(
DeclareCursorNode));
107 var insensitiveOpt =
new NonTerminal(
"insensitive_opt");
108 var scrollOpt =
new NonTerminal(
"scroll_opt");
109 var cursorArgsOpt =
new NonTerminal(
"cursor_args_opt");
110 var cursorArgs =
new NonTerminal(
"cursor_args");
112 declareCursor.Rule = Key(
"CURSOR") + Identifier + cursorArgsOpt +
113 insensitiveOpt + scrollOpt +
114 Key(
"IS") + SqlQueryExpression();
115 cursorArgsOpt.Rule = Empty |
"(" + cursorArgs +
")";
116 cursorArgs.Rule = MakePlusRule(cursorArgs, Comma, cursorArg);
117 cursorArg.Rule = Identifier + DataType();
118 insensitiveOpt.Rule = Empty | Key(
"INSENSITIVE");
119 scrollOpt.Rule = Empty | Key(
"SCROLL");
120 return declareCursor;
124 var declareCuror =
new NonTerminal(
"declare_cursor");
125 declareCuror.Rule = Key(
"DECLARE") + CursorDeclaration();
130 var declareVariable =
new NonTerminal(
"variable_declaration", typeof(
DeclareVariableNode));
131 var constantOpt =
new NonTerminal(
"constant_opt");
132 var varNotNullOpt =
new NonTerminal(
"var_not_null_opt");
133 var varDefaultOpt =
new NonTerminal(
"var_default_opt");
134 var varDefaultAssign =
new NonTerminal(
"var_default_assign");
136 declareVariable.Rule = Identifier + constantOpt + DataType() + varNotNullOpt + varDefaultOpt;
137 constantOpt.Rule = Empty | Key(
"CONSTANT");
138 varNotNullOpt.Rule = Empty | Key(
"NOT") + Key(
"NULL");
139 varDefaultOpt.Rule = Empty | varDefaultAssign + SqlExpression();
140 varDefaultAssign.Rule =
":=" | Key(
"DEFAULT");
142 return declareVariable;
147 declareException.Rule = Identifier + Key(
"EXCEPTION");
148 return declareException;
152 var command =
new NonTerminal(
"declare_exception");
153 command.Rule = Key(
"DECLARE") + ExceptionDeclaration();
158 var declareVariable =
new NonTerminal(
"declare_variable");
159 declareVariable.Rule = Key(
"DECLARE") + VariableDeclaration();
160 return declareVariable;
165 var argsOpt =
new NonTerminal(
"args_opt");
166 var argList =
new NonTerminal(
"arg_list");
168 openCommand.Rule = Key(
"OPEN") + Identifier + argsOpt;
169 argsOpt.Rule = Empty |
"(" + argList +
")";
170 argList.Rule = MakePlusRule(argList, Comma, SqlExpression());
176 closeCommand.Rule = Key(
"CLOSE") + Identifier;
182 var directionOpt =
new NonTerminal(
"direction_opt");
183 var fetchDirection =
new NonTerminal(
"fetch_direction");
184 var identOpt =
new NonTerminal(
"ident_opt");
185 identOpt.Flags = TermFlags.IsTransient;
186 var fromOpt =
new NonTerminal(
"from_opt");
187 var intoOpt =
new NonTerminal(
"into_opt");
189 fetchCommand.Rule = Key(
"FETCH") + directionOpt + fromOpt + identOpt + intoOpt;
190 directionOpt.Rule = Empty | fetchDirection;
191 identOpt.Rule = Empty | Identifier;
192 fetchDirection.Rule = Key(
"NEXT") |
196 Key(
"ABSOLUTE") + SqlExpression() |
197 Key(
"RELATIVE") + SqlExpression();
198 fromOpt.Rule = Empty | Key(
"FROM");
199 intoOpt.Rule = Empty | Key(
"INTO") + SqlExpression();
204 var sqlStatement =
new NonTerminal(
"sql_statement");
206 sqlStatement.Rule = Select() |
221 var plsqlBlock =
new NonTerminal(
"plsql_block", typeof(
PlSqlBlockNode));
222 var labelStatement =
new NonTerminal(
"plsql_label", typeof(
LabelNode));
223 var labelStatementOpt =
new NonTerminal(
"plsql_label_opt");
224 var declareStatementOpt =
new NonTerminal(
"declare_statement_opt");
225 var declareSpec =
new NonTerminal(
"declare_spec");
226 var declareCommand =
new NonTerminal(
"declare_command");
227 var declareSpecList =
new NonTerminal(
"declare_spec_list");
229 var sqlStatementList =
new NonTerminal(
"sql_statement_list");
230 var declarePragma =
new NonTerminal(
"declare_pragma", typeof(
DeclarePragmaNode));
231 var exceptionBlockOpt =
new NonTerminal(
"exception_block_opt");
232 var exceptionBlock =
new NonTerminal(
"exception_block");
234 var exceptionHandlerList =
new NonTerminal(
"exception_handler_list");
235 var exceptionNames =
new NonTerminal(
"exception_names");
236 var handledExceptions =
new NonTerminal(
"handled_exceptions");
237 var whenOpt =
new NonTerminal(
"when_opt");
239 whenOpt.Rule = Empty | Key(
"WHEN") + SqlExpression();
241 #region PL/SQL Statement
243 var plsqlStatement =
new NonTerminal(
"plsql_statement");
244 var plsqlCommand =
new NonTerminal(
"plsql_command");
246 var plsqlStatementList =
new NonTerminal(
"plsql_statement_list");
247 plsqlStatementList.Rule = MakePlusRule(plsqlStatementList, plsqlStatement);
251 var conditionalStatement =
new NonTerminal(
"conditional_statement");
252 var conditionalElsifList =
new NonTerminal(
"conditional_elsif_list");
253 var conditionalElsif =
new NonTerminal(
"conditional_elsif");
254 var conditionalElseOpt =
new NonTerminal(
"conditional_else_opt");
256 conditionalStatement.Rule = IF + SqlExpression() + THEN + plsqlStatementList +
257 conditionalElsifList +
260 conditionalElsifList.Rule = MakeStarRule(conditionalElsifList, conditionalElsif);
261 conditionalElsif.Rule = ELSIF + SqlExpression() + THEN + plsqlStatementList;
262 conditionalElseOpt.Rule = Empty | ELSE + plsqlStatementList;
268 var loopStatement =
new NonTerminal(
"loop_statement");
269 var loopLabelOpt =
new NonTerminal(
"loop_label_opt");
270 var loopHeadOpt =
new NonTerminal(
"loop_head_opt");
271 var loopHead =
new NonTerminal(
"loop_head");
272 var whileLoop =
new NonTerminal(
"while_loop");
273 var forLoop =
new NonTerminal(
"for_loop");
274 var numericLoopParam =
new NonTerminal(
"numeric_loop_param");
275 var reverseOpt =
new NonTerminal(
"reverse_opt");
276 var forLoopParam =
new NonTerminal(
"for_loop_param");
277 var cursorLoopParam =
new NonTerminal(
"cursor_loop_param");
278 var loopBodyList =
new NonTerminal(
"loop_body_list");
279 var loopBody =
new NonTerminal(
"loop_body");
280 var loopControlStatement =
new NonTerminal(
"loop_control_statement");
281 var labelOpt =
new NonTerminal(
"label_opt");
283 labelOpt.Rule = Empty | Identifier;
287 var exitStatement =
new NonTerminal(
"exit_statement", typeof(
ExitStatementNode));
289 exitStatement.Rule = Key(
"EXIT") + labelOpt + whenOpt + StatementEnd();
297 breakStatement.Rule = Key(
"BREAK") + labelOpt + whenOpt + StatementEnd();
305 continueStatement.Rule = Key(
"CONTINUE") + labelOpt + whenOpt + StatementEnd();
309 loopStatement.Rule = loopLabelOpt + loopHeadOpt + Key(
"LOOP") + loopBodyList + Key(
"LOOP") + Key(
"END");
310 loopLabelOpt.Rule = Empty | Identifier;
311 loopBody.Rule = plsqlStatement | loopControlStatement;
312 loopBodyList.Rule = MakePlusRule(loopBodyList, loopBody);
313 loopControlStatement.Rule = exitStatement |
316 loopHeadOpt.Rule = Empty | loopHead;
317 loopHead.Rule = whileLoop | forLoop;
318 whileLoop.Rule = Key(
"WHILE") + SqlExpression();
319 forLoop.Rule = Key(
"FOR") + forLoopParam;
320 forLoopParam.Rule = numericLoopParam | cursorLoopParam;
321 numericLoopParam.Rule = Identifier + Key(
"IN") + reverseOpt + SqlExpression() +
".." + SqlExpression();
322 reverseOpt.Rule = Empty | Key(
"REVERSE");
323 cursorLoopParam.Rule = Identifier + Key(
"IN") +
ObjectName();
330 var exceptionNameOpt =
new NonTerminal(
"exception_name_opt");
331 raiseStatement.Rule = Key(
"RAISE") + exceptionNameOpt;
332 exceptionNameOpt.Rule = Empty | Identifier;
339 returnStatement.Rule = Key(
"RETURN") + SqlExpression();
345 var gotoStatement =
new NonTerminal(
"goto_statement", typeof(
GotoStatementNode));
346 gotoStatement.Rule = Key(
"GOTO") + StringLiteral;
350 plsqlStatement.Rule = plsqlCommand + StatementEnd();
351 plsqlCommand.Rule = NestedSqlStatement() |
356 conditionalStatement;
360 plsqlBlock.Rule = labelStatementOpt + declareStatementOpt + plsqlCodeBlock;
361 labelStatementOpt.Rule = Empty | labelStatement;
362 labelStatement.Rule =
"<<" + Identifier +
">>";
363 declareStatementOpt.Rule = Empty | DECLARE + declareSpecList;
364 declareSpecList.Rule = MakePlusRule(declareSpecList, declareSpec);
365 declareCommand.Rule = VariableDeclaration() |
366 ExceptionDeclaration() |
369 declareSpec.Rule = declareCommand + StatementEnd();
370 declarePragma.Rule = Key(
"PRAGMA") + Key(
"EXCEPTION_INIT") +
"(" + StringLiteral +
"," + PositiveLiteral +
")";
372 plsqlCodeBlock.Rule = Key(
"BEGIN") + plsqlStatementList + exceptionBlockOpt + Key(
"END");
374 sqlStatementList.Rule = MakePlusRule(sqlStatementList, NestedSqlStatement());
376 exceptionBlockOpt.Rule = Empty | exceptionBlock;
377 exceptionBlock.Rule = Key(
"EXCEPTION") + exceptionHandlerList;
378 exceptionHandlerList.Rule = MakePlusRule(exceptionHandlerList, exceptionHandler);
379 exceptionHandler.Rule = Key(
"WHEN") + handledExceptions + Key(
"THEN") + plsqlStatementList;
380 handledExceptions.Rule = Key(
"OTHERS") | exceptionNames;
381 exceptionNames.Rule = MakePlusRule(exceptionNames, OR, Identifier);
389 var createCommand =
new NonTerminal(
"create_command");
392 createCommand.Rule = CreateSchema() |
401 return createCommand;
405 var createTable =
new NonTerminal(
"create_table", typeof(
CreateTableNode));
406 var ifNotExistsOpt =
new NonTerminal(
"if_not_exists_opt");
407 var temporaryOpt =
new NonTerminal(
"temporary_opt");
408 var columnOrConstraintList =
new NonTerminal(
"column_or_constraint_list");
409 var columnOrConstraint =
new NonTerminal(
"column_or_constraint");
410 var tableColumn =
new NonTerminal(
"table_column", typeof (
TableColumnNode));
411 var columnDefaultOpt =
new NonTerminal(
"column_default_opt");
412 var columnIdentityOpt =
new NonTerminal(
"column_identity_opt");
413 var columnConstraintList =
new NonTerminal(
"column_constraint_list");
415 var columnConstraintRefOpt =
new NonTerminal(
"column_constraint_ref_opt");
416 var fkeyActionList =
new NonTerminal(
"fkey_action_list");
417 var fkeyAction =
new NonTerminal(
"fkey_action");
418 var fkeyActionType =
new NonTerminal(
"fkey_action_type");
420 var constraintName =
new NonTerminal(
"constraint_name");
421 var tableConstraintNameOpt =
new NonTerminal(
"table_constraint_name_opt");
422 var defTableConstraint =
new NonTerminal(
"def_table_constraint");
423 var columnList =
new NonTerminal(
"column_list");
425 createTable.Rule = CREATE + temporaryOpt + TABLE + ifNotExistsOpt +
ObjectName() +
"(" + columnOrConstraintList +
")";
426 ifNotExistsOpt.Rule = Empty | IF + NOT + EXISTS;
427 temporaryOpt.Rule = Empty | Key(
"TEMPORARY");
428 columnOrConstraintList.Rule = MakePlusRule(columnOrConstraintList, Comma, columnOrConstraint);
430 columnOrConstraint.Rule = tableColumn | tableConstraint;
432 tableColumn.Rule = Identifier + DataType() + columnConstraintList + columnDefaultOpt + columnIdentityOpt;
434 columnConstraintList.Rule = MakeStarRule(columnConstraintList, columnConstraint);
435 columnConstraint.Rule = NULL |
439 CHECK + SqlExpression() |
440 REFERENCES +
ObjectName() + columnConstraintRefOpt + fkeyActionList;
441 columnConstraintRefOpt.Rule = Empty |
"(" + Identifier +
")";
442 columnDefaultOpt.Rule = Empty | DEFAULT + SqlExpression();
443 columnIdentityOpt.Rule = Empty | IDENTITY;
444 fkeyActionList.Rule = MakeStarRule(fkeyActionList, fkeyAction);
445 fkeyAction.Rule = ON + DELETE + fkeyActionType | ON + UPDATE + fkeyActionType;
446 fkeyActionType.Rule = Key(
"CASCADE") |
447 Key(
"SET") + Key(
"NULL") |
448 Key(
"SET") + Key(
"DEFAULT") |
449 Key(
"NO") + Key(
"ACTION");
451 tableConstraint.Rule = tableConstraintNameOpt + defTableConstraint;
452 tableConstraintNameOpt.Rule = Empty | CONSTRAINT + constraintName;
453 constraintName.Rule = Identifier;
454 defTableConstraint.Rule = PRIMARY + KEY +
"(" + columnList +
")" |
455 UNIQUE +
"(" + columnList +
")" |
456 CHECK +
"(" + SqlExpression() +
")" |
457 FOREIGN + KEY +
"(" + columnList +
")" + REFERENCES +
ObjectName() +
"(" + columnList +
460 columnList.Rule = MakePlusRule(columnList, Comma, Identifier);
466 var createView =
new NonTerminal(
"create_view", typeof(
CreateViewNode));
467 var columnList =
new NonTerminal(
"column_list");
468 var columnName =
new NonTerminal(
"column_name");
469 var columnListOpt =
new NonTerminal(
"column_list_opt");
471 columnName.Rule = Identifier;
472 columnList.Rule = MakeStarRule(columnList, Comma, columnName);
473 columnListOpt.Rule = Empty |
"(" + columnList +
")";
474 createView.Rule = CREATE + OrReplace() + VIEW +
ObjectName() + columnListOpt +
"AS" + SqlQueryExpression();
481 var identifiedRule =
new NonTerminal(
"identified");
483 var identifiedByAuth =
new NonTerminal(
"identified_by_auth");
484 var setAccountLockOpt =
new NonTerminal(
"set_account_lock_opt");
485 var setGroupsOpt =
new NonTerminal(
"set_groups_opt");
487 createUser.Rule = Key(
"CREATE") + Key(
"USER") + Identifier +
488 Key(
"IDENTIFIED") + identifiedRule + setAccountLockOpt + setGroupsOpt;
489 identifiedRule.Rule = identifiedByPassword | identifiedByAuth;
490 identifiedByPassword.Rule = Key(
"BY") + Key(
"PASSWORD") + SqlExpression();
491 identifiedByAuth.Rule = Key(
"BY") + StringLiteral;
493 setAccountLockOpt.Rule = Empty |
494 SET + ACCOUNT + LOCK |
495 SET + ACCOUNT + UNLOCK;
496 setGroupsOpt.Rule = Empty | SET + GROUPS + StringLiteral;
502 var createIndex =
new NonTerminal(
"create_index");
504 var columnList =
new NonTerminal(
"column_list");
505 var columnName =
new NonTerminal(
"column_name");
507 columnName.Rule = Identifier;
508 columnList.Rule = MakePlusRule(columnList, Comma, columnName);
518 var incrementOpt =
new NonTerminal(
"increment_opt");
519 var increment =
new NonTerminal(
"increment");
520 var startOpt =
new NonTerminal(
"start_opt");
521 var start =
new NonTerminal(
"start");
522 var minvalueOpt =
new NonTerminal(
"minvalue_opt");
523 var minvalue =
new NonTerminal(
"minvalue");
524 var maxvalueOpt =
new NonTerminal(
"maxvalue_opt");
525 var maxvalue =
new NonTerminal(
"maxvalue");
526 var cacheOpt =
new NonTerminal(
"cache_opt");
527 var cycleOpt =
new NonTerminal(
"cycle_opt");
528 var cache =
new NonTerminal(
"cache");
530 createSequence.Rule = Key(
"CREATE") + Key(
"SEQUENCE") +
ObjectName() +
537 incrementOpt.Rule = Empty | increment;
538 increment.Rule = Key(
"INCREMENT") + Key(
"BY") + SqlExpression();
539 startOpt.Rule = Empty | start;
540 start.Rule = Key(
"START") + Key(
"WITH") + SqlExpression();
541 minvalueOpt.Rule = Empty | minvalue;
542 minvalue.Rule = Key(
"MINVALUE") + SqlExpression();
543 maxvalueOpt.Rule = Empty | maxvalue;
544 maxvalue.Rule = Key(
"MAXVALUE") + SqlExpression();
545 cycleOpt.Rule = Empty | Key(
"CYCLE");
546 cacheOpt.Rule = Empty | cache;
547 cache.Rule = Key(
"CACHE") + SqlExpression();
549 return createSequence;
553 var createSchema =
new NonTerminal(
"create_schema", typeof(
CreateSchemaNode));
554 createSchema.Rule = Key(
"CREATE") + Key(
"SCHEMA") + Identifier;
560 var createTrigger =
new NonTerminal(
"create_trigger", typeof(
CreateTriggerNode));
561 var createProcedureTrigger =
new NonTerminal(
"create_procedure_trigger");
562 var createCallbackTrigger =
new NonTerminal(
"create_callback_trigger");
563 var triggerSync =
new NonTerminal(
"trigger_sync");
564 var beforeOrAfter =
new NonTerminal(
"before_or_after");
565 var triggerEvents =
new NonTerminal(
"trigger_events");
566 var triggerEvent =
new NonTerminal(
"trigger_event");
567 var triggerBody =
new NonTerminal(
"trigger_body");
568 var triggerRefOpt =
new NonTerminal(
"trigger_ref_opt");
569 var triggerRefList =
new NonTerminal(
"trigger_ref_list");
570 var triggerRef =
new NonTerminal(
"trigger_ref");
571 var stateTableRef =
new NonTerminal(
"state_table_ref");
572 var asOpt =
new NonTerminal(
"as_opt");
574 var functionCallArgsOpt =
new NonTerminal(
"function_call_args_opt");
575 var functionCallArgsList =
new NonTerminal(
"function_call_args_list");
577 createTrigger.Rule = createProcedureTrigger | createCallbackTrigger;
578 createCallbackTrigger.Rule = CREATE + OrReplace() + CALLBACK + TRIGGER +
580 createProcedureTrigger.Rule = CREATE + OrReplace() + TRIGGER + ObjectName() +
581 triggerSync + triggerRefOpt +
582 FOR + EACH + ROW + triggerBody;
583 triggerSync.Rule = beforeOrAfter + triggerEvents + ON + ObjectName();
584 beforeOrAfter.Rule = BEFORE | AFTER;
585 triggerEvents.Rule = MakePlusRule(triggerEvents, OR, triggerEvent);
586 triggerEvent.Rule = INSERT | UPDATE | DELETE;
587 triggerRefOpt.Rule = Empty | Key(
"REFERENCING") + triggerRefList;
588 triggerRefList.Rule = MakePlusRule(triggerRefList, triggerRef);
589 triggerRef.Rule = stateTableRef + asOpt + Identifier;
590 asOpt.Rule = Empty | Key(
"AS");
591 stateTableRef.Rule = Key(
"OLD") | Key(
"NEW");
592 triggerBody.Rule = EXECUTE + PROCEDURE + ObjectName() +
"(" + functionCallArgsList +
")" |
595 functionCallArgsOpt.Rule = Empty |
"(" + functionCallArgsList +
")";
596 functionCallArgsList.Rule = MakeStarRule(functionCallArgsList, Comma, SqlExpression());
598 return createTrigger;
602 var createType =
new NonTerminal(
"create_type");
604 createType.Rule = CREATE + OrReplace() + TYPE +
ObjectName();
614 var alterCommand =
new NonTerminal(
"alter_command");
616 alterCommand.Rule = AlterTable() | AlterUser();
622 var alterTable =
new NonTerminal(
"alter_table", typeof(
AlterTableNode));
623 var alterActions =
new NonTerminal(
"alter_actions");
624 var alterAction =
new NonTerminal(
"alter_action");
625 var addColumn =
new NonTerminal(
"add_column", typeof(
AddColumnNode));
626 var columnOpt =
new NonTerminal(
"column_opt");
627 var addConstraint =
new NonTerminal(
"add_constraint", typeof(
AddConstraintNode));
628 var dropColumn =
new NonTerminal(
"drop_column", typeof(
DropColumnNode));
631 var setDefault =
new NonTerminal(
"set_default", typeof(
SetDefaultNode));
632 var alterColumn =
new NonTerminal(
"alter_column", typeof(
AlterColumnNode));
633 var dropDefault =
new NonTerminal(
"drop_default", typeof(
DropDefaultNode));
634 var columnDef =
new NonTerminal(
"column_def", typeof(
TableColumnNode));
635 var columnConstraintList =
new NonTerminal(
"column_constraint_lst");
636 var columnDefaultOpt =
new NonTerminal(
"column_default_opt");
637 var columnIdentityOpt =
new NonTerminal(
"column_identity_opt");
639 var columnConstraintRefOpt =
new NonTerminal(
"column_constraint_ref_opt");
640 var fkeyActionList =
new NonTerminal(
"fkey_action_list");
641 var fkeyAction =
new NonTerminal(
"fkey_action");
642 var fkeyActionType =
new NonTerminal(
"fkey_action_type");
644 var constraintName =
new NonTerminal(
"constraint_name");
645 var tableConstraintNameOpt =
new NonTerminal(
"table_constraint_name_opt");
646 var defTableConstraint =
new NonTerminal(
"def_table_constraint");
647 var columnList =
new NonTerminal(
"column_list");
649 alterTable.Rule = Key(
"ALTER") + Key(
"TABLE") +
ObjectName() + alterActions;
650 alterActions.Rule = MakePlusRule(alterActions, alterAction);
651 alterAction.Rule = addColumn | addConstraint | dropColumn | dropConstraint | dropPrimaryKey | setDefault | dropDefault | alterColumn;
652 addColumn.Rule = Key(
"ADD") + columnOpt + columnDef;
653 columnOpt.Rule = Empty | Key(
"COLUMN");
654 dropColumn.Rule = Key(
"DROP") + columnOpt + Identifier;
655 addConstraint.Rule = Key(
"ADD") + Key(
"CONSTRAINT") + tableConstraint;
656 dropConstraint.Rule = Key(
"DROP") + Key(
"CONSTRAINT") + Identifier;
657 dropPrimaryKey.Rule = Key(
"DROP") + Key(
"PRIMARY") + Key(
"KEY");
658 dropDefault.Rule = Key(
"ALTER") + columnOpt + Identifier + Key(
"DROP") + Key(
"DEFAULT");
659 setDefault.Rule = Key(
"ALTER") + columnOpt + Identifier + Key(
"SET") + Key(
"DEFAULT") + SqlExpression();
660 alterColumn.Rule = Key(
"ALTER") + columnOpt + columnDef;
661 columnDef.Rule = Identifier + DataType() + columnConstraintList + columnDefaultOpt + columnIdentityOpt;
662 columnConstraintList.Rule = MakeStarRule(columnConstraintList, columnConstraint);
663 columnConstraint.Rule = Key(
"NULL") |
664 Key(
"NOT") + Key(
"NULL") |
666 Key(
"PRIMARY") + Key(
"KEY") |
667 Key(
"CHECK") + SqlExpression() |
668 Key(
"REFERENCES") +
ObjectName() + columnConstraintRefOpt + fkeyActionList;
669 columnConstraintRefOpt.Rule = Empty |
"(" + Identifier +
")";
670 columnDefaultOpt.Rule = Empty | Key(
"DEFAULT") + SqlExpression();
671 columnIdentityOpt.Rule = Empty | Key(
"IDENTITY");
672 fkeyActionList.Rule = MakeStarRule(fkeyActionList, fkeyAction);
673 fkeyAction.Rule = ON + DELETE + fkeyActionType | ON + UPDATE + fkeyActionType;
674 fkeyActionType.Rule = Key(
"CASCADE") |
675 Key(
"SET") + Key(
"NULL") |
676 Key(
"SET") + Key(
"DEFAULT") |
677 Key(
"NO") + Key(
"ACTION");
679 tableConstraint.Rule = tableConstraintNameOpt + defTableConstraint;
680 tableConstraintNameOpt.Rule = Empty | constraintName;
681 constraintName.Rule = Identifier;
682 defTableConstraint.Rule = Key(
"PRIMARY") + Key(
"KEY") +
"(" + columnList +
")" |
683 Key(
"UNIQUE") +
"(" + columnList +
")" |
684 Key(
"CHECK") +
"(" + SqlExpression() +
")" |
685 FOREIGN + KEY +
"(" + columnList +
")" + REFERENCES +
ObjectName() +
"(" + columnList +
688 columnList.Rule = MakePlusRule(columnList, Comma, Identifier);
695 var actionList =
new NonTerminal(
"action_list");
696 var action =
new NonTerminal(
"action");
698 var setPassword =
new NonTerminal(
"set_password", typeof(
SetPasswordNode));
699 var setGroups =
new NonTerminal(
"set_groups", typeof(
SetGroupsNode));
700 var accountStatus =
new NonTerminal(
"account_status");
702 alterUser.Rule = Key(
"ALTER") + Key(
"USER") + Identifier + actionList;
703 actionList.Rule = MakePlusRule(actionList, action);
704 action.Rule = setAccountStatus | setPassword | setGroups;
705 setAccountStatus.Rule = Key(
"SET") + Key(
"ACCOUNT") + accountStatus;
706 accountStatus.Rule = Key(
"LOCK") | Key(
"UNLOCK");
707 setPassword.Rule = Key(
"SET") + Key(
"PASSWORD") + SqlExpression();
708 setGroups.Rule = Key(
"SET") + Key(
"GROUPS") + SqlExpressionList();
716 var dropCommand =
new NonTerminal(
"drop_command");
718 dropCommand.Rule = DropSchema() |
733 dropSchema.Rule = Key(
"DROP") + Key(
"SCHEMA") + Identifier;
739 var tableNameList =
new NonTerminal(
"table_name_list");
740 var ifExistsOpt =
new NonTerminal(
"if_exists_opt");
742 dropTable.Rule = Key(
"DROP") + Key(
"TABLE") + ifExistsOpt + tableNameList;
743 tableNameList.Rule = MakePlusRule(tableNameList, Comma,
ObjectName());
744 ifExistsOpt.Rule = Empty | Key(
"IF") + Key(
"EXISTS");
751 var viewNameList =
new NonTerminal(
"view_name_list");
752 var ifExistsOpt =
new NonTerminal(
"if_exists_opt");
754 dropView.Rule = Key(
"DROP") + Key(
"VIEW") + ifExistsOpt + viewNameList;
755 viewNameList.Rule = MakePlusRule(viewNameList, Comma,
ObjectName());
756 ifExistsOpt.Rule = Empty | Key(
"IF") + Key(
"EXISTS");
762 var dropIndex =
new NonTerminal(
"drop_index");
763 dropIndex.Rule = Key(
"DROP") + Key(
"INDEX") +
ObjectName();
768 var dropSequence =
new NonTerminal(
"drop_index");
769 dropSequence.Rule = Key(
"DROP") + Key(
"SEQUENCE") +
ObjectName();
774 var dropTrigger =
new NonTerminal(
"drop_trigger");
775 var dropProcedureTrigger =
new NonTerminal(
"drop_procedure_trigger");
776 var dropCallbackTrigger =
new NonTerminal(
"drop_callback_trigger");
778 dropTrigger.Rule = dropProcedureTrigger | dropCallbackTrigger;
779 dropProcedureTrigger.Rule = Key(
"DROP") + Key(
"TRIGGER") +
ObjectName();
780 dropCallbackTrigger.Rule = Key(
"DROP") + Key(
"CALLBACK") + Key(
"TRIGGER") + Key(
"FROM") +
ObjectName();
785 var dropUser =
new NonTerminal(
"drop_user");
786 dropUser.Rule = Key(
"DROP") + Key(
"USER") + Identifier;
791 var dropType =
new NonTerminal(
"drop_type");
792 dropType.Rule = Key(
"DROP") + Key(
"TYPE") +
ObjectName();
798 commitCommand.Rule = Key(
"COMMIT");
799 return commitCommand;
804 command.Rule = Key(
"ROLLBACK");
810 var orderOpt =
new NonTerminal(
"order_opt");
811 var sortedDef =
new NonTerminal(
"sorted_def", typeof(
OrderByNode));
812 var sortedDefList =
new NonTerminal(
"sorted_def_list");
813 var sortOrder =
new NonTerminal(
"sort_order");
814 var limitOpt =
new NonTerminal(
"limit_opt");
815 var limit =
new NonTerminal(
"limit", typeof(
LimitNode));
817 selectCommand.Rule = SqlQueryExpression() + orderOpt + limitOpt;
819 orderOpt.Rule = Empty | Key(
"ORDER") + Key(
"BY") + sortedDefList;
820 sortedDef.Rule = SqlExpression() + sortOrder;
821 sortOrder.Rule = Key(
"ASC") | Key(
"DESC");
822 sortedDefList.Rule = MakePlusRule(sortedDefList, Comma, sortedDef);
824 limitOpt.Rule = Empty | limit;
825 limit.Rule = Key(
"LIMIT") + PositiveLiteral +
"," + PositiveLiteral |
826 Key(
"LIMIT") + PositiveLiteral;
828 return selectCommand;
832 var grant =
new NonTerminal(
"grant");
835 var roleList =
new NonTerminal(
"role_list");
837 var privList =
new NonTerminal(
"priv_list");
838 var objPriv =
new NonTerminal(
"object_priv");
839 var privilegeOpt =
new NonTerminal(
"privilege_opt");
840 var privilegesOpt =
new NonTerminal(
"privileges_opt");
841 var distributionList =
new NonTerminal(
"distribution_list");
842 var withAdminOpt =
new NonTerminal(
"with_admin_opt");
843 var withAdmin =
new NonTerminal(
"with_admin");
844 var withGrantOpt =
new NonTerminal(
"with_grant_opt");
845 var withGrant =
new NonTerminal(
"with_grant");
846 var optionOpt =
new NonTerminal(
"option_opt");
847 var columnList =
new NonTerminal(
"column_list");
848 var columnListOpt =
new NonTerminal(
"column_list_opt");
849 var referencePriv =
new NonTerminal(
"reference_priv");
850 var updatePriv =
new NonTerminal(
"update_priv");
851 var selectPriv =
new NonTerminal(
"select_priv");
853 grant.Rule = grantObject | grantPriv;
854 grantPriv.Rule = Key(
"GRANT") + roleList + Key(
"TO") + distributionList + withAdminOpt;
855 roleList.Rule = MakePlusRule(roleList, Comma, Identifier);
856 withAdminOpt.Rule = Empty | withAdmin;
857 withAdmin.Rule = Key(
"WITH") + Key(
"ADMIN") + optionOpt;
858 optionOpt.Rule = Empty | Key(
"OPTION");
860 grantObject.Rule = Key(
"GRANT") + objPriv + Key(
"ON") +
ObjectName() + Key(
"TO") + distributionList + withGrantOpt;
861 objPriv.Rule = Key(
"ALL") + privilegesOpt | privList;
862 privilegesOpt.Rule = Empty | Key(
"PRIVILEGES");
863 privilegeOpt.Rule = Empty | Key(
"PRIVILEGE");
864 privList.Rule = MakePlusRule(privList, Comma, priv);
865 priv.Rule = Key(
"USAGE") + privilegeOpt|
866 Key(
"INSERT") + privilegeOpt |
867 Key(
"DELETE") + privilegeOpt |
868 Key(
"EXECUTE") + privilegeOpt |
869 Key(
"ALTER") + privilegeOpt |
870 Key(
"INDEX") + privilegeOpt |
874 updatePriv.Rule = Key(
"UPDATE") + privilegeOpt + columnListOpt;
875 referencePriv.Rule = Key(
"REFERENCES") + privilegeOpt + columnListOpt;
876 selectPriv.Rule = Key(
"SELECT") + columnListOpt;
877 columnListOpt.Rule = Empty |
"(" + columnList +
")";
878 columnList.Rule = MakePlusRule(columnList, Comma, Identifier);
879 withGrantOpt.Rule = Empty | withGrant;
880 withGrant.Rule = Key(
"WITH") + Key(
"GRANT") + optionOpt;
881 distributionList.Rule = MakePlusRule(distributionList, Comma, Identifier);
887 var revoke =
new NonTerminal(
"revoke");
888 var grantObject =
new NonTerminal(
"grant_object");
889 var grantPriv =
new NonTerminal(
"grant_priv");
890 var roleList =
new NonTerminal(
"role_list");
891 var priv =
new NonTerminal(
"priv");
892 var privList =
new NonTerminal(
"priv_list");
893 var objPriv =
new NonTerminal(
"object_priv");
894 var privilegeOpt =
new NonTerminal(
"privilege_opt");
895 var privilegesOpt =
new NonTerminal(
"privileges_opt");
896 var distributionList =
new NonTerminal(
"distribution_list");
898 revoke.Rule = grantObject | grantPriv;
899 grantPriv.Rule = Key(
"REVOKE") + roleList + Key(
"FROM") + distributionList;
900 roleList.Rule = MakePlusRule(roleList, Comma, Identifier);
902 grantObject.Rule = Key(
"REVOKE") + objPriv + Key(
"ON") +
ObjectName() + Key(
"TO") + distributionList;
903 objPriv.Rule = Key(
"ALL") + privilegesOpt | privList;
904 privilegesOpt.Rule = Empty | Key(
"PRIVILEGES");
905 privilegeOpt.Rule = Empty | Key(
"PRIVILEGE");
906 privList.Rule = MakePlusRule(privList, Comma, priv);
907 priv.Rule = Key(
"USAGE") + privilegeOpt |
908 Key(
"INSERT") + privilegeOpt |
909 Key(
"DELETE") + privilegeOpt |
910 Key(
"EXECUTE") + privilegeOpt |
911 Key(
"ALTER") + privilegeOpt |
912 Key(
"INDEX") + privilegeOpt |
913 Key(
"UPDATE") + privilegeOpt |
914 Key(
"REFERENCES") + privilegeOpt |
915 Key(
"SELECT") + privilegeOpt;
916 distributionList.Rule = MakePlusRule(distributionList, Comma, Identifier);
923 var insertSource =
new NonTerminal(
"insert_source");
924 var sourceWithColumns =
new NonTerminal(
"source_with_columns");
927 var fromQuery =
new NonTerminal(
"from_query", typeof(
QueryInsertNode));
928 var fromSet =
new NonTerminal(
"from_set", typeof(
SetInsertNode));
929 var columnList =
new NonTerminal(
"column_list");
930 var columnListOpt =
new NonTerminal(
"column_list_opt");
931 var columnSet =
new NonTerminal(
"column_set", typeof(
InsertSetNode));
932 var columnSetList =
new NonTerminal(
"column_set_list");
933 var insertTuple =
new NonTerminal(
"insert_tuple");
934 var insertValue =
new NonTerminal(
"insert_value", typeof(
InsertValueNode));
936 insert.Rule = Key(
"INSERT") + Key(
"INTO") +
ObjectName() + insertSource;
937 insertSource.Rule = columnListOpt + sourceWithColumns | fromSet;
938 sourceWithColumns.Rule = fromQuery | fromValues;
939 fromValues.Rule = columnListOpt + Key(
"VALUES") + insertTuple;
940 fromQuery.Rule = columnListOpt + Key(
"FROM") +
"(" + SqlQueryExpression() +
")";
941 fromSet.Rule = Key(
"SET") + columnSetList;
942 columnListOpt.Rule = Empty |
"(" + columnList +
")";
943 columnList.Rule = MakePlusRule(columnList, Comma, Identifier);
944 fromValues.Rule = Key(
"VALUES") + insertTuple;
945 insertTuple.Rule = MakePlusRule(insertTuple, Comma, insertValue);
946 insertValue.Rule =
"(" + SqlExpressionList() +
")";
947 columnSetList.Rule = MakePlusRule(columnSetList, Comma, columnSet);
948 columnSet.Rule = Identifier +
"=" + SqlExpression();
953 var deleteCommand =
new NonTerminal(
"delete_command");
954 var whereOpt =
new NonTerminal(
"where_opt");
956 deleteCommand.Rule = Key(
"DELETE") + Key(
"FROM") +
ObjectName() + whereOpt;
957 whereOpt.Rule = Empty | Key(
"WHERE") + SqlQueryExpression();
959 return deleteCommand;
964 var updateSimple =
new NonTerminal(
"update_simple", typeof(
SimpleUpdateNode));
965 var updateQuery =
new NonTerminal(
"update_query");
967 var columnSetList =
new NonTerminal(
"column_set_list");
968 var columnList =
new NonTerminal(
"column_list");
969 var updateWhere =
new NonTerminal(
"update_where");
970 var limitOpt =
new NonTerminal(
"limit_opt");
972 update.Rule = updateSimple | updateQuery;
973 updateSimple.Rule = Key(
"UPDATE") +
ObjectName() + Key(
"SET") + columnSetList + updateWhere + limitOpt;
974 updateQuery.Rule = Key(
"UPDATE") +
ObjectName() + Key(
"SET") +
"(" + columnList +
")" +
"=" + SqlQueryExpression() + updateWhere + limitOpt;
975 columnSetList.Rule = MakePlusRule(columnSetList, Comma, columnSet);
976 columnSet.Rule = Identifier +
"=" + SqlExpression();
977 columnList.Rule = MakePlusRule(columnList, Comma, Identifier);
978 updateWhere.Rule = Key(
"WHERE") + SqlExpression();
979 limitOpt.Rule = Empty | Key(
"LIMIT") + PositiveLiteral;
985 var truncate =
new NonTerminal(
"truncate_command");
986 truncate.Rule = Key(
"TRUNCATE") +
ObjectName();
990 private NonTerminal
Set() {
991 var set =
new NonTerminal(
"set_command");
992 set.Rule = SetTransaction() | SetVariable();
997 var set =
new NonTerminal(
"set_transaction");
998 var access =
new NonTerminal(
"access");
999 var accessType =
new NonTerminal(
"access_type");
1000 var isolationLevel =
new NonTerminal(
"isolation_level");
1001 var levelType =
new NonTerminal(
"level_type");
1002 var defaultSchema =
new NonTerminal(
"default_schema");
1004 set.Rule = access | isolationLevel | defaultSchema;
1005 access.Rule = Key(
"SET") + Key(
"TRANSACTION") + accessType;
1006 accessType.Rule = Key(
"READ") + Key(
"ONLY") | Key(
"READ") + Key(
"WRITE");
1007 isolationLevel.Rule = Key(
"SET") + Key(
"TRANSACTION") + Key(
"ISOLATION") + Key(
"LEVEL") + levelType;
1008 levelType.Rule = Key(
"SERIALIZABLE") |
1009 Key(
"READ") + Key(
"COMMITTED") |
1010 Key(
"READ") + Key(
"UNCOMMITTED") |
1012 defaultSchema.Rule = Key(
"SET") + Key(
"TRANSACTION") + Key(
"DEFAULT") + Key(
"SCHEMA") + Identifier;
1017 var varSet =
new NonTerminal(
"var_set");
1018 varSet.Rule = Identifier +
"=" + SqlExpression();
NonTerminal NestedSqlStatement()
NonTerminal StatementEnd()
NonTerminal CreateTrigger()
NonTerminal VariableDeclaration()
Within an SQL query node, this describes the ordering criteria that will be applied when returning th...
NonTerminal ExceptionDeclaration()
override NonTerminal MakeRoot()
NonTerminal SqlStatementList()
Describes the name of an object within a database.
void Productions(NonTerminal root)
NonTerminal CreateIndex()
NonTerminal CreateSchema()
NonTerminal SetTransaction()
NonTerminal DropSequence()
NonTerminal DeclareVariable()
NonTerminal DeclareException()
NonTerminal DeclareCursor()
NonTerminal CreateSequence()
NonTerminal SqlStatement()
NonTerminal CreateTable()
NonTerminal CursorDeclaration()
NonTerminal DropTrigger()
NonTerminal SetVariable()