DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Protected Member Functions | Properties | Static Private Member Functions | List of all members
Deveel.Data.Sql.Parser.AlterTableNode Class Reference
Inheritance diagram for Deveel.Data.Sql.Parser.AlterTableNode:
Deveel.Data.Sql.Parser.SqlStatementNode Deveel.Data.Sql.Parser.SqlNode Deveel.Data.Sql.Parser.ISqlVisitableNode Deveel.Data.Sql.Parser.IStatementNode Deveel.Data.Sql.Parser.ISqlNode Deveel.Data.Sql.Parser.ISqlNode Deveel.Data.Sql.Parser.ISqlNode

Protected Member Functions

override ISqlNode OnChildNode (ISqlNode node)
 During the initialization of the node from the parser, this method is called for every child node added to ChildNodes More...
 
override void BuildStatement (StatementBuilder builder)
 
- Protected Member Functions inherited from Deveel.Data.Sql.Parser.SqlNode
virtual void OnNodeInit ()
 After the initialization of the node from the parser, this method is invoked to let the specific initialization to occur. More...
 

Properties

string TableName [get, private set]
 
IEnumerable< IAlterActionNodeActions [get, private set]
 
CreateTableNode CreateTable [get, private set]
 
- Properties inherited from Deveel.Data.Sql.Parser.SqlNode
ISqlNode Parent [get, private set]
 Gets the parent of the current node. More...
 
string NodeName [get, private set]
 Gets the name of the node, as expressed in the SQL grammar. More...
 
IEnumerable< ISqlNodeChildNodes [get, private set]
 Gets an immutable list of nodes, children of the current node. More...
 
IEnumerable< TokenTokens [get, private set]
 Gets an immutable list of Token that represent the source of this node. More...
 
string ISqlNode. NodeName [get]
 
ISqlNode ISqlNode. Parent [get]
 
IEnumerable< ISqlNode > ISqlNode. ChildNodes [get]
 
IEnumerable< Token > ISqlNode. Tokens [get]
 
- Properties inherited from Deveel.Data.Sql.Parser.ISqlNode
string NodeName [get]
 Gets the name of the node analyzed from the parser. More...
 
ISqlNode Parent [get]
 Gets a reference to the parent ISqlNode, if any. More...
 
IEnumerable< ISqlNodeChildNodes [get]
 Gets a read-only enumeration of the children nodes, if any. More...
 
IEnumerable< TokenTokens [get]
 Gets an enumeration of the tokens composing the this node. More...
 

Static Private Member Functions

static void BuildAction (ITypeResolver typeResolver, ObjectName tableName, IAlterActionNode action, ICollection< IStatement > statements)
 

Additional Inherited Members

- Public Member Functions inherited from Deveel.Data.Sql.Parser.SqlNode
 SqlNode ()
 

Detailed Description

Definition at line 24 of file AlterTableNode.cs.

Member Function Documentation

static void Deveel.Data.Sql.Parser.AlterTableNode.BuildAction ( ITypeResolver  typeResolver,
ObjectName  tableName,
IAlterActionNode  action,
ICollection< IStatement statements 
)
inlinestaticprivate

Definition at line 63 of file AlterTableNode.cs.

64  {
65  if (action is AddColumnNode) {
66  var column = ((AddColumnNode) action).Column;
67  var constraints = new List<SqlTableConstraint>();
68  var columnInfo = column.BuildColumn(typeResolver, tableName.FullName, constraints);
69 
70  statements.Add(new AlterTableStatement(tableName, new AddColumnAction(columnInfo)));
71 
72  foreach (var constraint in constraints) {
73  statements.Add(new AlterTableStatement(tableName, new AddConstraintAction(constraint)));
74  }
75  } else if (action is AddConstraintNode) {
76  var constraint = ((AddConstraintNode) action).Constraint;
77 
78  var constraintInfo = constraint.BuildConstraint();
79  statements.Add(new AlterTableStatement(tableName, new AddConstraintAction(constraintInfo)));
80  } else if (action is DropColumnNode) {
81  var columnName = ((DropColumnNode) action).ColumnName;
82  statements.Add(new AlterTableStatement(tableName, new DropColumnAction(columnName)));
83  } else if (action is DropConstraintNode) {
84  var constraintName = ((DropConstraintNode) action).ConstraintName;
85  statements.Add(new AlterTableStatement(tableName, new DropConstraintAction(constraintName)));
86  } else if (action is SetDefaultNode) {
87  var actionNode = ((SetDefaultNode) action);
88  var columnName = actionNode.ColumnName;
89  var expression = ExpressionBuilder.Build(actionNode.Expression);
90  statements.Add(new AlterTableStatement(tableName, new SetDefaultAction(columnName, expression)));
91  } else if (action is DropDefaultNode) {
92  var columnName = ((DropDefaultNode) action).ColumnName;
93  statements.Add(new AlterTableStatement(tableName, new DropDefaultAction(columnName)));
94  } else if (action is AlterColumnNode) {
95  var column = ((AlterColumnNode) action).Column;
96  var constraints = new List<SqlTableConstraint>();
97  var columnInfo = column.BuildColumn(typeResolver, tableName.FullName, constraints);
98 
99  // CHECK: Here we do a drop and add column: is there a better way on the back-end?
100  statements.Add(new AlterTableStatement(tableName, new DropColumnAction(columnInfo.ColumnName)));
101 
102  statements.Add(new AlterTableStatement(tableName, new AddColumnAction(columnInfo)));
103 
104  foreach (var constraint in constraints) {
105  statements.Add(new AlterTableStatement(tableName, new AddConstraintAction(constraint)));
106  }
107  }
108  }
override void Deveel.Data.Sql.Parser.AlterTableNode.BuildStatement ( StatementBuilder  builder)
inlineprotectedvirtual

Implements Deveel.Data.Sql.Parser.SqlStatementNode.

Definition at line 43 of file AlterTableNode.cs.

43  {
44  if (CreateTable != null) {
45  var statements = new List<IStatement>();
46  CreateTable.Build(builder.TypeResolver, statements);
47 
48  foreach (var statement in statements) {
49  if (statement is CreateTableStatement)
50  ((CreateTableStatement) statement).IfNotExists = true;
51  }
52 
53  foreach (var statement in statements) {
54  builder.Statements.Add(statement);
55  }
56  } else if (Actions != null) {
57  foreach (var action in Actions) {
58  BuildAction(builder.TypeResolver, ObjectName.Parse(TableName), action, builder.Statements);
59  }
60  }
61  }
The statement object used to create a table in a database.
IEnumerable< IAlterActionNode > Actions
void Build(ITypeResolver typeResolver, ICollection< IStatement > statements)
static void BuildAction(ITypeResolver typeResolver, ObjectName tableName, IAlterActionNode action, ICollection< IStatement > statements)
override ISqlNode Deveel.Data.Sql.Parser.AlterTableNode.OnChildNode ( ISqlNode  node)
inlineprotectedvirtual

During the initialization of the node from the parser, this method is called for every child node added to ChildNodes

Parameters
nodeThe node being added to the list of children.
Returns
Returns a normalized version of the child node, or the node itself.

Reimplemented from Deveel.Data.Sql.Parser.SqlNode.

Definition at line 31 of file AlterTableNode.cs.

31  {
32  if (node is ObjectNameNode) {
33  TableName = ((ObjectNameNode) node).Name;
34  } else if (node is CreateTableNode) {
35  CreateTable = (CreateTableNode) node;
36  } else if (node.NodeName == "alter_actions") {
37  Actions = node.FindNodes<IAlterActionNode>();
38  }
39 
40  return base.OnChildNode(node);
41  }
IEnumerable< IAlterActionNode > Actions

Property Documentation

IEnumerable<IAlterActionNode> Deveel.Data.Sql.Parser.AlterTableNode.Actions
getprivate set

Definition at line 27 of file AlterTableNode.cs.

CreateTableNode Deveel.Data.Sql.Parser.AlterTableNode.CreateTable
getprivate set

Definition at line 29 of file AlterTableNode.cs.

string Deveel.Data.Sql.Parser.AlterTableNode.TableName
getprivate set

Definition at line 25 of file AlterTableNode.cs.


The documentation for this class was generated from the following file: