public static void DeleteRows(this IMutableTable table, IEnumerable <int> rows) { foreach (var row in rows) { table.RemoveRow(row); } }
private static int InsertIntoTable(IMutableTable table, ICursor cursor) { int addedd = 0; bool verified = false; foreach (var row in cursor) { if (!verified) { if (AreCompatible(table.TableInfo, cursor.Source.TableInfo)) { throw new StatementException("The source cursor is not compatible to the destination table."); } verified = true; } var newRow = table.NewRow(); for (int i = 0; i < row.ColumnCount; i++) { newRow.SetValue(i, row.GetValue(i)); } table.AddRow(newRow); addedd++; } return(addedd); }
public ConfigurableLrTable(ILrDfa dfa, RuntimeOptions flags) { this.grammar = dfa.GrammarAnalysis; this.data = new MutableTable<int>(dfa.States.Length, grammar.Symbols.Count); Configure(dfa, flags, out underlyingTable); }
public ConfigurableLrTable(ILrDfa dfa, RuntimeOptions flags) { this.grammar = dfa.GrammarAnalysis; this.data = new MutableTable <int>(dfa.States.Length, grammar.Symbols.Count); Configure(dfa, flags, out underlyingTable); }
public UpdatableResultSetView(SystemTransaction transaction, IMutableTable backedTable, Expression[] project, IRowCursor select) { this.transaction = transaction; this.backedTable = backedTable; this.project = project; originalSelect = select; currentSelect = select; this.select = null; }
public CanonicalLrDfaTable(ILrDfa dfa, IMutableTable<int> actionTable) { var flag = LrTableOptimizations.EliminateLr0ReduceStates; this.canOptimizeReduceStates = (dfa.Optimizations & flag) == flag; this.grammar = dfa.GrammarAnalysis; this.actionTable = actionTable ?? new MutableTable<int>(dfa.States.Length, grammar.Symbols.Count); FillDfaTable(dfa.States); BuildConflictTable(); }
public ReductionModifiedLrDfaTable(ILrDfa dfa, IMutableTable<int> actionTable = null) { var flag = LrTableOptimizations.EliminateLr0ReduceStates; this.canOptimizeReduceStates = (dfa.Optimizations & flag) == flag; this.grammar = dfa.GrammarAnalysis; var states = dfa.States; this.actionTable = actionTable ?? new MutableTable<int>(states.Length, dfa.GrammarAnalysis.Symbols.Count); FillDfaTable(states); BuildConflictActionTable(); }
public static bool Delete(this IMutableTable table, int columnOffset, DataObject value) { var list = table.SelectRowsEqual(columnOffset, value).ToArray(); if (list.Length == 0) { return(false); } return(table.RemoveRow(list[0])); }
public CanonicalLrDfaTable(ILrDfa dfa, IMutableTable <int> actionTable) { var flag = LrTableOptimizations.EliminateLr0ReduceStates; this.canOptimizeReduceStates = (dfa.Optimizations & flag) == flag; this.grammar = dfa.GrammarAnalysis; this.actionTable = actionTable ?? new MutableTable <int>(dfa.States.Length, grammar.Symbols.Count); FillDfaTable(dfa.States); BuildConflictTable(); }
public ReductionModifiedLrDfaTable(ILrDfa dfa, IMutableTable <int> actionTable = null) { var flag = LrTableOptimizations.EliminateLr0ReduceStates; this.canOptimizeReduceStates = (dfa.Optimizations & flag) == flag; this.grammar = dfa.GrammarAnalysis; var states = dfa.States; this.actionTable = actionTable ?? new MutableTable <int>(states.Length, dfa.GrammarAnalysis.Symbols.Count); FillDfaTable(states); BuildConflictActionTable(); }
private static void RevokeAllGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType, ObjectName objectName, string revoker, string grantee, bool withOption = false) { var objectCol = grantTable.GetResolvedColumnName(1); var paramCol = grantTable.GetResolvedColumnName(2); var granteeCol = grantTable.GetResolvedColumnName(3); var grantOptionCol = grantTable.GetResolvedColumnName(4); var granterCol = grantTable.GetResolvedColumnName(5); ITable t1 = grantTable; // All that match the given object parameter // It's most likely this will reduce the search by the most so we do // it first. t1 = t1.SimpleSelect(queryContext, paramCol, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(objectName.FullName))); // The next is a single exhaustive select through the remaining records. // It finds all grants that match either public or the grantee is the // user or role, and that match the object type. // Expression: ("grantee_col" = grantee) var userCheck = SqlExpression.Equal(SqlExpression.Reference(granteeCol), SqlExpression.Constant(Field.String(grantee))); // Expression: ("object_col" = object AND // "grantee_col" = grantee) // All that match the given grantee or public and given object var expr = SqlExpression.And( SqlExpression.Equal(SqlExpression.Reference(objectCol), SqlExpression.Constant(Field.BigInt((int)objectType))), userCheck); // Are we only searching for grant options? var grantOptionCheck = SqlExpression.Equal(SqlExpression.Reference(grantOptionCol), SqlExpression.Constant(Field.Boolean(withOption))); expr = SqlExpression.And(expr, grantOptionCheck); // Make sure the granter matches up also var granterCheck = SqlExpression.Equal(SqlExpression.Reference(granterCol), SqlExpression.Constant(Field.String(revoker))); expr = SqlExpression.And(expr, granterCheck); t1 = t1.ExhaustiveSelect(queryContext, expr); // Remove these rows from the table grantTable.Delete(t1); }
private static void UpdateGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType, ObjectName objectName, string granter, string grantee, Privileges privileges, bool withOption) { RevokeAllGrants(queryContext, grantTable, objectType, objectName, granter, grantee, withOption); if (privileges != Privileges.None) { // Add the grant to the grants table. var row = grantTable.NewRow(); row.SetValue(0, (int)privileges); row.SetValue(1, (int)objectType); row.SetValue(2, objectName.FullName); row.SetValue(3, grantee); row.SetValue(4, withOption); row.SetValue(5, granter); grantTable.AddRow(row); } }
public void DeleteCurrent(IMutableTable table, IRequest request) { AssertNotDisposed(); AssertNotClosed(); var pkey = request.Query.Session.Transaction.QueryTablePrimaryKey(table.TableInfo.TableName); if (pkey == null) { throw new MissingPrimaryKeyException(table.TableInfo.TableName); } var colIndexes = new int[pkey.ColumnNames.Length]; for (int i = 0; i < colIndexes.Length; i++) { var colIdx = table.TableInfo.IndexOfColumn(pkey.ColumnNames[i]); colIndexes[i] = colIdx; } var currentRow = State.CurrentRow; var values = new Field[colIndexes.Length]; for (int i = 0; i < colIndexes.Length; i++) { values[i] = currentRow.GetValue(colIndexes[i]); } ITable deleteSet = table; for (int i = 0; i < colIndexes.Length; i++) { deleteSet = deleteSet.SelectEqual(colIndexes[i], values[i]); } if (deleteSet.RowCount == 0) { return; } table.Delete(deleteSet, 1); }
private void InsertIntoTable(IMutableTable table) { var row = table.NewRow(); row.SetValue(0, "Antonello Provenzano"); row.SetValue(1, 33); row.SetValue(2, 0); table.AddRow(row); row = table.NewRow(); row.SetValue(0, "Maart Roosmaa"); row.SetValue(1, 28); row.SetValue(2, 5); table.AddRow(row); row = table.NewRow(); row.SetValue(0, "Rezaul Horaque"); row.SetValue(1, 27); row.SetValue(2, 2); table.AddRow(row); }
private void SelectIntoTable(IMutableTable table, ITable result) { if (!AreCompatible(table.TableInfo, result.TableInfo)) { throw new InvalidOperationException(); } for (int i = 0; i < result.RowCount; i++) { var newRow = table.NewRow(); for (int j = 0; j < result.ColumnCount(); j++) { var value = result.GetValue(i, j); newRow.SetValue(j, value); } table.AddRow(newRow); } }
private static void UpdateGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType, ObjectName objectName, string granter, string grantee, Privileges privileges, bool withOption) { RevokeAllGrants(queryContext, grantTable, objectType, objectName, granter, grantee, withOption); if (privileges != Privileges.None) { // Add the grant to the grants table. var row = grantTable.NewRow(); row.SetValue(0, (int) privileges); row.SetValue(1, (int) objectType); row.SetValue(2, objectName.FullName); row.SetValue(3, grantee); row.SetValue(4, withOption); row.SetValue(5, granter); grantTable.AddRow(row); } }
internal static void SetInsertRowToDefault(SystemTransaction transaction, TableName table_name, IMutableTable table, RowId rowid) { // Get all column defaults on the table IList<object> table_defaults = transaction.QueryTableDefaults(table_name); int sz = table_defaults.Count / 2; // Exit quickly if there's no default values if (sz == 0) return; // Create a query processor QueryProcessor processor = new QueryProcessor(transaction); // For each default value, TableRow row = table.GetRow(rowid); for (int i = 0; i < sz; ++i) { string colName = (string)table_defaults[i * 2]; Expression colDefault = (Expression)table_defaults[(i * 2) + 1]; // Execute the default value expression ITable defaultResult = processor.Execute(colDefault); // Turn it into a TObject SqlObject val = defaultResult.GetValue(0, new RowId(0)); // The col num of the column name int colIndex = table.Columns.IndexOf(colName); if (colIndex < 0) throw new ApplicationException("Column '" + colName + "' not found for DEFAULT value"); // And insert it row.SetValue(colIndex, val); } }
private QueryResult TableUpdatable(IMutableTable table) { return new QueryResult(new EmbeddedSessionContext.EmbeddedQueryContext(table, transaction, new Object())); }
internal Prepared(IQueryPlanNode queryPlan, IMutableTable table) : this(queryPlan) { IsForTable = true; Table = table; }
internal static void CompleteRowUpdate(SystemTransaction transaction, IMutableTable table, TableName tableName, RowId beforeRowid, RowId afterRowid) { IIndexSetDataSource[] ids = transaction.GetTableIndexes(tableName); foreach (IIndexSetDataSource i in ids) { i.Remove(beforeRowid); i.Insert(afterRowid); } // TODO: check for constraint violations table.Commit(); }
internal void AccessTable(IMutableTable table) { lock (accessedTables) { accessedTables.Add(table); } }
private void SelectIntoTable(IMutableTable table, ITable result) { if (!AreCompatible(table.TableInfo, result.TableInfo)) throw new InvalidOperationException(); for (int i = 0; i < result.RowCount; i++) { var newRow = table.NewRow(); for (int j = 0; j < result.ColumnCount(); j++) { var value = result.GetValue(i, j); newRow.SetValue(j, value); } table.AddRow(newRow); } }
private static void RevokeAllGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType, ObjectName objectName, string revoker, string grantee, bool withOption = false) { var objectCol = grantTable.GetResolvedColumnName(1); var paramCol = grantTable.GetResolvedColumnName(2); var granteeCol = grantTable.GetResolvedColumnName(3); var grantOptionCol = grantTable.GetResolvedColumnName(4); var granterCol = grantTable.GetResolvedColumnName(5); ITable t1 = grantTable; // All that match the given object parameter // It's most likely this will reduce the search by the most so we do // it first. t1 = t1.SimpleSelect(queryContext, paramCol, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(objectName.FullName))); // The next is a single exhaustive select through the remaining records. // It finds all grants that match either public or the grantee is the // user or role, and that match the object type. // Expression: ("grantee_col" = grantee) var userCheck = SqlExpression.Equal(SqlExpression.Reference(granteeCol), SqlExpression.Constant(Field.String(grantee))); // Expression: ("object_col" = object AND // "grantee_col" = grantee) // All that match the given grantee or public and given object var expr = SqlExpression.And( SqlExpression.Equal(SqlExpression.Reference(objectCol), SqlExpression.Constant(Field.BigInt((int) objectType))), userCheck); // Are we only searching for grant options? var grantOptionCheck = SqlExpression.Equal(SqlExpression.Reference(grantOptionCol), SqlExpression.Constant(Field.Boolean(withOption))); expr = SqlExpression.And(expr, grantOptionCheck); // Make sure the granter matches up also var granterCheck = SqlExpression.Equal(SqlExpression.Reference(granterCol), SqlExpression.Constant(Field.String(revoker))); expr = SqlExpression.And(expr, granterCheck); t1 = t1.ExhaustiveSelect(queryContext, expr); // Remove these rows from the table grantTable.Delete(t1); }
public static int Delete(this IMutableTable table, ITable other, int limit) { List <int> rowSet = new List <int>(other.RowCount); var e = other.GetEnumerator(); while (e.MoveNext()) { rowSet.Add(e.Current.RowId.RowNumber); } // HACKY: Find the first column of this table in the search table. This // will allow us to generate a row set of only the rows in the search // table. int firstColumn = other.IndexOfColumn(table.GetResolvedColumnName(0)); if (firstColumn == -1) { throw new DatabaseSystemException("Search table does not contain any reference to table being deleted from"); } // Generate a row set that is in this tables domain. var rowsToDelete = other.ResolveRows(firstColumn, rowSet, table).ToList(); // row_set may contain duplicate row indices, therefore we must sort so // any duplicates are grouped and therefore easier to find. rowSet.Sort(); // If limit less than zero then limit is whole set. if (limit < 0) { limit = Int32.MaxValue; } // Remove each row in row set in turn. Make sure we don't remove the // same row index twice. int len = System.Math.Min(rowsToDelete.Count, limit); int lastRemoved = -1; int removeCount = 0; for (int i = 0; i < len; ++i) { int toRemove = rowsToDelete[i]; if (toRemove < lastRemoved) { throw new DatabaseSystemException("Internal error: row sorting error or row set not in the range > 0"); } if (toRemove != lastRemoved) { table.RemoveRow(toRemove); lastRemoved = toRemove; ++removeCount; } } if (removeCount > 0) { // Perform a referential integrity check on any changes to the table. table.AssertConstraints(); } return(removeCount); }
public static int Update(this IMutableTable mutableTable, IQuery context, ITable table, IEnumerable <SqlAssignExpression> assignList, int limit) { // Get the rows from the input table. var rowSet = new List <int>(); var e = table.GetEnumerator(); while (e.MoveNext()) { rowSet.Add(e.Current.RowId.RowNumber); } // HACKY: Find the first column of this table in the search table. This // will allow us to generate a row set of only the rows in the search // table. int firstColumn = table.FindColumn(mutableTable.GetResolvedColumnName(0)); if (firstColumn == -1) { throw new InvalidOperationException("Search table does not contain any " + "reference to table being updated from"); } // Convert the row_set to this table's domain. rowSet = table.ResolveRows(firstColumn, rowSet, mutableTable).ToList(); // NOTE: Assume there's no duplicate rows. // If limit less than zero then limit is whole set. if (limit < 0) { limit = Int32.MaxValue; } // Update each row in row set in turn up to the limit. int len = System.Math.Min(rowSet.Count, limit); int updateCount = 0; for (int i = 0; i < len; ++i) { int toUpdate = rowSet[i]; // Make a row object from this row (plus keep the original intact // in case we need to roll back to it). var row = mutableTable.GetRow(toUpdate); row.SetFromTable(); // Run each assignment on the row. foreach (var assignment in assignList) { row.EvaluateAssignment(assignment, context); } // Update the row mutableTable.UpdateRow(row); ++updateCount; } if (updateCount > 0) { // Perform a referential integrity check on any changes to the table. mutableTable.AssertConstraints(); } return(updateCount); }
/// <summary> /// Creates a new row that is compatible with the /// table context, ready to be populated and added. /// </summary> /// <remarks> /// <para> /// When this method is called, a new <see cref="RowId"/> /// is generated and persisted: when a subsequent call to /// this method will be issued, another new row identifier /// will be generated, even if the row was not persisted /// into the table. /// </para> /// </remarks> /// <returns> /// Returns an instance of <see cref="Row"/> that /// belongs to this table and can be added or updated through /// <see cref="IMutableTable.AddRow"/> or <see cref="IMutableTable.UpdateRow"/> /// method calls. /// </returns> public static Row NewRow(this IMutableTable table) { return(new Row(table)); }
public static bool RemoveRow(this IMutableTable table, int rowIndex) { return(table.RemoveRow(new RowId(table.TableInfo.Id, rowIndex))); }
public static int Delete(this IMutableTable table, ITable t) { return(Delete(table, t, -1)); }
private static int InsertIntoTable(IMutableTable table, ICursor cursor) { int addedd = 0; bool verified = false; foreach (var row in cursor) { if (!verified) { if (AreCompatible(table.TableInfo, cursor.Source.TableInfo)) throw new StatementException("The source cursor is not compatible to the destination table."); verified = true; } var newRow = table.NewRow(); for (int i = 0; i < row.ColumnCount; i++) { newRow.SetValue(i, row.GetValue(i)); } table.AddRow(newRow); addedd++; } return addedd; }