18 using System.Collections.Generic;
24 namespace Deveel.Data.Sql.Parser {
28 public bool IfNotExists {
get;
private set; }
30 public bool Temporary {
get;
private set; }
32 public IEnumerable<TableColumnNode> Columns {
get;
private set; }
34 public IEnumerable<TableConstraintNode> Constraints {
get;
private set; }
37 TableName = this.FindNode<ObjectNameNode>();
38 IfNotExists = this.HasOptionalNode(
"if_not_exists_opt");
39 Temporary = this.HasOptionalNode(
"temporary_opt");
41 var elements = this.FindNodes<ITableElementNode>().ToList();
51 string idColumn = null;
53 var tableName = TableName;
54 var constraints =
new List<SqlTableConstraint>();
55 var columns =
new List<SqlTableColumn>();
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,
63 if (column.Default != null)
64 throw new InvalidOperationException(
String.Format(
"The identity column {0} cannot have a DEFAULT constraint.",
67 idColumn = column.ColumnName.Text;
70 var columnInfo = column.BuildColumn(typeResolver, tableName.Name, constraints);
72 columns.Add(columnInfo);
77 statements.Add(MakeCreateTable(tableName.Name, columns, IfNotExists, Temporary));
79 foreach (var constraint
in Constraints) {
80 var constraintInfo = constraint.BuildConstraint();
84 foreach (var constraint
in constraints) {
85 statements.Add(MakeAlterTableAddConstraint(tableName.Name, constraint));
99 tree.Temporary = temporary;
override void BuildStatement(StatementBuilder builder)
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
A long string in the system.
The statement object used to create a table in a database.
Represents a composed name for an object within the system.
void Build(ITypeResolver typeResolver, ICollection< IStatement > statements)
Describes the name of an object within a database.
Represents the foundation class of SQL statements to be executed.
ICollection< IStatement > Statements
ITypeResolver TypeResolver
override void OnNodeInit()
After the initialization of the node from the parser, this method is invoked to let the specific init...
static SqlStatement MakeAlterTableAddConstraint(string tableName, SqlTableConstraint constraint)
static SqlStatement MakeCreateTable(string tableName, IEnumerable< SqlTableColumn > columns, bool ifNotExists, bool temporary)