DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Properties | Static Private Member Functions | List of all members
Deveel.Data.Sql.Parser.CreateTableNode Class Reference
Inheritance diagram for Deveel.Data.Sql.Parser.CreateTableNode:
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

Public Member Functions

void Build (ITypeResolver typeResolver, ICollection< IStatement > statements)
 
- Public Member Functions inherited from Deveel.Data.Sql.Parser.SqlNode
 SqlNode ()
 

Protected Member Functions

override void OnNodeInit ()
 After the initialization of the node from the parser, this method is invoked to let the specific initialization to occur. More...
 
override void BuildStatement (StatementBuilder builder)
 
- Protected Member Functions inherited from Deveel.Data.Sql.Parser.SqlNode
virtual 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...
 

Properties

ObjectNameNode TableName [get, private set]
 
bool IfNotExists [get, private set]
 
bool Temporary [get, private set]
 
IEnumerable< TableColumnNodeColumns [get, private set]
 
IEnumerable< TableConstraintNodeConstraints [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 SqlStatement MakeAlterTableAddConstraint (string tableName, SqlTableConstraint constraint)
 
static SqlStatement MakeCreateTable (string tableName, IEnumerable< SqlTableColumn > columns, bool ifNotExists, bool temporary)
 

Detailed Description

Definition at line 25 of file CreateTableNode.cs.

Member Function Documentation

void Deveel.Data.Sql.Parser.CreateTableNode.Build ( ITypeResolver  typeResolver,
ICollection< IStatement statements 
)
inline

Definition at line 50 of file CreateTableNode.cs.

50  {
51  string idColumn = null;
52 
53  var tableName = TableName;
54  var constraints = new List<SqlTableConstraint>();
55  var columns = new List<SqlTableColumn>();
56 
57  foreach (var column in Columns) {
58  if (column.IsIdentity) {
59  if (!String.IsNullOrEmpty(idColumn))
60  throw new InvalidOperationException(String.Format("Table {0} defines already {1} as identity column.", TableName,
61  idColumn));
62 
63  if (column.Default != null)
64  throw new InvalidOperationException(String.Format("The identity column {0} cannot have a DEFAULT constraint.",
65  idColumn));
66 
67  idColumn = column.ColumnName.Text;
68  }
69 
70  var columnInfo = column.BuildColumn(typeResolver, tableName.Name, constraints);
71 
72  columns.Add(columnInfo);
73  }
74 
75  //TODO: Optimization: merge same constraints
76 
77  statements.Add(MakeCreateTable(tableName.Name, columns, IfNotExists, Temporary));
78 
79  foreach (var constraint in Constraints) {
80  var constraintInfo = constraint.BuildConstraint();
81  statements.Add(new AlterTableStatement(ObjectName.Parse(tableName.Name), new AddConstraintAction(constraintInfo)));
82  }
83 
84  foreach (var constraint in constraints) {
85  statements.Add(MakeAlterTableAddConstraint(tableName.Name, constraint));
86  }
87  }
A long string in the system.
IEnumerable< TableColumnNode > Columns
IEnumerable< TableConstraintNode > Constraints
static SqlStatement MakeAlterTableAddConstraint(string tableName, SqlTableConstraint constraint)
static SqlStatement MakeCreateTable(string tableName, IEnumerable< SqlTableColumn > columns, bool ifNotExists, bool temporary)
override void Deveel.Data.Sql.Parser.CreateTableNode.BuildStatement ( StatementBuilder  builder)
inlineprotectedvirtual

Implements Deveel.Data.Sql.Parser.SqlStatementNode.

Definition at line 46 of file CreateTableNode.cs.

46  {
47  Build(builder.TypeResolver, builder.Statements);
48  }
void Build(ITypeResolver typeResolver, ICollection< IStatement > statements)
static SqlStatement Deveel.Data.Sql.Parser.CreateTableNode.MakeAlterTableAddConstraint ( string  tableName,
SqlTableConstraint  constraint 
)
inlinestaticprivate

Definition at line 89 of file CreateTableNode.cs.

89  {
90  var action = new AddConstraintAction(constraint);
91 
92  return new AlterTableStatement(ObjectName.Parse(tableName), action);
93  }
static SqlStatement Deveel.Data.Sql.Parser.CreateTableNode.MakeCreateTable ( string  tableName,
IEnumerable< SqlTableColumn columns,
bool  ifNotExists,
bool  temporary 
)
inlinestaticprivate

Definition at line 95 of file CreateTableNode.cs.

96  {
97  var tree = new CreateTableStatement(tableName, columns.ToList());
98  tree.IfNotExists = ifNotExists;
99  tree.Temporary = temporary;
100  return tree;
101  }
The statement object used to create a table in a database.
override void Deveel.Data.Sql.Parser.CreateTableNode.OnNodeInit ( )
inlineprotectedvirtual

After the initialization of the node from the parser, this method is invoked to let the specific initialization to occur.

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

Definition at line 36 of file CreateTableNode.cs.

36  {
37  TableName = this.FindNode<ObjectNameNode>();
38  IfNotExists = this.HasOptionalNode("if_not_exists_opt");
39  Temporary = this.HasOptionalNode("temporary_opt");
40 
41  var elements = this.FindNodes<ITableElementNode>().ToList();
42  Columns = elements.OfType<TableColumnNode>();
43  Constraints = elements.OfType<TableConstraintNode>();
44  }
IEnumerable< TableColumnNode > Columns
IEnumerable< TableConstraintNode > Constraints

Property Documentation

IEnumerable<TableColumnNode> Deveel.Data.Sql.Parser.CreateTableNode.Columns
getprivate set

Definition at line 32 of file CreateTableNode.cs.

IEnumerable<TableConstraintNode> Deveel.Data.Sql.Parser.CreateTableNode.Constraints
getprivate set

Definition at line 34 of file CreateTableNode.cs.

bool Deveel.Data.Sql.Parser.CreateTableNode.IfNotExists
getprivate set

Definition at line 28 of file CreateTableNode.cs.

ObjectNameNode Deveel.Data.Sql.Parser.CreateTableNode.TableName
getprivate set

Definition at line 26 of file CreateTableNode.cs.

bool Deveel.Data.Sql.Parser.CreateTableNode.Temporary
getprivate set

Definition at line 30 of file CreateTableNode.cs.


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