-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLite.cs
105 lines (87 loc) · 2.72 KB
/
SQLite.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//This code was generated by a tool.
//Changes to this file will be lost if the code is regenerated.
// See the blog post here for help on using the generated code: http://erikej.blogspot.dk/2014/10/database-first-with-sqlite-in-universal.html
using SQLite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel.Chat;
using Windows.Storage;
using SQLite.Net;
using SQLite.Net.Attributes;
using SQLite.Net.Platform.WinRT;
namespace Memory
{
public class SQLiteDb
{
private SQLiteConnection db;
public SQLiteDb()
{
var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "db.sqlite");
db = new SQLiteConnection(new SQLitePlatformWinRT(), path);
//db.TraceListener = new DebugTraceListener();
}
public void Create()
{
db.CreateTable<Score>();
}
public void AddHighscore(String name, int time, int incorrectPairs, int points)
{
var score = new Score
{
Name = name,
IncorrectPairs = incorrectPairs,
TimeInSeconds = time,
Points = points
};
db.Insert(score);
}
public List<Score> GetTopHighscores()
{
//get all
List<Score> users = (from u in db.Table<Score>()
orderby u.IncorrectPairs, u.TimeInSeconds ascending
select u
).Take(10).ToList();
return users;
/*s
get user by id
User m = (from u in db.Table<User>()
where u.Id == Id
select u).FirstOrDefault();
*/
}
public void DeleteAllHighscores()
{
db.DeleteAll<Score>();
}
public void Update()
{
User m = (from u in db.Table<User>()
where u.Naam == "test"
select u).FirstOrDefault();
m.Naam = "testupdate";
db.Update(m);
}
public void Saveandclose()
{
db.Close();
}
}
public partial class Score
{
[PrimaryKey, AutoIncrement]
public Int32 Id { get; set; }
public string Name { get; set; }
public int IncorrectPairs { get; set; }
public int Points { get; set; }
public int TimeInSeconds { get; set; }
}
public partial class User
{
[PrimaryKey, AutoIncrement]
public Int64 Id { get; set; }
public String Naam { get; set; }
}
}