-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathNoteRepository.cs
More file actions
56 lines (49 loc) · 1.82 KB
/
NoteRepository.cs
File metadata and controls
56 lines (49 loc) · 1.82 KB
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
using AnkiNet.CollectionFile.Database.Model;
using Microsoft.Data.Sqlite;
namespace AnkiNet.CollectionFile.Database;
internal class NoteRepository : SqliteRepository<note>
{
public NoteRepository(SqliteConnection connection) : base(connection)
{
}
protected override string TableName => "[notes]";
protected override string Columns =>
"[id], [guid], [mid], " +
"[mod], [usn], [tags], " +
"[flds], [sfld], [csum], " +
"[flags], [data]";
private static string SanitizeHtmlInput(string value)
{
return value.Replace(@"""", @"\""").Replace("'", @"''");
}
protected override string GetValues(note i)
{
return
$"{i.id},'{i.guid}',{i.mid}," +
$"{i.mod},{i.usn},'{i.tags}'," +
$"'{SanitizeHtmlInput(i.flds)}','{SanitizeHtmlInput(i.sfld)}',{i.csum}," +
$"{i.flags},'{i.data}'";
}
protected override note Map(SqliteDataReader reader)
{
/*
* Regarding column 'sfld'.
* See: https://anki.tenderapp.com/discussions/ankidesktop/32752-bug-in-ankis-database-schema-sfld-an-integer
* | The sort field is an integer so that when users are sorting on a field that contains only numbers,
* | they are sorted in numeric instead of lexical order.
*/
return new note(
reader.Get<long>("id"),
reader.Get<string>("guid"),
reader.Get<long>("mid"),
reader.Get<long>("mod"),
reader.Get<long>("usn"),
reader.Get<string>("tags"),
reader.Get<string>("flds"),
reader.Get<string>("sfld"), // 'sfld' is an integer column but contains strings
reader.Get<long>("csum"),
reader.Get<long>("flags"),
reader.Get<string>("data")
);
}
}