Exemplo n.º 1
0
 internal OldNewTableState(ObjectName tableSource, int oldRowIndex, Row newDataRow, bool newMutable)
 {
     TableSource = tableSource;
     OldRowIndex = oldRowIndex;
     NewDataRow = newDataRow;
     IsNewMutable = newMutable;
 }
Exemplo n.º 2
0
                public void UpdateRow(Row row)
                {
                    if (row.RowId.RowNumber < 0 ||
                        row.RowId.RowNumber >= 1)
                        throw new ArgumentOutOfRangeException();
                    if (readOnly)
                        throw new NotSupportedException(String.Format("Updating '{0}' is not permitted.", tableInfo.TableName));

                    int sz = TableInfo.ColumnCount;
                    for (int i = 0; i < sz; ++i) {
                        data.SetValue(i, row.GetValue(i));
                    }
                }
Exemplo n.º 3
0
 public void SetData(Row row)
 {
     data = row;
 }
Exemplo n.º 4
0
 public RowId AddRow(Row row)
 {
     throw new NotSupportedException(String.Format("Inserting data into '{0}' is not allowed.", tableInfo.TableName));
 }
Exemplo n.º 5
0
            public ITable GetTable(int offset)
            {
                var tableInfo = GetTableInfo(offset);

                var table = new TriggeredOldNew(transaction.DatabaseContext, tableInfo);

                if (HasOldTable) {
                    if (offset == 0) {
                        // Copy data from the table to the new table
                        var dtable = transaction.GetTable(transaction.TableState.TableSource);
                        var oldRow = new Row(table);
                        int rowIndex = transaction.TableState.OldRowIndex;
                        for (int i = 0; i < tableInfo.ColumnCount; ++i) {
                            oldRow.SetValue(i, dtable.GetValue(rowIndex, i));
                        }

                        // All OLD tables are immutable
                        table.SetReadOnly(true);
                        table.SetData(oldRow);

                        return table;
                    }
                }

                table.SetReadOnly(!transaction.TableState.IsNewMutable);
                table.SetData(transaction.TableState.NewDataRow);

                return table;
            }
Exemplo n.º 6
0
        public RowId AddRow(Row row)
        {
            OnTableEvent(TriggerEventType.BeforeInsert, RowId.Null, row);

            var newRowId = MutableTable.AddRow(row);

            OnTableEvent(TriggerEventType.AfterInsert, newRowId, row);

            return newRowId;
        }
Exemplo n.º 7
0
 private void OnTableEvent(TriggerEventType eventType, RowId rowId, Row row)
 {
     Context.FireTrigger(new TableEventContext(this, eventType, rowId, row));
 }
Exemplo n.º 8
0
        public void UpdateRow(Row row)
        {
            if (row == null)
                throw new ArgumentNullException("row");

            var rowId = row.RowId;
            if (rowId.IsNull)
                throw new ArgumentException("Cannot update a row with NULL ROWID");

            OnTableEvent(TriggerEventType.BeforeUpdate, rowId, row);

            MutableTable.UpdateRow(row);
        }
Exemplo n.º 9
0
 public RowVariableResolver(Row row)
 {
     this.row = row;
 }
Exemplo n.º 10
0
        public static void SetUserStatus(this IQueryContext queryContext, string username, UserStatus status)
        {
            if (!queryContext.UserCanManageUsers())
                throw new MissingPrivilegesException(queryContext.UserName(), new ObjectName(username), Privileges.Alter,
                    String.Format("User '{0}' cannot change the status of user '{1}'", queryContext.UserName(), username));

            // Internally we implement this by adding the user to the #locked group.
            var table = queryContext.GetMutableTable(SystemSchema.UserPrivilegesTableName);
            var c1 = table.GetResolvedColumnName(0);
            var c2 = table.GetResolvedColumnName(1);
            // All 'user_priv' where UserName = %username%
            var t = table.SimpleSelect(queryContext, c1, SqlExpressionType.Equal, SqlExpression.Constant(username));
            // All from this set where PrivGroupName = %group%
            t = t.SimpleSelect(queryContext, c2, SqlExpressionType.Equal, SqlExpression.Constant(SystemGroupNames.LockGroup));

            bool userBelongsToLockGroup = t.RowCount > 0;
            if (status == UserStatus.Locked &&
                !userBelongsToLockGroup) {
                // Lock the user by adding the user to the Lock group
                // Add this user to the locked group.
                var rdat = new Row(table);
                rdat.SetValue(0, username);
                rdat.SetValue(1, SystemGroupNames.LockGroup);
                table.AddRow(rdat);
            } else if (status == UserStatus.Unlocked &&
                userBelongsToLockGroup) {
                // Unlock the user by removing the user from the Lock group
                // Remove this user from the locked group.
                table.Delete(t);
            }
        }
Exemplo n.º 11
0
 public static void GrantHostAccessToUser(this IQueryContext queryContext, string user, string protocol, string host)
 {
     // The user connect priv table
     var table = queryContext.GetMutableTable(SystemSchema.UserConnectPrivilegesTableName);
     // Add the protocol and host to the table
     var rdat = new Row(table);
     rdat.SetValue(0, user);
     rdat.SetValue(1, protocol);
     rdat.SetValue(2, host);
     rdat.SetValue(3, true);
     table.AddRow(rdat);
 }
Exemplo n.º 12
0
        public static void SetUserLock(this IQueryContext queryContext, string username, bool lockStatus)
        {
            // Internally we implement this by adding the user to the #locked group.
            var table = queryContext.GetMutableTable(SystemSchema.UserPrivilegesTableName);
            var c1 = table.GetResolvedColumnName(0);
            var c2 = table.GetResolvedColumnName(1);
            // All 'user_priv' where UserName = %username%
            var t = table.SimpleSelect(queryContext, c1, SqlExpressionType.Equal, SqlExpression.Constant(username));
            // All from this set where PrivGroupName = %group%
            t = t.SimpleSelect(queryContext, c2, SqlExpressionType.Equal, SqlExpression.Constant(SystemGroupNames.LockGroup));

            bool userBelongsToLockGroup = t.RowCount > 0;
            if (lockStatus && !userBelongsToLockGroup) {
                // Lock the user by adding the user to the Lock group
                // Add this user to the locked group.
                var rdat = new Row(table);
                rdat.SetValue(0, username);
                rdat.SetValue(1, SystemGroupNames.LockGroup);
                table.AddRow(rdat);
            } else if (!lockStatus && userBelongsToLockGroup) {
                // Unlock the user by removing the user from the Lock group
                // Remove this user from the locked group.
                table.Delete(t);
            }
        }