Beispiel #1
0
        /// <inheritdoc />
        public EntityInfo Extract(DbCommand command, SqlString sqlString)
        {
            if (!sqlString.StartsWithCaseInsensitive("DELETE"))
            {
                return(null);
            }

            var parser = new SqlTokenizer(new SqlString(command.CommandText));

            using (var enumerator = parser.GetEnumerator())
            {
                ReadToTablePath(enumerator);
                var tablePath = ReadTablePath(enumerator);
                if (tablePath == null)
                {
                    return(null);
                }
                var where = ReadWhere(enumerator);
                if (where == null)
                {
                    return(null);
                }

                return(new EntityInfo()
                {
                    State = EntityState.Deleted,
                    TablePath = tablePath,
                    Values = ExtractorHelper.CreateValues(where.Item1, where.Item2, command)
                });
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public EntityInfo Extract(DbCommand command, SqlString sqlString)
        {
            if (!sqlString.StartsWithCaseInsensitive("INSERT INTO"))
            {
                return(null);
            }

            var parser = new SqlTokenizer(new SqlString(command.CommandText));

            using (var enumerator = parser.GetEnumerator())
            {
                ReadToTablePath(enumerator);
                var tablePath = ReadTablePath(enumerator);
                if (tablePath == null)
                {
                    return(null);
                }
                var columns = ReadColumns(enumerator);
                if (columns == null)
                {
                    return(null);
                }
                ReadToValues(enumerator);
                var parameters = ReadParameters(enumerator);
                if (parameters == null)
                {
                    return(null);
                }

                if (columns.Length != parameters.Length)
                {
                    return(null);
                }

                return(new EntityInfo()
                {
                    State = EntityState.Added,
                    TablePath = tablePath,
                    Values = ExtractorHelper.CreateValues(columns, parameters, command)
                });
            }
        }
        /// <inheritdoc />
        public EntityInfo Extract(DbCommand command, SqlString sqlString)
        {
            if (!sqlString.StartsWithCaseInsensitive("UPDATE"))
            {
                return(null);
            }

            var parser = new SqlTokenizer(new SqlString(command.CommandText));

            using (var enumerator = parser.GetEnumerator())
            {
                ReadToTablePath(enumerator);
                var tablePath = ReadTablePath(enumerator);
                if (tablePath == null)
                {
                    return(null);
                }
                var set = ReadSet(enumerator);
                if (set == null)
                {
                    return(null);
                }
                var where = ReadWhere(enumerator);
                if (where == null)
                {
                    return(null);
                }

                var setValues   = ExtractorHelper.CreateValues(set.Item1, set.Item2, command);
                var whereValues = ExtractorHelper.CreateValues(where.Item1, where.Item2, command);

                return(new EntityInfo()
                {
                    State = EntityState.Modified,
                    TablePath = tablePath,
                    Values = ExtractorHelper.Union(whereValues, setValues),
                    UpdatedKey = ExtractorHelper.Intersect(setValues, whereValues)
                });
            }
        }