Beispiel #1
0
        public SQLiteObjectIndex(SQLiteObjectTable table, string name, IReadOnlyList <SQLiteIndexedColumn> columns)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (columns == null)
            {
                throw new ArgumentNullException(nameof(columns));
            }

            Table   = table;
            Name    = name;
            Columns = columns;
        }
Beispiel #2
0
        public SQLiteObjectColumn(SQLiteObjectTable table, string name, string dataType, Type clrType,
                                  Func <object, object> getValueFunc,
                                  Action <SQLiteLoadOptions, object, object> setValueAction)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (dataType == null)
            {
                throw new ArgumentNullException(nameof(dataType));
            }

            if (clrType == null)
            {
                throw new ArgumentNullException(nameof(clrType));
            }

            if (getValueFunc == null)
            {
                throw new ArgumentNullException(nameof(getValueFunc));
            }

            Table          = table;
            Name           = name;
            DataType       = dataType;
            ClrType        = clrType;
            GetValueFunc   = getValueFunc;
            SetValueAction = setValueAction; // can be null for RO props
        }
 protected virtual SQLiteObjectColumn CreateObjectColumn(SQLiteObjectTable table, string name, string dataType, Type clrType,
                                                         Func <object, object> getValueFunc,
                                                         Action <SQLiteLoadOptions, object, object> setValueAction) => new SQLiteObjectColumn(table, name, dataType, clrType, getValueFunc, setValueAction);
 protected virtual SQLiteObjectIndex CreateObjectIndex(SQLiteObjectTable table, string name, IReadOnlyList <SQLiteIndexedColumn> columns) => new SQLiteObjectIndex(table, name, columns);
        protected virtual void AddIndices(SQLiteObjectTable table, IDictionary <string, IReadOnlyList <Tuple <SQLiteColumnAttribute, SQLiteIndexAttribute> > > indices)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (indices == null)
            {
                throw new ArgumentNullException(nameof(indices));
            }

            foreach (var index in indices)
            {
                var list = index.Value;
                for (int i = 0; i < list.Count; i++)
                {
                    SQLiteColumnAttribute col = list[i].Item1;
                    SQLiteIndexAttribute  idx = list[i].Item2;
                    if (idx.Order == SQLiteIndexAttribute.DefaultOrder)
                    {
                        idx.Order = i;
                    }
                }

                var    columns    = new List <SQLiteIndexedColumn>();
                bool   unique     = false;
                string schemaName = null;
                foreach (var kv in list.OrderBy(l => l.Item2.Order))
                {
                    var col = CreateIndexedColumn(kv.Item1.Name);
                    if (col == null)
                    {
                        throw new InvalidOperationException();
                    }

                    col.CollationName = kv.Item2.CollationName;
                    col.Direction     = kv.Item2.Direction;

                    // if at least one defines unique, it's unique
                    if (kv.Item2.IsUnique)
                    {
                        unique = true;
                    }

                    // first schema defined is used
                    if (!string.IsNullOrWhiteSpace(kv.Item2.SchemaName))
                    {
                        schemaName = kv.Item2.SchemaName;
                    }
                    columns.Add(col);
                }

                var oidx = CreateObjectIndex(table, index.Key, columns);
                if (oidx == null)
                {
                    throw new InvalidOperationException();
                }

                oidx.IsUnique   = unique;
                oidx.SchemaName = schemaName;
                table.AddIndex(oidx);
            }
        }