예제 #1
0
        public async Task InsertAsync(BaseEntry entry)
        {
            try
            {
                await Task.Run(() =>
                {
                    using (var custstmt = DbConnection.Prepare(EasySql.CreateInsert(entry.GetType())))
                    {
                        EasySql.FillInsert(custstmt, entry);
                        var res = custstmt.Step();
                        if (res != SQLiteResult.DONE)
                        {
                            throw new Exception();
                        }
                    }
                }
                               );
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return;
            }

            using (var idstmt = DbConnection.Prepare("SELECT last_insert_rowid()"))
            {
                idstmt.Step();
                {
                    entry.Id = (long)idstmt[0];
                }
            }
        }
예제 #2
0
        public static SqlPart IsNotIn <T>(this TypedColumnBase <T> column, params T[] vals)
        {
            var v = new List <object>();

            foreach (var item in vals)
            {
                v.Add(EasySql.StringValue(item));
            }
            return(new SqlPart(column, " ", new SqlFunction("not in", v.ToArray())));
        }
예제 #3
0
        private void CreateTablesIfNotExists()
        {
            var sql = EasySql.CreateTable(typeof(Artist));

            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            sql = EasySql.CreateTable(typeof(Album));
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            sql = EasySql.CreateTable(typeof(Song));
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            sql = EasySql.CreateTable(typeof(QueueSong));
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            sql = EasySql.CreateTable(typeof(Playlist));
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            sql = EasySql.CreateTable(typeof(PlaylistSong));
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            // Turn on Foreign Key constraints
            sql = @"PRAGMA foreign_keys = ON";
            using (var statement = DbConnection.Prepare(sql))
            {
                statement.Step();
            }

            UpdateDbVersion();
        }
예제 #4
0
        public Task UpdateItemAsync(BaseEntry item)
        {
            return(Task.Run(() =>
            {
                using (
                    var projstmt =
                        DbConnection.Prepare(EasySql.CreateUpdate(item.GetType())))
                {
                    // Reset the prepared statement so we can reuse it.
                    projstmt.ClearBindings();
                    projstmt.Reset();

                    EasySql.FillUpdate(projstmt, item);

                    projstmt.Step();
                }
            }));
        }