Пример #1
0
        public int save()
        {
            var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");

            using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
            {
                var infoTable = conn.GetTableInfo("User");

                if (!infoTable.Any())
                {
                  //  conn.DropTable<User>();
                    conn.CreateTable<User>();

                }
                var info = conn.GetMapping(typeof(User));

                if (this._user.UserID == 0)
                { 
                    //var i = conn.InsertOrReplace(this._user);
                    var i = conn.Insert(this._user);
                    conn.Commit();
                   // this._user.UserID = i;
                    return i;
                }
                else
                {
                    var i = conn.Update(this._user);
                    return i;
                }
                

            }
        }
Пример #2
0
        public int save()
        {
            var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");

            using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
            {
                var infoTable = conn.GetTableInfo("Eat");

                if (!infoTable.Any())
                {
                    //conn.DropTable<Eat>();
                    conn.CreateTable <Eat>();
                }
                var info = conn.GetMapping(typeof(Eat));

                if (this._eat.EatID == 0)
                {
                    var i = conn.Insert(this._eat);
                    conn.Commit();
                    return(i);
                }
                else
                {
                    var i = conn.Update(this._eat);
                    return(i);
                }
            }
        }
Пример #3
0
        public void Migrate()
        {
            var database = DependencyService.Get <ISQLite> ();

            SQLite.Net.SQLiteConnection connection = null;

            if (!database.Exists())
            {
                connection = database.GetConnection();

                connection.BeginTransaction();
                connection.Execute(@"CREATE TABLE DBVersion (Version INT NOT NULL,
										ExecutionTime TEXT NOT NULL)"                                        );
                connection.Execute("INSERT INTO DBVersion (Version, ExecutionTime) VALUES (?,?)", new object[] { 0, DateTime.Now });
                connection.Commit();
            }

            if (connection == null)
            {
                connection = database.GetConnection();
            }

            foreach (var migration in Migrations)
            {
                int currentVersion = connection.ExecuteScalar <int> ("SELECT Version FROM DBVersion ORDER BY Version DESC LIMIT 1");

                if (migration.Key == (currentVersion + 1))
                {
                    connection.BeginTransaction();

                    foreach (var step in migration.Value)
                    {
                        connection.Execute(step);
                    }

                    connection.Execute("INSERT INTO DBVersion (Version, ExecutionTime) VALUES (?,?)", new object[] { migration.Key, DateTime.Now });
                    connection.Commit();
                }
            }
        }
Пример #4
0
 // Close database connection
 private void closeDBconnection()
 {
     conn.Commit();
     conn.Dispose();
     conn.Close();
 }
Пример #5
0
        //Adds user to db
        public void addUser(String username)
        {
            var query = conn.Insert(new User(username, 0));

            conn.Commit();
        }