DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Static Public Member Functions | Static Package Functions | Static Private Member Functions | List of all members
Deveel.Data.Sql.Tables.QueryContextExtensions Class Reference

Static Public Member Functions

static int DeleteFrom (this IQuery context, ObjectName tableName, SqlQueryExpression query)
 
static int DeleteFrom (this IQuery context, ObjectName tableName, SqlExpression expression)
 
static int DeleteFrom (this IQuery context, ObjectName tableName, SqlExpression expression, int limit)
 
static int DeleteFrom (this IQuery context, ObjectName tableName, SqlQueryExpression query, int limit)
 
static int DeleteFrom (this IQuery context, ObjectName tableName, ITable deleteSet, int limit)
 
static int UpdateTable (this IQuery context, ObjectName tableName, IQueryPlanNode queryPlan, IEnumerable< SqlAssignExpression > assignments, int limit)
 
static void InsertIntoTable (this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression > assignments)
 
static int InsertIntoTable (this IQuery context, ObjectName tableName, IEnumerable< SqlAssignExpression[]> assignments)
 
static ObjectName ResolveTableName (this IQueryContext context, ObjectName tableName)
 
static ObjectName ResolveTableName (this IQueryContext context, string name)
 
static bool TableExists (this IQueryContext context, ObjectName tableName)
 
static void CreateTable (this IQueryContext context, TableInfo tableInfo)
 
static void CreateTable (this IQueryContext context, TableInfo tableInfo, bool onlyIfNotExists)
 
static void CreateTable (this IQueryContext context, TableInfo tableInfo, bool onlyIfNotExists, bool temporary)
 
static void DropTables (this IQueryContext context, IEnumerable< ObjectName > tableNames)
 
static void DropTables (this IQueryContext context, IEnumerable< ObjectName > tableNames, bool onlyIfExists)
 
static void DropTable (this IQueryContext context, ObjectName tableName)
 
static void DropTable (this IQueryContext context, ObjectName tableName, bool onlyIfExists)
 
static void AlterTable (this IQueryContext context, TableInfo tableInfo)
 
static ITable GetTable (this IQueryContext context, ObjectName tableName)
 
static IMutableTable GetMutableTable (this IQueryContext context, ObjectName tableName)
 
static ITable GetCachedTable (this IQueryContext context, string cacheKey)
 
static void CacheTable (this IQueryContext context, string cacheKey, ITable table)
 
static void ClearCachedTables (this IQueryContext context)
 
static void AddPrimaryKey (this IQueryContext context, ObjectName tableName, string[] columnNames)
 
static void AddPrimaryKey (this IQueryContext context, ObjectName tableName, string[] columnNames, string constraintName)
 
static void AddPrimaryKey (this IQueryContext context, ObjectName tableName, string columnName)
 
static void AddPrimaryKey (this IQueryContext context, ObjectName tableName, string columnName, string constraintName)
 
static void AddForeignKey (this IQueryContext context, ObjectName table, string[] columns, ObjectName refTable, string[] refColumns, ForeignKeyAction deleteRule, ForeignKeyAction updateRule, String constraintName)
 
static void AddForeignKey (this IQueryContext context, ObjectName table, string[] columns, ObjectName refTable, string[] refColumns, ForeignKeyAction deleteRule, ForeignKeyAction updateRule, ConstraintDeferrability deferred, String constraintName)
 
static void AddUniqueKey (this IQueryContext context, ObjectName tableName, string[] columns)
 
static void AddUniqueKey (this IQueryContext context, ObjectName tableName, string[] columns, string constraintName)
 
static void AddUniqueKey (this IQueryContext context, ObjectName tableName, string[] columns, ConstraintDeferrability deferrability)
 
static void AddUniqueKey (this IQueryContext context, ObjectName tableName, string[] columns, ConstraintDeferrability deferrability, string constraintName)
 
static void AddCheck (this IQueryContext context, ObjectName tableName, SqlExpression expression, string constraintName)
 
static void AddCheck (this IQueryContext context, ObjectName tableName, SqlExpression expression, ConstraintDeferrability deferred, string constraintName)
 
static void DropAllTableConstraints (this IQueryContext context, ObjectName tableName)
 
static int DropConstraint (this IQueryContext context, ObjectName tableName, string constraintName)
 
static void AddConstraint (this IQueryContext context, ObjectName tableName, ConstraintInfo constraintInfo)
 
static bool DropPrimaryKey (this IQueryContext context, ObjectName tableName, string constraintName)
 
static void CheckConstraints (this IQueryContext context, ObjectName tableName)
 
static ConstraintInfo[] GetTableCheckExpressions (this IQueryContext context, ObjectName tableName)
 
static ConstraintInfo[] GetTableImportedForeignKeys (this IQueryContext context, ObjectName tableName)
 
static ConstraintInfo[] GetTableForeignKeys (this IQueryContext context, ObjectName tableName)
 
static ConstraintInfo GetTablePrimaryKey (this IQueryContext context, ObjectName tableName)
 
static ConstraintInfo[] GetTableUniqueKeys (this IQueryContext context, ObjectName tableName)
 

Static Package Functions

static void CreateSystemTable (this IQueryContext context, TableInfo tableInfo)
 

Static Private Member Functions

static ICache TableCache (this IQueryContext context)
 

Detailed Description

Definition at line 12 of file QueryContext.Tables.Commands.cs.

Member Function Documentation

static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddCheck ( this IQueryContext  context,
ObjectName  tableName,
SqlExpression  expression,
string  constraintName 
)
inlinestatic

Definition at line 256 of file QueryContextExtensions.Tables.cs.

256  {
257  AddCheck(context, tableName, expression, ConstraintDeferrability.InitiallyImmediate, constraintName);
258  }
ConstraintDeferrability
The type of deferrance of a constraint.
static void AddCheck(this IQueryContext context, ObjectName tableName, SqlExpression expression, string constraintName)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddCheck ( this IQueryContext  context,
ObjectName  tableName,
SqlExpression  expression,
ConstraintDeferrability  deferred,
string  constraintName 
)
inlinestatic

Definition at line 260 of file QueryContextExtensions.Tables.cs.

260  {
261  context.Session().AddCheck(tableName, expression, deferred, constraintName);
262  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddConstraint ( this IQueryContext  context,
ObjectName  tableName,
ConstraintInfo  constraintInfo 
)
inlinestatic

Definition at line 272 of file QueryContextExtensions.Tables.cs.

272  {
273  if (constraintInfo.ConstraintType == ConstraintType.PrimaryKey) {
274  var columnNames = constraintInfo.ColumnNames;
275  if (columnNames.Length > 1)
276  throw new ArgumentException();
277 
278  context.AddPrimaryKey(tableName, columnNames[0], constraintInfo.ConstraintName);
279  } else if (constraintInfo.ConstraintType == ConstraintType.Unique) {
280  context.AddUniqueKey(tableName, constraintInfo.ColumnNames, constraintInfo.ConstraintName);
281  } else if (constraintInfo.ConstraintType == ConstraintType.Check) {
282  context.AddCheck(tableName, constraintInfo.CheckExpression, constraintInfo.ConstraintName);
283  } else if (constraintInfo.ConstraintType == ConstraintType.ForeignKey) {
284  context.AddForeignKey(tableName, constraintInfo.ColumnNames, constraintInfo.ForeignTable,
285  constraintInfo.ForeignColumnNames, constraintInfo.OnDelete, constraintInfo.OnUpdate, constraintInfo.ConstraintName);
286  }
287  }
ConstraintType
An enumeration of all the supported kinds of constraints within a table or a schema.
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddForeignKey ( this IQueryContext  context,
ObjectName  table,
string[]  columns,
ObjectName  refTable,
string[]  refColumns,
ForeignKeyAction  deleteRule,
ForeignKeyAction  updateRule,
String  constraintName 
)
inlinestatic

Definition at line 218 of file QueryContextExtensions.Tables.cs.

220  {
221  AddForeignKey(context, table, columns, refTable, refColumns, deleteRule, updateRule, ConstraintDeferrability.InitiallyImmediate, constraintName);
222  }
ConstraintDeferrability
The type of deferrance of a constraint.
static void AddForeignKey(this IQueryContext context, ObjectName table, string[] columns, ObjectName refTable, string[] refColumns, ForeignKeyAction deleteRule, ForeignKeyAction updateRule, String constraintName)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddForeignKey ( this IQueryContext  context,
ObjectName  table,
string[]  columns,
ObjectName  refTable,
string[]  refColumns,
ForeignKeyAction  deleteRule,
ForeignKeyAction  updateRule,
ConstraintDeferrability  deferred,
String  constraintName 
)
inlinestatic

Definition at line 224 of file QueryContextExtensions.Tables.cs.

226  {
227  if (!context.UserCanAlterTable(table))
228  throw new MissingPrivilegesException(context.UserName(), table, Privileges.Alter);
229  if (!context.UserCanReferenceTable(refTable))
230  throw new MissingPrivilegesException(context.UserName(), refTable, Privileges.References);
231 
232  context.Session().AddForeignKey(table, columns, refTable, refColumns, deleteRule, updateRule, deferred, constraintName);
233  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddPrimaryKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columnNames 
)
inlinestatic

Definition at line 199 of file QueryContextExtensions.Tables.cs.

199  {
200  AddPrimaryKey(context, tableName, columnNames, null);
201  }
static void AddPrimaryKey(this IQueryContext context, ObjectName tableName, string[] columnNames)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddPrimaryKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columnNames,
string  constraintName 
)
inlinestatic

Definition at line 203 of file QueryContextExtensions.Tables.cs.

203  {
204  if (!context.UserCanAlterTable(tableName))
205  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Alter);
206 
207  context.Session().AddPrimaryKey(tableName, columnNames, ConstraintDeferrability.InitiallyImmediate, constraintName);
208  }
ConstraintDeferrability
The type of deferrance of a constraint.
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddPrimaryKey ( this IQueryContext  context,
ObjectName  tableName,
string  columnName 
)
inlinestatic

Definition at line 210 of file QueryContextExtensions.Tables.cs.

210  {
211  AddPrimaryKey(context, tableName, columnName, null);
212  }
static void AddPrimaryKey(this IQueryContext context, ObjectName tableName, string[] columnNames)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddPrimaryKey ( this IQueryContext  context,
ObjectName  tableName,
string  columnName,
string  constraintName 
)
inlinestatic

Definition at line 214 of file QueryContextExtensions.Tables.cs.

214  {
215  context.AddPrimaryKey(tableName, new[] { columnName }, constraintName);
216  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddUniqueKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columns 
)
inlinestatic

Definition at line 235 of file QueryContextExtensions.Tables.cs.

235  {
236  AddUniqueKey(context, tableName, columns, null);
237  }
static void AddUniqueKey(this IQueryContext context, ObjectName tableName, string[] columns)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddUniqueKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columns,
string  constraintName 
)
inlinestatic

Definition at line 239 of file QueryContextExtensions.Tables.cs.

239  {
240  AddUniqueKey(context, tableName, columns, ConstraintDeferrability.InitiallyImmediate, constraintName);
241  }
static void AddUniqueKey(this IQueryContext context, ObjectName tableName, string[] columns)
ConstraintDeferrability
The type of deferrance of a constraint.
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddUniqueKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columns,
ConstraintDeferrability  deferrability 
)
inlinestatic

Definition at line 243 of file QueryContextExtensions.Tables.cs.

244  {
245  AddUniqueKey(context, tableName, columns, deferrability, null);
246  }
static void AddUniqueKey(this IQueryContext context, ObjectName tableName, string[] columns)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AddUniqueKey ( this IQueryContext  context,
ObjectName  tableName,
string[]  columns,
ConstraintDeferrability  deferrability,
string  constraintName 
)
inlinestatic

Definition at line 248 of file QueryContextExtensions.Tables.cs.

249  {
250  if (!context.UserCanAlterTable(tableName))
251  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Alter);
252 
253  context.Session().AddUniqueKey(tableName, columns, deferrability, constraintName);
254  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.AlterTable ( this IQueryContext  context,
TableInfo  tableInfo 
)
inlinestatic

Definition at line 144 of file QueryContextExtensions.Tables.cs.

144  {
145  context.AlterObject(tableInfo);
146  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CacheTable ( this IQueryContext  context,
string  cacheKey,
ITable  table 
)
inlinestatic

Definition at line 181 of file QueryContextExtensions.Tables.cs.

181  {
182  var tableCache = context.TableCache();
183  if (tableCache == null)
184  return;
185 
186  tableCache.Set(cacheKey, table);
187  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CheckConstraints ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 293 of file QueryContextExtensions.Tables.cs.

293  {
294  context.Session().CheckConstraintViolations(tableName);
295  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.ClearCachedTables ( this IQueryContext  context)
inlinestatic

Definition at line 189 of file QueryContextExtensions.Tables.cs.

189  {
190  var tableCache = context.TableCache();
191  if (tableCache == null)
192  return;
193 
194  tableCache.Clear();
195  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CreateSystemTable ( this IQueryContext  context,
TableInfo  tableInfo 
)
inlinestaticpackage

Definition at line 71 of file QueryContextExtensions.Tables.cs.

71  {
72  if (tableInfo == null)
73  throw new ArgumentNullException("tableInfo");
74 
75  var tableName = tableInfo.TableName;
76 
77  if (!context.UserCanCreateTable(tableName))
78  throw new MissingPrivilegesException(context.User().Name, tableName, Privileges.Create);
79 
80  context.Session().CreateTable(tableInfo, false);
81  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CreateTable ( this IQueryContext  context,
TableInfo  tableInfo 
)
inlinestatic

Definition at line 39 of file QueryContextExtensions.Tables.cs.

39  {
40  CreateTable(context, tableInfo, false);
41  }
static void CreateTable(this IQueryContext context, TableInfo tableInfo)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CreateTable ( this IQueryContext  context,
TableInfo  tableInfo,
bool  onlyIfNotExists 
)
inlinestatic

Definition at line 43 of file QueryContextExtensions.Tables.cs.

43  {
44  CreateTable(context, tableInfo, onlyIfNotExists, false);
45  }
static void CreateTable(this IQueryContext context, TableInfo tableInfo)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.CreateTable ( this IQueryContext  context,
TableInfo  tableInfo,
bool  onlyIfNotExists,
bool  temporary 
)
inlinestatic

Definition at line 47 of file QueryContextExtensions.Tables.cs.

47  {
48  if (tableInfo == null)
49  throw new ArgumentNullException("tableInfo");
50 
51  var tableName = tableInfo.TableName;
52 
53  if (!context.UserCanCreateTable(tableName))
54  throw new MissingPrivilegesException(context.User().Name, tableName, Privileges.Create);
55 
56  if (context.TableExists(tableName)) {
57  if (!onlyIfNotExists)
58  throw new InvalidOperationException(
59  String.Format("The table {0} already exists and the IF NOT EXISTS clause was not specified.", tableName));
60 
61  return;
62  }
63 
64  context.Session().CreateTable(tableInfo, temporary);
65 
66  using (var systemContext = context.ForSystemUser()) {
67  systemContext.GrantToUserOnTable(tableInfo.TableName, context.User().Name, Privileges.TableAll);
68  }
69  }
A long string in the system.
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DeleteFrom ( this IQuery  context,
ObjectName  tableName,
SqlQueryExpression  query 
)
inlinestatic

Definition at line 13 of file QueryContext.Tables.Commands.cs.

13  {
14  return DeleteFrom(context, tableName, query, -1);
15  }
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query)
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DeleteFrom ( this IQuery  context,
ObjectName  tableName,
SqlExpression  expression 
)
inlinestatic

Definition at line 17 of file QueryContext.Tables.Commands.cs.

17  {
18  return DeleteFrom(context, tableName, expression, -1);
19  }
static int DeleteFrom(this IQuery context, ObjectName tableName, SqlQueryExpression query)
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DeleteFrom ( this IQuery  context,
ObjectName  tableName,
SqlExpression  expression,
int  limit 
)
inlinestatic

Definition at line 21 of file QueryContext.Tables.Commands.cs.

21  {
22  if (expression is SqlQueryExpression)
23  return context.DeleteFrom(tableName, (SqlQueryExpression)expression, limit);
24 
25  var table = context.GetMutableTable(tableName);
26  if (table == null)
27  throw new ObjectNotFoundException(tableName);
28 
29  var queryExpression = new SqlQueryExpression(new List<SelectColumn> { SelectColumn.Glob("*") });
30  queryExpression.FromClause.AddTable(tableName.Name);
31  queryExpression.WhereExpression = expression;
32 
33  var planExpression = queryExpression.Evaluate(context, null);
34  var plan = (SqlQueryObject)((SqlConstantExpression)planExpression).Value.Value;
35  var deleteSet = plan.QueryPlan.Evaluate(context);
36 
37  return context.DeleteFrom(tableName, deleteSet, limit);
38  }
virtual SqlExpression Evaluate(EvaluateContext context)
When overridden by a derived class, this method evaluates the expression within the provided context...
Represents a column selected to be in the output of a select statement.
Definition: SelectColumn.cs:31
An expression that holds a constant value.
static SelectColumn Glob(string glob)
Creates a special SelectColumn that is used to select all the columns in a table. ...
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DeleteFrom ( this IQuery  context,
ObjectName  tableName,
SqlQueryExpression  query,
int  limit 
)
inlinestatic

Definition at line 40 of file QueryContext.Tables.Commands.cs.

40  {
41  IQueryPlanNode plan;
42 
43  try {
44  var planValue = query.EvaluateToConstant(context, null);
45  if (planValue == null)
46  throw new InvalidOperationException();
47 
48  if (!(planValue.Type is QueryType))
49  throw new InvalidOperationException();
50 
51  plan = ((SqlQueryObject)planValue.Value).QueryPlan;
52  } catch (QueryException) {
53  throw;
54  } catch (SecurityException) {
55  throw;
56  } catch (Exception ex) {
57  throw new InvalidOperationException(String.Format("Could not delete from table '{0}': unable to form the delete set.", tableName), ex);
58  }
59 
60  var deleteSet = plan.Evaluate(context);
61  return context.DeleteFrom(tableName, deleteSet, limit);
62  }
A long string in the system.
ITable Evaluate(IRequest context)
A node element of a query plan tree. /summary>
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DeleteFrom ( this IQuery  context,
ObjectName  tableName,
ITable  deleteSet,
int  limit 
)
inlinestatic

Definition at line 64 of file QueryContext.Tables.Commands.cs.

64  {
65  if (!context.UserCanDeleteFromTable(tableName))
66  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Delete);
67 
68  var table = context.GetMutableTable(tableName);
69  if (table == null)
70  throw new ObjectNotFoundException(tableName);
71 
72  return table.Delete(deleteSet, limit);
73  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.DropAllTableConstraints ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 264 of file QueryContextExtensions.Tables.cs.

264  {
265  context.Session().DropAllTableConstraints(tableName);
266  }
static int Deveel.Data.Sql.Tables.QueryContextExtensions.DropConstraint ( this IQueryContext  context,
ObjectName  tableName,
string  constraintName 
)
inlinestatic

Definition at line 268 of file QueryContextExtensions.Tables.cs.

268  {
269  return context.Session().DropTableConstraint(tableName, constraintName);
270  }
static bool Deveel.Data.Sql.Tables.QueryContextExtensions.DropPrimaryKey ( this IQueryContext  context,
ObjectName  tableName,
string  constraintName 
)
inlinestatic

Definition at line 289 of file QueryContextExtensions.Tables.cs.

289  {
290  return context.Session().DropTablePrimaryKey(tableName, constraintName);
291  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.DropTable ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 136 of file QueryContextExtensions.Tables.cs.

136  {
137  DropTable(context, tableName, false);
138  }
static void DropTable(this IQueryContext context, ObjectName tableName)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.DropTable ( this IQueryContext  context,
ObjectName  tableName,
bool  onlyIfExists 
)
inlinestatic

Definition at line 140 of file QueryContextExtensions.Tables.cs.

140  {
141  context.DropTables(new[] {tableName}, onlyIfExists);
142  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.DropTables ( this IQueryContext  context,
IEnumerable< ObjectName tableNames 
)
inlinestatic

Definition at line 83 of file QueryContextExtensions.Tables.cs.

83  {
84  DropTables(context, tableNames, false);
85  }
static void DropTables(this IQueryContext context, IEnumerable< ObjectName > tableNames)
static void Deveel.Data.Sql.Tables.QueryContextExtensions.DropTables ( this IQueryContext  context,
IEnumerable< ObjectName tableNames,
bool  onlyIfExists 
)
inlinestatic

Definition at line 87 of file QueryContextExtensions.Tables.cs.

87  {
88  var tableNameList = tableNames.ToList();
89  foreach (var tableName in tableNameList) {
90  if (!context.UserCanDropObject(DbObjectType.Table, tableName))
91  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Drop);
92  }
93 
94  // Check there are no referential links to any tables being dropped
95  foreach (var tableName in tableNameList) {
96  var refs = context.GetTableImportedForeignKeys(tableName);
97 
98  foreach (var reference in refs) {
99  // If the key table isn't being dropped then error
100  if (!tableNameList.Contains(reference.TableName)) {
101  throw new ConstraintViolationException(SqlModelErrorCodes.DropTableViolation,
102  String.Format("Constraint violation ({0}) dropping table '{1}' because of referential link from '{2}'",
103  reference.ConstraintName, tableName, reference.TableName));
104  }
105  }
106  }
107 
108  // If the 'only if exists' flag is false, we need to check tables to drop
109  // exist first.
110  if (!onlyIfExists) {
111  // For each table to drop.
112  foreach (var tableName in tableNameList) {
113  // If table doesn't exist, throw an error
114  if (!context.TableExists(tableName)) {
115  throw new InvalidOperationException(String.Format("The table '{0}' does not exist and cannot be dropped.",
116  tableName));
117  }
118  }
119  }
120 
121  foreach (var tname in tableNameList) {
122  // Does the table already exist?
123  if (context.TableExists(tname)) {
124  // Drop table in the transaction
125  context.DropObject(DbObjectType.Table, tname);
126 
127  // Revoke all the grants on the table
128  context.RevokeAllGrantsOnTable(tname);
129 
130  // Drop all constraints from the schema
131  context.DropAllTableConstraints(tname);
132  }
133  }
134  }
A long string in the system.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static ITable Deveel.Data.Sql.Tables.QueryContextExtensions.GetCachedTable ( this IQueryContext  context,
string  cacheKey 
)
inlinestatic

Definition at line 169 of file QueryContextExtensions.Tables.cs.

169  {
170  var tableCache = context.TableCache();
171  if (tableCache == null)
172  return null;
173 
174  object obj;
175  if (!tableCache.TryGet(cacheKey, out obj))
176  return null;
177 
178  return obj as ITable;
179  }
static IMutableTable Deveel.Data.Sql.Tables.QueryContextExtensions.GetMutableTable ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 161 of file QueryContextExtensions.Tables.cs.

161  {
162  return context.GetTable(tableName) as IMutableTable;
163  }
static ITable Deveel.Data.Sql.Tables.QueryContextExtensions.GetTable ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 148 of file QueryContextExtensions.Tables.cs.

148  {
149  var table = context.GetCachedTable(tableName.FullName) as ITable;
150  if (table == null) {
151  table = context.Session().GetTable(tableName);
152  if (table != null) {
153  table = new UserContextTable(context, table);
154  context.CacheTable(tableName.FullName, table);
155  }
156  }
157 
158  return table;
159  }
static ConstraintInfo [] Deveel.Data.Sql.Tables.QueryContextExtensions.GetTableCheckExpressions ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 297 of file QueryContextExtensions.Tables.cs.

297  {
298  return context.Session().QueryTableCheckExpressions(tableName);
299  }
static ConstraintInfo [] Deveel.Data.Sql.Tables.QueryContextExtensions.GetTableForeignKeys ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 305 of file QueryContextExtensions.Tables.cs.

305  {
306  return context.Session().QueryTableForeignKeys(tableName);
307  }
static ConstraintInfo [] Deveel.Data.Sql.Tables.QueryContextExtensions.GetTableImportedForeignKeys ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 301 of file QueryContextExtensions.Tables.cs.

301  {
302  return context.Session().QueryTableImportedForeignKeys(tableName);
303  }
static ConstraintInfo Deveel.Data.Sql.Tables.QueryContextExtensions.GetTablePrimaryKey ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 309 of file QueryContextExtensions.Tables.cs.

309  {
310  return context.Session().QueryTablePrimaryKey(tableName);
311  }
static ConstraintInfo [] Deveel.Data.Sql.Tables.QueryContextExtensions.GetTableUniqueKeys ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 313 of file QueryContextExtensions.Tables.cs.

313  {
314  return context.Session().QueryTableUniqueKeys(tableName);
315  }
static void Deveel.Data.Sql.Tables.QueryContextExtensions.InsertIntoTable ( this IQuery  context,
ObjectName  tableName,
IEnumerable< SqlAssignExpression assignments 
)
inlinestatic

Definition at line 95 of file QueryContext.Tables.Commands.cs.

95  {
96  var columnNames =
97  assignments.Select(x => x.ReferenceExpression)
98  .Cast<SqlReferenceExpression>()
99  .Select(x => x.ReferenceName.Name).ToArray();
100  if (!context.UserCanInsertIntoTable(tableName, columnNames))
101  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Insert);
102 
103  var table = context.GetMutableTable(tableName);
104 
105  var row = table.NewRow();
106  foreach (var expression in assignments) {
107  row.EvaluateAssignment(expression, context);
108  }
109 
110  table.AddRow(row);
111  }
An expression that references an object within a context.
static int Deveel.Data.Sql.Tables.QueryContextExtensions.InsertIntoTable ( this IQuery  context,
ObjectName  tableName,
IEnumerable< SqlAssignExpression[]>  assignments 
)
inlinestatic

Definition at line 113 of file QueryContext.Tables.Commands.cs.

114  {
115  int insertCount = 0;
116 
117  foreach (var assignment in assignments) {
118  context.InsertIntoTable(tableName, assignment);
119  insertCount++;
120  }
121 
122  return insertCount;
123  }
static ObjectName Deveel.Data.Sql.Tables.QueryContextExtensions.ResolveTableName ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 14 of file QueryContextExtensions.Tables.cs.

14  {
15  return context.Session().ResolveTableName(tableName);
16  }
static ObjectName Deveel.Data.Sql.Tables.QueryContextExtensions.ResolveTableName ( this IQueryContext  context,
string  name 
)
inlinestatic

Definition at line 18 of file QueryContextExtensions.Tables.cs.

18  {
19  var schema = context.CurrentSchema;
20  if (String.IsNullOrEmpty(schema))
21  throw new InvalidOperationException("Default schema not specified in the context.");
22 
23  var objSchemaName = context.ResolveSchemaName(schema);
24  if (objSchemaName == null)
25  throw new InvalidOperationException(
26  String.Format("The default schema of the session '{0}' is not defined in the database.", schema));
27 
28  var objName = ObjectName.Parse(name);
29  if (objName.Parent == null)
30  objName = new ObjectName(objSchemaName, objName.Name);
31 
32  return context.ResolveTableName(objName);
33  }
A long string in the system.
static ICache Deveel.Data.Sql.Tables.QueryContextExtensions.TableCache ( this IQueryContext  context)
inlinestaticprivate

Definition at line 165 of file QueryContextExtensions.Tables.cs.

165  {
166  return context.ResolveService<ICache>("TableCache");
167  }
Provides a contract to access a caching system.
Definition: ICache.cs:25
static bool Deveel.Data.Sql.Tables.QueryContextExtensions.TableExists ( this IQueryContext  context,
ObjectName  tableName 
)
inlinestatic

Definition at line 35 of file QueryContextExtensions.Tables.cs.

35  {
36  return context.ObjectExists(DbObjectType.Table, tableName);
37  }
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static int Deveel.Data.Sql.Tables.QueryContextExtensions.UpdateTable ( this IQuery  context,
ObjectName  tableName,
IQueryPlanNode  queryPlan,
IEnumerable< SqlAssignExpression assignments,
int  limit 
)
inlinestatic

Definition at line 75 of file QueryContext.Tables.Commands.cs.

76  {
77  var columnNames = assignments.Select(x => x.ReferenceExpression)
78  .Cast<SqlReferenceExpression>()
79  .Select(x => x.ReferenceName.Name).ToArray();
80 
81  if (!context.UserCanUpdateTable(tableName, columnNames))
82  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Update);
83 
84  if (!context.UserCanSelectFromPlan(queryPlan))
85  throw new InvalidOperationException();
86 
87  var table = context.GetMutableTable(tableName);
88  if (table == null)
89  throw new ObjectNotFoundException(tableName);
90 
91  var updateSet = queryPlan.Evaluate(context);
92  return table.Update(context, updateSet, assignments, limit);
93  }
An expression that references an object within a context.
ITable Evaluate(IRequest context)

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