18 using System.Collections.Generic;
24 namespace Deveel.Data.Sql.Parser {
31 columns =
new List<string>();
32 refColumns =
new List<string>();
35 public string ConstraintName {
get;
private set; }
39 public IEnumerable<string> Columns {
40 get {
return columns.AsEnumerable(); }
47 public IEnumerable<string> ReferencedColumns {
48 get {
return refColumns.AsEnumerable(); }
51 public string OnUpdateAction {
get;
private set; }
53 public string OnDeleteAction {
get;
private set; }
56 if (node.
NodeName ==
"table_constraint_name_opt") {
58 }
else if (node.
NodeName ==
"def_table_constraint") {
59 ReadConstraintDefinition(node);
62 return base.OnChildNode(node);
66 foreach (var childNode
in node.ChildNodes) {
68 var keyNode = (SqlKeyNode) childNode;
69 if (String.Equals(keyNode.Text,
"NULL", StringComparison.OrdinalIgnoreCase)) {
75 }
else if (String.Equals(keyNode.Text,
"NOT", StringComparison.OrdinalIgnoreCase)) {
77 }
else if (String.Equals(keyNode.Text,
"REFERENCES", StringComparison.OrdinalIgnoreCase)) {
79 }
else if (String.Equals(keyNode.Text,
"CHECK", StringComparison.OrdinalIgnoreCase)) {
81 }
else if (String.Equals(keyNode.Text,
"PRIMARY", StringComparison.OrdinalIgnoreCase)) {
83 }
else if (String.Equals(keyNode.Text,
"UNIQUE", StringComparison.OrdinalIgnoreCase)) {
86 }
else if (childNode.NodeName ==
"column_list") {
87 ReadColumnList(childNode.ChildNodes);
93 foreach (var node
in nodes) {
95 ConstraintName = ((IdentifierNode) node).Text;
97 ReadConstraintName(node.ChildNodes);
103 foreach (var node
in nodes) {
105 columns.Add(((IdentifierNode) node).Text);
107 ReadColumnList(node.ChildNodes);
115 return new SqlTableConstraint(ConstraintName, Tables.ConstraintType.Check, Columns.ToArray()) {
116 CheckExpression = exp
124 var fTable = ReferencedTableName.Name;
125 var fColumns = ReferencedColumns;
129 if (!String.IsNullOrEmpty(OnDeleteAction))
131 if (!String.IsNullOrEmpty(OnUpdateAction))
135 fColumns.ToArray(), onDelete, onUpdate);
140 throw new NotSupportedException();
SqlTableConstraint BuildConstraint()
void ReadConstraintName(IEnumerable< ISqlNode > nodes)
This is a simple identifier within a SQL grammar.
Defines the contract for nodes in an AST model for a SQL grammar analysis and parsing.
Represents a keyword found during the compilation of a source text.
void ReadConstraintDefinition(ISqlNode node)
Represents a composed name for an object within the system.
string NodeName
Gets the name of the node analyzed from the parser.
static SqlExpression Build(IExpressionNode node)
static SqlTableConstraint PrimaryKey(string constraintName, string[] columns)
static ForeignKeyAction GetForeignKeyAction(string actionName)
override ISqlNode OnChildNode(ISqlNode node)
During the initialization of the node from the parser, this method is called for every child node add...
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
ConstraintType
An enumeration of all the supported kinds of constraints within a table or a schema.
static SqlTableConstraint UniqueKey(string constraintName, string[] columns)
IEnumerable< ISqlNode > ChildNodes
Gets a read-only enumeration of the children nodes, if any.
readonly IList< string > columns
void ReadColumnList(IEnumerable< ISqlNode > nodes)
readonly IList< string > refColumns
This interface acts like a marker that indicates if a ISqlNode represents a SQL expression.
static SqlTableConstraint ForeignKey(string constraintName, string[] columns, string refTable, string[] refcolumns, ForeignKeyAction onDelete, ForeignKeyAction onUpdate)
The default implementation of ISqlNode, that is a node in the text analysis parsing of SQL commands...