Пример #1
0
 /// <summary>Initializes a new instance of the <see cref="TestDb"/> class.</summary>
 /// <param name="columnInformationProvider">The column information provider.</param>
 /// <param name="contractResolver">The contract resolver.</param>
 protected TestDb(
     IColumnInformationProvider columnInformationProvider = null,
     IContractResolver contractResolver = null)
     : base(
         new SQLitePlatformTest(), CreateTemporaryDatabase(), columnInformationProvider,
         resolver: contractResolver)
 {
 }
Пример #2
0
 /// <summary>Initializes a new instance of the <see cref="TestBaseDb"/> class.</summary>
 /// <param name="platform">The test platform.</param>
 /// <param name="columnInformationProvider">The column information provider.</param>
 /// <param name="contractResolver">The contract resolver.</param>
 public TestBaseDb(
     ISQLitePlatform platform,
     IColumnInformationProvider columnInformationProvider = null,
     IContractResolver contractResolver = null)
     : base(
         platform, CreateTemporaryDatabase(), columnInformationProvider,
         resolver: contractResolver)
 {
 }
Пример #3
0
		public TableMapping(Type type, IEnumerable<PropertyInfo> properties, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
        {
			if (infoProvider == null)
			{
				infoProvider = new DefaultColumnInformationProvider ();
			}

            MappedType = type;

            var tableAttr = type.GetTypeInfo().GetCustomAttributes<TableAttribute>().FirstOrDefault();

            TableName = tableAttr != null ?  tableAttr.Name : MappedType.Name;

            var props = properties;

            var cols = new List<Column>();
            foreach (var p in props)
            {
				var ignore = infoProvider.IsIgnored (p);

                if (p.CanWrite && !ignore)
                {
                    cols.Add(new Column(p, createFlags));
                }
            }
            Columns = cols.ToArray();
            foreach (var c in Columns)
            {
                if (c.IsAutoInc && c.IsPK)
                {
                    _autoPk = c;
                }
                if (c.IsPK)
                {
                    PK = c;
                }
            }

            HasAutoIncPK = _autoPk != null;

            if (PK != null)
            {
                GetByPrimaryKeySql = string.Format("select * from \"{0}\" where \"{1}\" = ?", TableName, PK.Name);
            }
            else
            {
                // People should not be calling Get/Find without a PK
                GetByPrimaryKeySql = string.Format("select * from \"{0}\" limit 1", TableName);
            }
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="SQLiteConnectionWithLockBridge" />
 ///   class.
 /// </summary>
 /// <param name="sqlitePlatform">The sqlite platform.</param>
 /// <param name="databasePath">The database path.</param>
 /// <param name="columnInformationProvider">The column information provider.</param>
 /// <param name="storeDateTimeAsTicks">if set to <c>true</c> [store date time as ticks].</param>
 /// <param name="serializer">The serializer.</param>
 /// <param name="tableMappings">The table mappings.</param>
 /// <param name="extraTypeMappings">The extra type mappings.</param>
 /// <param name="resolver">The resolver.</param>
 public SQLiteConnectionWithLockBridge(
     ISQLitePlatform sqlitePlatform, string databasePath,
     IColumnInformationProvider columnInformationProvider = null,
     bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null,
     IDictionary <string, TableMapping> tableMappings = null,
     IDictionary <Type, string> extraTypeMappings     = null, IContractResolver resolver = null)
     : base(
         sqlitePlatform,
         new SQLiteConnectionString(databasePath, storeDateTimeAsTicks, serializer, resolver),
         tableMappings, extraTypeMappings)
 {
     ColumnInformationProvider = columnInformationProvider
                                 ?? new ColumnInformationProviderBridge();
 }
Пример #5
0
			public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
            {
				if (infoProvider == null)
				{
					infoProvider = new DefaultColumnInformationProvider();
				}

                _prop = prop;
				Name = infoProvider.GetColumnName(prop);
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                var isAuto = Orm.IsAutoInc(prop) ||
                             (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));
                IsAutoGuid = isAuto && ColumnType == typeof (Guid);
                IsAutoInc = isAuto && !IsAutoGuid;

                DefaultValue = Orm.GetDefaultValue(prop);

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any()
                    && !IsPK
                    && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex)
                    && Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    Indices = new[] {new IndexedAttribute()};
                }
                IsNullable = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);
            }
Пример #6
0
        public TableMapping(Type type, IEnumerable <PropertyInfo> properties, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
        {
            if (infoProvider == null)
            {
                infoProvider = new DefaultColumnInformationProvider();
            }

            MappedType = type;

            var tableAttr = type.GetTypeInfo().GetCustomAttributes <TableAttribute>().FirstOrDefault();

            TableName = tableAttr != null ? tableAttr.Name : MappedType.Name;

            var props = properties;

            var cols = new List <Column>();

            foreach (var p in props)
            {
                var ignore = infoProvider.IsIgnored(p);

                if (p.CanWrite && !ignore)
                {
                    cols.Add(new Column(p, createFlags));
                }
            }
            Columns = cols.ToArray();
            foreach (var c in Columns)
            {
                if (c.IsAutoInc && c.IsPK)
                {
                    _autoPk = c;
                }
                if (c.IsPK)
                {
                    PKs.Add(c);
                }
            }

            HasAutoIncPK = _autoPk != null;

            if (PK != null)
            {
                GetByPrimaryKeySql  = string.Format("select * from \"{0}\" where \"{1}\" = ?", TableName, PK.Name);
                PkWhereSql          = PKs.Aggregate(new StringBuilder(), (sb, pk) => sb.AppendFormat(" \"{0}\" = ? and", pk.Name), sb => sb.Remove(sb.Length - 3, 3).ToString());
                GetByPrimaryKeysSql = String.Format("select * from \"{0}\" where {1}", TableName, PkWhereSql);
            }
            else
            {
                // People should not be calling Get/Find without a PK
                GetByPrimaryKeysSql = GetByPrimaryKeySql = string.Format("select * from \"{0}\" limit 1", TableName);
            }
        }
Пример #7
0
            public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null)
            {
                if (infoProvider == null)
                {
                    infoProvider = new DefaultColumnInformationProvider();
                }

                _prop = prop;
                Name  = infoProvider.GetColumnName(prop);
                //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead
                ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
                Collation  = Orm.Collation(prop);

                IsPK = Orm.IsPK(prop) ||
                       (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) &&
                        string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0);

                var isAuto = Orm.IsAutoInc(prop) ||
                             (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK));

                IsAutoGuid = isAuto && ColumnType == typeof(Guid);
                IsAutoInc  = isAuto && !IsAutoGuid;

                DefaultValue = Orm.GetDefaultValue(prop);

                Indices = Orm.GetIndices(prop);
                if (!Indices.Any() &&
                    !IsPK &&
                    ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) &&
                    Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    Indices = new[] { new IndexedAttribute() };
                }
                IsNullable      = !(IsPK || Orm.IsMarkedNotNull(prop));
                MaxStringLength = Orm.MaxStringLength(prop);
            }