internal OldNewTableState(ObjectName tableSource, int oldRowIndex, Row newDataRow, bool newMutable)
 {
     TableSource = tableSource;
     OldRowIndex = oldRowIndex;
     NewDataRow = newDataRow;
     IsNewMutable = newMutable;
 }
示例#2
0
        internal TableEvent(ITable table, TriggerEventType eventType, RowId oldRowId, Row newRow)
        {
            if (table == null)
                throw new ArgumentNullException("table");

            Table = table;
            EventType = eventType;
            OldRowId = oldRowId;
            NewRow = newRow;
        }
示例#3
0
        internal TriggerEvent(IEventSource source, ObjectName triggerName, ObjectName sourceName, TriggerEventType eventType, RowId oldRowId, Row newRow)
        {
            if (triggerName == null)
                throw new ArgumentNullException("triggerName");
            if (sourceName == null)
                throw new ArgumentNullException("sourceName");

            Source = source;
            TriggerName = triggerName;
            SourceName = sourceName;
            TriggerEventType = eventType;
            OldRowId = oldRowId;
            NewRow = newRow;
        }
示例#4
0
        private TriggerInfo FormTrigger(Row row)
        {
            var schema = row.GetValue(0).Value.ToString();
            var name = row.GetValue(1).Value.ToString();
            var triggerName = new ObjectName(new ObjectName(schema), name);

            var triggerType = ((SqlNumber)row.GetValue(2).Value).ToInt32();

            var tableName = ObjectName.Parse(((SqlString) row.GetValue(3).Value).ToString());
            var eventTime = (TriggerEventTime)((SqlNumber)row.GetValue(4).Value).ToInt32();
            var eventType = (TriggerEventType) ((SqlNumber) row.GetValue(5).Value).ToInt32();

            TriggerInfo triggerInfo;

            if (triggerType == ProcedureType) {
                var procNameString = row.GetValue(6).Value.ToString();
                var procName = ObjectName.Parse(procNameString);
                var argsBinary = (SqlBinary)row.GetValue(7).Value;
                var args = DeserializeArguments(argsBinary.ToByteArray());

                triggerInfo = new ProcedureTriggerInfo(triggerName,tableName, eventTime, eventType, procName);

                if (args != null && args.Length > 0) {
                    foreach (var expression in args) {
                        ((ProcedureTriggerInfo) triggerInfo).Arguments = args;
                    }
                }
            } else if (triggerType == PlSqlType) {
                var binary = (SqlBinary) row.GetValue(8).Value;
                var body = binary.ToObject<PlSqlBlockStatement>();

                triggerInfo = new PlSqlTriggerInfo(triggerName, tableName, eventTime, eventType, body);
            } else {
                throw new InvalidOperationException();
            }

            triggerInfo.Status = (TriggerStatus) ((SqlNumber) row.GetValue(9).Value).ToByte();

            return triggerInfo;
        }
示例#5
0
 private void FetchIntoVatiable(IRequest request, Row row, string varName)
 {
     throw new NotImplementedException();
 }
示例#6
0
        private void FetchIntoReference(IRequest request, Row row, ObjectName reference)
        {
            if (reference == null)
                throw new ArgumentNullException("reference");

            var table = request.Query.GetMutableTable(reference);
            if (table == null)
                throw new ObjectNotFoundException(reference);

            throw new NotImplementedException();
        }
示例#7
0
        private TriggerInfo FormTrigger(Row row)
        {
            var schema = row.GetValue(0).Value.ToString();
            var name = row.GetValue(1).Value.ToString();
            var triggerName = new ObjectName(new ObjectName(schema), name);

            var triggerType = (TriggerType)((SqlNumber)row.GetValue(2).Value).ToInt32();

            // TODO: In case it's  a procedural trigger, take the reference to the procedure
            if (triggerType == TriggerType.Procedure)
                throw new NotImplementedException();

            var tableName = ObjectName.Parse(((SqlString) row.GetValue(3).Value).ToString());
            var eventType = (TriggerEventType) ((SqlNumber) row.GetValue(4).Value).ToInt32();
            return  new TriggerInfo(triggerName, triggerType, eventType, tableName);
        }
        public RowId AddRow(Row row)
        {
            OnTableEvent(TriggerEventType.BeforeInsert, RowId.Null, row);

            var newRowId = MutableTable.AddRow(row);

            OnTableEvent(TriggerEventType.AfterInsert, newRowId, row);

            return newRowId;
        }
示例#9
0
 public void SetData(Row row)
 {
     data = row;
 }
示例#10
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);
        }
示例#11
0
 private void OnTableEvent(TriggerEventTime eventTime, TriggerEventType eventType, RowId rowId, Row row)
 {
     Request.Access().FireTriggers(Request, new TableEvent(this, eventTime, eventType, rowId, row));
 }
示例#12
0
 public RowVariableResolver(Row row)
 {
     this.row = row;
 }
示例#13
0
        public ITable GetTable(int offset)
        {
            var tableInfo = GetTableInfo(offset);

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

            if (HasOldTable) {
                if (offset == 0) {
                    // Copy data from the table to the new table
                    var dtable = transaction.GetTable(Handler.TableState.TableSource);
                    var oldRow = new Row(table);
                    int rowIndex = Handler.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(!Handler.TableState.IsNewMutable);
            table.SetData(Handler.TableState.NewDataRow);

            return table;
        }
示例#14
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));
                }
            }
示例#15
0
        public void SetUserStatus(string userName, UserStatus status)
        {
            // Internally we implement this by adding the user to the #locked group.
            var table = QueryContext.GetMutableTable(SystemSchema.UserGroupTableName);
            var c1 = table.GetResolvedColumnName(0);
            var c2 = table.GetResolvedColumnName(1);
            // All 'user_group' 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(SystemGroups.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, SystemGroups.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);
            }
        }
示例#16
0
 private void OnTableEvent(TriggerEventType eventType, RowId rowId, Row row)
 {
     Context.FireTriggers(new TableEvent(this, eventType, rowId, row));
 }
示例#17
0
 public RowId AddRow(Row row)
 {
     throw new NotSupportedException(String.Format("Inserting data into '{0}' is not allowed.", tableInfo.TableName));
 }