sqlite-sqliteCpp库

github

新建

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
std::unique_ptr<SQLite::Database> m_spDb;
std::unique_ptr <SQLite::Statement> m_spQuery;

try
{
// Open a database file
m_spDb = make_unique<SQLite::Database>(SQLite::Database(utils::w2s(str),SQLite::OPEN_CREATE|SQLite::OPEN_READWRITE));

// Begin transaction
SQLite::Transaction transaction(*m_spDb);

// 几何系数表
string sql = "CREATE TABLE IF NOT EXISTS main.t_geometric_coeff( \
f_id INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY AUTOINCREMENT, \
f_name TEXT NOT NULL DEFAULT '', \
f_notes TEXT DEFAULT '', \
f_value REAL NOT NULL);\
CREATE UNIQUE INDEX idx_t_g_c_f_id ON t_geometric_coeff (f_id ASC);";
m_spDb->exec(sql);

// 测量工步表
sql = " CREATE TABLE IF NOT EXISTS t_measure_step ( \
f_id INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY AUTOINCREMENT, \
f_notes TEXT DEFAULT '', \
f_measure_type TEXT DEFAULT '', \
f_operate_type TEXT DEFAULT '', \
f_samples_count TEXT DEFAULT '', \
f_preelabration_samples_count TEXT DEFAULT '', \
f_samples_time TEXT DEFAULT '', \
f_delay_time TEXT DEFAULT '');\
CREATE UNIQUE INDEX idx_m_s_f_id ON t_measure_step (f_id ASC); ";
m_spDb->exec(sql);

// 预处理表
sql = "CREATE TABLE IF NOT EXISTS t_preelaboration (\
f_id INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY AUTOINCREMENT,\
f_notes TEXT DEFAULT '',\
f_step TEXT DEFAULT '',\
f_sub_step TEXT DEFAULT '',\
f_measure_type TEXT DEFAULT '',\
f_unit TEXT DEFAULT '',\
f_decimals TEXT DEFAULT '',\
f_abs_unit TEXT DEFAULT '',\
f_abs_decimals TEXT DEFAULT '',\
f_display_position TEXT DEFAULT '',\
f_nominal_value real,\
f_upper_limit real,\
f_lower_limit real,\
f_formula TEXT DEFAULT '',\
f_elaboration TEXT DEFAULT '',\
f_zero TEXT DEFAULT '',\
f_zero_step TEXT DEFAULT '',\
f_zero_sub_step TEXT DEFAULT '',\
f_zero_elaboration TEXT DEFAULT '',\
f_mean_master TEXT DEFAULT '',\
f_mean_master_character TEXT DEFAULT '',\
f_initial_zero_upper real,\
f_initial_zero_lower real); \
CREATE UNIQUE INDEX idx_preela_f_id ON t_preelaboration (f_id ASC);";
m_spDb->exec(sql);

// Commit transaction
transaction.commit();

}
catch (std::exception& e)
{
g_logger->error("create new db failed. err={}", e.what());
}

插入

坚持原创技术分享,您的支持将鼓励我继续创作!