18 using System.Collections.Generic;
25 namespace Deveel.Data.Sql.Statements {
36 TableName = tableName;
37 Columns =
new List<SqlTableColumn>();
38 if (columns != null) {
39 foreach (var column
in columns) {
45 public string TableName {
get;
private set; }
47 public IList<SqlTableColumn> Columns {
get;
private set; }
49 public bool IfNotExists {
get; set; }
51 public bool Temporary {
get; set; }
54 var tableInfo = CreateTableInfo(context);
56 return new Prepared(tableInfo, IfNotExists, Temporary);
60 var tableName = context.
Query.ResolveTableName(TableName);
62 var idColumnCount = Columns.Count(x => x.IsIdentity);
63 if (idColumnCount > 1)
64 throw new InvalidOperationException(
"More than one IDENTITY column specified.");
66 bool ignoreCase = context.
Query.IgnoreIdentifiersCase();
72 foreach (var column
in Columns) {
73 var columnInfo = CreateColumnInfo(tableName.Name, column, columnChecker);
74 tableInfo.AddColumn(columnInfo);
84 throw new InvalidOperationException(String.Format(
"Identity column '{0}' cannot define a DEFAULT expression.", column.
ColumnName));
86 if (expression != null)
93 DefaultExpression = expression,
110 public bool Temporary {
get;
private set; }
112 public bool IfNotExists {
get;
private set; }
116 IfNotExists = ifNotExists;
117 Temporary = temporary;
130 data.
SetValue(
"Temporary", Temporary);
131 data.
SetValue(
"IfNotExists", IfNotExists);
137 #region TableColumnChecker
140 private readonly IEnumerable<SqlTableColumn>
columns;
144 this.columns = columns;
145 this.ignoreCase = ignoreCase;
149 var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
150 string foundColumn = null;
152 foreach (var columnInfo
in columns) {
153 if (foundColumn != null)
154 throw new InvalidOperationException(String.Format(
"Column name '{0}' caused an ambiguous match in table.", columnName));
156 if (String.Equals(columnInfo.ColumnName, columnName, comparison))
157 foundColumn = columnInfo.ColumnName;
166 #region PreparedSerializer
Defines the metadata properties of a column within a table of a database.
TableColumnChecker(IEnumerable< SqlTableColumn > columns, bool ignoreCase)
The statement object used to create a table in a database.
string StripTableName(string tableDomain, string column)
SqlExpression DefaultExpression
ColumnInfo CreateColumnInfo(string tableName, SqlTableColumn column, TableColumnChecker columnChecker)
Prepared(ObjectData data)
void SetValue(string key, Type type, object value)
override void ExecuteStatement(ExecutionContext context)
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Represents the foundation class of SQL statements to be executed.
CreateTableStatement(string tableName, IEnumerable< SqlTableColumn > columns)
override string ResolveColumnName(string columnName)
bool GetBoolean(string key)
SqlExpression CheckExpression(SqlExpression expression)
object GetValue(string key)
IStatement Prepare(IRequest request)
override void GetData(SerializeData data)
Defines the metadata properties of a table existing within a database.
Prepared(TableInfo tableInfo, bool ifNotExists, bool temporary)
TableInfo CreateTableInfo(IRequest context)
readonly IEnumerable< SqlTableColumn > columns