Пример #1
0
        private static void _BuildScalarOuterSelect(Type type, Type clrType, List <ViewColumnInfo> columns, StringBuilder sqlOuter)
        {
            var info   = Mapping.ClrMapping[clrType];
            var castAs = String.Format("CAST ([C1] AS {0})", info.DefaultDataType.Build());

            AppendColumn(sqlOuter, castAs, Text.SingleColumnName);
            ViewColumnInfo column = new ViewColumnInfo(Text.SingleColumnName, type, clrType);

            columns.Add(column);
        }
Пример #2
0
        internal static View ConvertScalar <T>(T data, Type clrType)
        {
            var type = typeof(T);
            var sql  = Text.GenerateSql(50)
                       .Append(Text.Select).S();

            AppendScalarColumn(sql, data, clrType);
            ViewColumnInfo column = new ViewColumnInfo(Text.SingleColumnName, type, clrType);
            var            view   = new View(sql.ToString(), clrType, new ViewColumnInfo[] { column }, 1);

            return(view);
        }
Пример #3
0
        private static Type StoreColumnInfo(List <ViewColumnInfo> columns, string columnName, Type columnType, bool?isNullable = null)
        {
            Type clrType;
            QueryTalkException exception;
            var clrMatch = Mapping.CheckClrCompliance(columnType, out clrType, out exception);

            if (clrMatch != Mapping.ClrTypeMatch.ClrMatch)
            {
                return(null);
            }

            ViewColumnInfo columnInfo = new ViewColumnInfo(columnName, columnType, clrType, isNullable);

            columns.Add(columnInfo);

            return(clrType);
        }
Пример #4
0
        internal static View ConvertValue(Value data)
        {
            var sql = Text.GenerateSql(50)
                      .Append(Text.Select).S();

            ViewColumnInfo column;
            Type           dataType = typeof(string); // default data type (used when data = null)

            if (data.IsUndefined())
            {
                AppendNullColumn(sql);
                column = new ViewColumnInfo(Text.SingleColumnName, dataType, dataType);
            }
            else
            {
                dataType = data.ClrType;
                AppendScalarColumn(sql, data.Original, dataType);
                column = new ViewColumnInfo(Text.SingleColumnName, data.ClrType, data.ClrType);
            }

            return(new View(sql.ToString(), dataType, new ViewColumnInfo[] { column }, 1));
        }
Пример #5
0
        private static void _BuildClassOuterSelect(Type type, ref Type clrType, ref QueryTalkException exception, List <ViewColumnInfo> columns,
                                                   bool isEmpty, PropertyInfo[] properties, out List <IPropertyAccessor> getters, out int numberOfProperties,
                                                   StringBuilder sqlOuter, StringBuilder sqlEmpty)
        {
            numberOfProperties = properties.Length;
            if (numberOfProperties == 0)
            {
                throw new QueryTalkException("ViewConverter.ToView<T>", QueryTalkExceptionType.InvalidDataClass,
                                             String.Format("data class = {0}", type));
            }

            bool cached = Cache.PropertyAccessors.TryGetValue(type, out getters);

            if (!cached)
            {
                getters = new List <IPropertyAccessor>();
            }

            NodeMap rowMap  = null;
            bool    isDbRow = type.IsDbRow();

            if (isDbRow)
            {
                rowMap = DbMapping.GetNodeMap(type);
                if (rowMap.ID.Equals(DB3.Default))
                {
                    DbRow.ThrowInvalidDbRowException(type);
                }
            }

            // outer select:
            int i = 0;

            foreach (var property in properties)
            {
                string column;

                var clrTypeMatch = Mapping.CheckClrCompliance(property.PropertyType, out clrType, out exception);
                if (clrTypeMatch != Mapping.ClrTypeMatch.ClrMatch)
                {
                    continue;
                }

                ViewColumnInfo columnInfo;
                if (isDbRow)
                {
                    var rowColumn = rowMap.Columns.Where(a => a.ID.ColumnZ == i + 1).First();
                    column     = rowColumn.Name.Part1;
                    columnInfo = new ViewColumnInfo(column, rowColumn.DataType, rowColumn.IsNullable);
                    columns.Add(columnInfo);
                }
                else
                {
                    column     = property.Name;
                    columnInfo = new ViewColumnInfo(column, property.PropertyType, clrType);
                    columns.Add(columnInfo);
                }

                if (i != 0)
                {
                    sqlOuter.NewLineIndent(Text.Comma);
                    sqlEmpty.Append(Text.Comma);
                }

                var dataType = Mapping.ProvideDataType(columnInfo.DataType, clrType);
                AppendOuterColumn(sqlOuter, dataType, i + 1, column);

                if (isEmpty)
                {
                    AppendNullValueColumn(sqlEmpty, i + 1);
                }

                if (!cached)
                {
                    getters.Add(PropertyAccessor.Create(type, property));
                }

                ++i;
            }

            numberOfProperties = i;
            if (numberOfProperties == 0)
            {
                ThrowInvalidDataClassException(type);
            }

            if (!cached)
            {
                Cache.PropertyAccessors[type] = getters;
            }
        }