private SqlExpression BuildVersionFilter(PersistRequestBuilderContext context, SqlTableRef filteredTable, List <PersistParameterBinding> currentBindings)
        {
            SqlExpression result = null;

            foreach (var column in context.Type.GetVersionColumns())
            {
                var fieldIndex = GetFieldIndex(context.Type, column);
                if (!context.Task.AvailableFields[fieldIndex])
                {
                    continue;
                }
                PersistParameterBinding binding;
                if (!context.VersionParameterBindings.TryGetValue(column, out binding))
                {
                    var typeMapping = driver.GetTypeMapping(column);
                    binding = new PersistParameterBinding(typeMapping, fieldIndex, ParameterTransmissionType.Regular, PersistParameterBindingType.VersionFilter);
                    context.VersionParameterBindings.Add(column, binding);
                }
                var filteredColumn = filteredTable[column.Name];
                if (filteredColumn.IsNullReference())
                {
                    continue;
                }
                var filterValue = binding.ParameterReference;
                // Handle decimal precision issue
                if (Type.GetTypeCode(column.ValueType) == TypeCode.Decimal)
                {
                    filterValue = SqlDml.Cast(filterValue, driver.MapValueType(column));
                }
                result &= SqlDml.Variant(binding, filteredColumn == filterValue, SqlDml.IsNull(filteredColumn));
                currentBindings.Add(binding);
            }
            return(result);
        }
 private PersistParameterBinding GetBinding(PersistRequestBuilderContext context, ColumnInfo column, Table table, int fieldIndex)
 {
     if (!context.ParameterBindings.TryGetValue(column, out var binding))
     {
         var typeMapping = driver.GetTypeMapping(column);
         var bindingType = GetTransmissionType(table.TableColumns[column.Name]);
         binding = new PersistParameterBinding(typeMapping, fieldIndex, bindingType);
         context.ParameterBindings.Add(column, binding);
     }
     return(binding);
 }
Пример #3
0
        private object GetParameterValue(SqlPersistTask task, PersistParameterBinding binding)
        {
            switch (binding.BindingType)
            {
            case PersistParameterBindingType.Regular:
                return(task.Tuple.GetValueOrDefault(binding.FieldIndex));

            case PersistParameterBindingType.VersionFilter:
                return(task.OriginalTuple.GetValueOrDefault(binding.FieldIndex));

            default:
                throw new ArgumentOutOfRangeException("binding.Source");
            }
        }
        private SqlExpression BuildKeyFilter(PersistRequestBuilderContext context, SqlTableRef filteredTable, List <PersistParameterBinding> currentBindings)
        {
            SqlExpression result = null;

            foreach (var column in context.PrimaryIndex.KeyColumns.Keys)
            {
                if (!context.ParameterBindings.TryGetValue(column, out var binding))
                {
                    var typeMapping = driver.GetTypeMapping(column);
                    var fieldIndex  = GetFieldIndex(context.Type, column);
                    binding = new PersistParameterBinding(typeMapping, fieldIndex);
                    context.ParameterBindings.Add(column, binding);
                }
                result &= filteredTable[column.Name] == binding.ParameterReference;
                currentBindings.Add(binding);
            }
            return(result);
        }
        private SqlInsert MakeUpInsertQuery(SqlTableRef temporaryTable, TypeMapping[] typeMappings, List <PersistParameterBinding> storeRequestBindings, bool hasColumns)
        {
            var insertStatement = SqlDml.Insert(temporaryTable);

            if (hasColumns)
            {
                var fieldIndex = 0;
                foreach (var column in temporaryTable.Columns)
                {
                    TypeMapping typeMapping = typeMappings[fieldIndex];
                    var         binding     = new PersistParameterBinding(typeMapping, fieldIndex);
                    insertStatement.Values[column] = binding.ParameterReference;
                    storeRequestBindings.Add(binding);
                    fieldIndex++;
                }
            }
            else
            {
                insertStatement.Values[temporaryTable.Columns[0]] = SqlDml.Literal(0);
            }
            return(insertStatement);
        }