Exemple #1
0
        protected override Task <int> DoDeleteAsync(string executableSql, Dict executableParams)
        {
            DeleteStatement executableStatement = new DeleteStatement(this.database, executableSql);
            var             memoryTable         = executableStatement.StatementFromRefs[0].table as MemoryTable;

            string evaluatedWhereClause = MemoryDatabase.EvaluateWhereClause(executableStatement.whereClause, executableParams, executableStatement.StatementFromRefs);
            var    dataRows             = memoryTable.DataTable.Select(evaluatedWhereClause);

            foreach (var dataRow in dataRows)
            {
                dataRow.Delete();
            }
            this.changedTables.Add(memoryTable);
            return(Task.FromResult(dataRows.Length));
        }
Exemple #2
0
        protected override Task <int> DoUpdateAsync(string executableSql, Dict executableParams)
        {
            UpdateStatement executableStatement = new UpdateStatement(this.database, executableSql);

            if (!(executableStatement.StatementFromRefs[0].table is MemoryTable memoryTable))
            {
                throw new Exception("Table is not a MemoryTable");
            }

            (var whereIndex, var setRefs, var whereRefs) = executableStatement.GetWhereIndexSetRefsAndWhereRefs(this.database, executableParams);
            var fieldValues = BaseStatement.RemapStatementParamsToFieldValues(executableParams, setRefs);

            string evaluatedWhereClause = MemoryDatabase.EvaluateWhereClause(executableStatement.whereClause, executableParams, executableStatement.StatementFromRefs);
            var    dataRows             = memoryTable.DataTable.Select(evaluatedWhereClause);
            int    count = 0;

            foreach (var dataRow in dataRows)
            {
                bool changed = false;
                foreach ((string name, object value) in fieldValues)
                {
                    //object value = executableParams[setRef.paramName];
                    if (dataRow[name] != value)
                    {
                        dataRow[name] = value;
                        changed       = true;
                    }
                }
                if (changed)
                {
                    count++;
                }
            }
            this.changedTables.Add(memoryTable);
            return(Task.FromResult(count));
        }
Exemple #3
0
 public MemoryTransaction(MemoryDatabase database) : base(database)
 {
 }