-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSpecDBSQLiteWrapper.cs
65 lines (50 loc) · 1.82 KB
/
SpecDBSQLiteWrapper.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Data.Sqlite;
namespace PDTools.SpecDB;
public class SpecDBSQLiteWrapper : ISpecDB
{
private SqliteConnection _conn;
public Task InitializeAsync(string fileName, CancellationTokenSource cancellationTokenSrc)
{
_conn = new SqliteConnection($"Data Source={fileName}");
return _conn.OpenAsync(cancellationTokenSrc.Token);
}
public async Task GetCarRowByCodeAsync(int code, CancellationTokenSource cancellationTokenSrc)
{
_conn.Open();
var com = _conn.CreateCommand();
com.CommandText = "SELECT * FROM GENERIC_CAR WHERE id = $id";
com.Parameters.AddWithValue("$code", code);
using var reader = await com.ExecuteReaderAsync(cancellationTokenSrc.Token);
while (reader.Read())
{
}
}
public async Task GetCarRowByLabelAsync(string label, CancellationTokenSource cancellationTokenSrc)
{
_conn.Open();
var com = _conn.CreateCommand();
com.CommandText = "SELECT * FROM GENERIC_CAR WHERE label = $label";
com.Parameters.AddWithValue("$label", label);
using var reader = await com.ExecuteReaderAsync(cancellationTokenSrc.Token);
while (reader.Read())
{
}
}
public async Task GetRowAsync(string table, int code, CancellationTokenSource cancellationTokenSrc)
{
_conn.Open();
var com = _conn.CreateCommand();
com.CommandText = "SELECT * FROM $table WHERE id = $id";
com.Parameters.AddWithValue("$table", table);
com.Parameters.AddWithValue("$id", code);
using var reader = await com.ExecuteReaderAsync(cancellationTokenSrc.Token);
while (reader.Read())
{
}
}
}