-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSQLiteHelper.cs
More file actions
68 lines (57 loc) · 2.25 KB
/
Copy pathSQLiteHelper.cs
File metadata and controls
68 lines (57 loc) · 2.25 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
57
58
59
60
61
62
63
64
65
66
67
68
namespace RevitAddinOutOfContext_gRPC_Client
{
using Microsoft.Data.Sqlite;
using System.IO;
public class SQLiteHelper
{
private readonly string _dbPath;
public SQLiteHelper(string dbPath)
{
_dbPath = dbPath;
}
public void InitializeDatabase()
{
if (File.Exists(_dbPath))
{
File.Delete(_dbPath);
}
//File.Create(_dbPath);
using (var connection = new SqliteConnection($"Data Source={_dbPath}"))
{
connection.Open();
string tableCommand = @"
CREATE TABLE IF NOT EXISTS RevitElements (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
CategoryName TEXT,
ElemName TEXT,
ElemGuid TEXT,
GeomParameters TEXT,
DataParameters TEXT
)";
using (var createTable = new SqliteCommand(tableCommand, connection))
{
createTable.ExecuteNonQuery();
}
}
}
public void InsertElement(string categoryName, string elemName, string elemGuid, string geomParameters, string dataParameters)
{
using (var connection = new SqliteConnection($"Data Source={_dbPath}"))
{
connection.Open();
string insertCommand = @"
INSERT INTO RevitElements (CategoryName, ElemName, ElemGuid, GeomParameters, DataParameters)
VALUES (@CategoryName, @ElemName, @ElemGuid, @GeomParameters, @DataParameters)";
using (var insert = new SqliteCommand(insertCommand, connection))
{
insert.Parameters.AddWithValue("@CategoryName", categoryName);
insert.Parameters.AddWithValue("@ElemName", elemName);
insert.Parameters.AddWithValue("@ElemGuid", elemGuid);
insert.Parameters.AddWithValue("@GeomParameters", geomParameters);
insert.Parameters.AddWithValue("@DataParameters", dataParameters);
insert.ExecuteNonQuery();
}
}
}
}
}