示例#1
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;
            }
 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);
 }
        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);
            }
        }
        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);
            }
        }