Esempio n. 1
0
        public IEnumerable <T> ExecuteDeferredQuery <T>(TableMapping map)
        {
            if (_conn.Trace)
            {
                Debug.WriteLine("Executing Query: " + this);
            }

            var stmt = Prepare();

            try
            {
                var cols = new TableMappingColumn[SQLite3.ColumnCount(stmt)];

                for (int i = 0; i < cols.Length; i++)
                {
                    var name = SQLite3.ColumnName16(stmt, i);
                    cols[i] = map.FindColumn(name);
                }

                while (SQLite3.Step(stmt) == SQLite3.Result.Row)
                {
                    var obj = Activator.CreateInstance(map.MappedType);
                    for (int i = 0; i < cols.Length; i++)
                    {
                        // TODO: Disabling on CanWrite here is temporary until we have
                        // accessing container subtables down
                        if (cols[i] == null)
                        {
                            continue;
                        }
                        if (cols[i] is DirectTableMappingColumn)
                        {
                            var colType       = SQLite3.ColumnType(stmt, i);
                            var colSQLiteType = SQLite3.GetSQLiteType(cols[i].TargetType);
                            var val           = colSQLiteType.Read(stmt, i, _conn.StoreDateTimeAsTicks);
                            (cols[i] as DirectTableMappingColumn).SetValue(obj, val);
                        }
                    }
                    foreach (IndirectTableMappingColumn column in map.IndirectColumns)
                    {
                        try
                        {
                            column.LoadValueFromDatabase(obj);
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.ToString());
                        }
                    }
                    OnInstanceCreated(obj);
                    yield return((T)obj);
                }
            }
            finally
            {
                SQLite3.Finalize(stmt);
            }
        }
        public void Test_InitializeDatabaseTables()
        {
            var          connection = DbProvider.GetConnectionInstance();
            TableMapping mapItem    = null;

            using (var en = connection.TableMappings.GetEnumerator())
            {
                while (en.MoveNext())
                {
                    if (en.Current.TableName == "Favorites")
                    {
                        mapItem = en.Current;
                    }
                }
            }
            Assert.NotNull(mapItem);
            Assert.NotNull(mapItem.FindColumn("Id"));
            Assert.NotNull(mapItem.FindColumn("EntityId"));
            Assert.NotNull(mapItem.FindColumn("Tag"));
        }
Esempio n. 3
0
        public IEnumerable <T> ExecuteDeferredQuery <T>(TableMapping map)
        {
            if (_conn.Trace)
            {
                Debug.WriteLine("Executing Query: " + this);
            }

            var stmt = Prepare();

            try
            {
                var cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)];

                for (int i = 0; i < cols.Length; i++)
                {
                    var name = SQLite3.ColumnName16(stmt, i);
                    cols[i] = map.FindColumn(name);
                }

                while (SQLite3.Step(stmt) == SQLite3.Result.Row)
                {
                    var obj = Activator.CreateInstance(map.MappedType);
                    for (int i = 0; i < cols.Length; i++)
                    {
                        if (cols[i] == null)
                        {
                            continue;
                        }
                        var colType = SQLite3.ColumnType(stmt, i);
                        var val     = ReadCol(stmt, i, colType, cols[i].ColumnType);
                        cols[i].SetValue(obj, val);
                    }
                    OnInstanceCreated(obj);
                    yield return((T)obj);
                }
            }
            finally
            {
                SQLite3.Finalize(stmt);
            }
        }