WebpagePrinterTool 2.0
Print a web page skip the browser's print preview
载入中...
搜索中...
未找到
ModelsSql.h
浏览该文件的文档.
1#include <QString>
2#include <array>
3#include <cstddef>
4#include <string_view>
5template <size_t N>
7 mutable char data[N]{};
8 constexpr ConstexprTableStr() = default;
9 consteval auto addData(std::string_view str, size_t& current_size) const {
10 for (size_t i = 0; i < str.size(); ++i) {
11 data[current_size++] = str[i];
12 }
13 }
14 consteval auto addData(size_t index, size_t& current_size) const {
15 data[current_size++] = static_cast<char>(index + 48);
16 }
17};
18
20 std::string_view field_name;
21 std::string_view field_data_type;
22};
23
24constexpr auto printer_config_table_helper = std::to_array({
25 PrinterConfigToTable{.field_name = "id", .field_data_type = "INTEGER"},
26 PrinterConfigToTable{.field_name = "name", .field_data_type = "TEXT"},
27 PrinterConfigToTable{.field_name = "is_save_png", .field_data_type = "INTEGER"},
28 PrinterConfigToTable{.field_name = "is_to_printer", .field_data_type = "INTEGER"},
29 PrinterConfigToTable{.field_name = "width_mm", .field_data_type = "INTEGER"},
30 PrinterConfigToTable{.field_name = "height_mm", .field_data_type = "INTEGER"},
31 PrinterConfigToTable{.field_name = "top_margin", .field_data_type = "INTEGER"},
32 PrinterConfigToTable{.field_name = "bottom_margin", .field_data_type = "INTEGER"},
33 PrinterConfigToTable{.field_name = "left_margin", .field_data_type = "INTEGER"},
34 PrinterConfigToTable{.field_name = "right_margin", .field_data_type = "INTEGER"},
35 PrinterConfigToTable{.field_name = "printer_name", .field_data_type = "TEXT"},
36 PrinterConfigToTable{.field_name = "is_use_printer_default_config",
37 .field_data_type = "INTEGER"},
38 PrinterConfigToTable{.field_name = "printer_paper_name", .field_data_type = "TEXT"},
39 PrinterConfigToTable{.field_name = "printer_orientation", .field_data_type = "TEXT"},
40 PrinterConfigToTable{.field_name = "process_at_end", .field_data_type = "TEXT"},
41 PrinterConfigToTable{.field_name = "process_argument_at_end", .field_data_type = "TEXT"},
42});
43
44constexpr auto printed_page_table_helper = std::to_array({
45 PrinterConfigToTable{.field_name = "id", .field_data_type = "INTEGER"},
46 PrinterConfigToTable{.field_name = "config_id", .field_data_type = "INTEGER"},
47 PrinterConfigToTable{.field_name = "page_loaded_or_js_request", .field_data_type = "TEXT"},
48 PrinterConfigToTable{.field_name = "time", .field_data_type = "TEXT"},
49 PrinterConfigToTable{.field_name = "status", .field_data_type = "TEXT"},
50 PrinterConfigToTable{.field_name = "from_ip", .field_data_type = "TEXT"},
51 PrinterConfigToTable{.field_name = "page_file_path", .field_data_type = "TEXT"},
52 PrinterConfigToTable{.field_name = "page_url", .field_data_type = "TEXT"},
53 PrinterConfigToTable{.field_name = "end_cmd_exec_status", .field_data_type = "INTEGER"},
54 PrinterConfigToTable{.field_name = "end_cmd_exec_message", .field_data_type = "TEXT"},
55 PrinterConfigToTable{.field_name = "error_message", .field_data_type = "TEXT"},
56});
57template <size_t N>
58consteval auto getCreateTableStrSize(const std::array<PrinterConfigToTable, N>& arr) {
59 size_t size = 0;
60 for (const auto& item : arr) {
61 size +=
62 item.field_name.size() + item.field_data_type.size() + 5; // +2 for space and newline
63 }
64 return size;
65}
66template <size_t N>
67consteval auto getUpdateTableStrSize(const std::array<PrinterConfigToTable, N>& arr) {
68 size_t size = 0;
69 int index = 1;
70 for (; index < arr.size(); ++index) {
71 auto& item = arr[index];
72 size += item.field_name.size();
73 if (item.field_data_type == "INTEGER") {
74 size += 5;
75 } else {
76 size += 7;
77 }
78 if (index < 10) {
79 size += 2;
80 } else {
81 size += 3;
82 }
83 }
84 return size;
85}
86template <size_t N>
87consteval auto getSelectTableStrSize(const std::array<PrinterConfigToTable, N>& arr) {
88 size_t size = 0;
89 for (const auto& item : arr) {
90 size += item.field_name.size() + 2; // +2 for space and newline
91 }
92 return size;
93}
94
95// 不要改变顺序注意 SqliteDb.cpp 的checkValid实现
96constexpr auto tables_name = std::to_array({"printed_page", "printer_config"});
97constexpr std::string_view page_head_str = "CREATE TABLE \"printed_page\" (\n";
98constexpr std::string_view config_head_str = "CREATE TABLE \"printer_config\" (\n";
99constexpr std::string_view tail_str = "PRIMARY KEY(\"id\" AUTOINCREMENT)\n)";
100consteval auto creatStrPageClass() {
101 // for /0 +1
103 page_head_str.size() + tail_str.size()>{};
104}
121template <size_t N>
122consteval auto getCreateTableStr(const std::array<PrinterConfigToTable, N>& arr, auto dat) {
123
124 size_t current_size = 0;
125 if (N == printer_config_table_helper.size()) {
126 dat.addData(config_head_str, current_size);
127 } else {
128 dat.addData(page_head_str, current_size);
129 }
130 for (const auto& item : arr) {
131 dat.addData("\"", current_size);
132 dat.addData(item.field_name, current_size);
133 dat.addData("\" ", current_size);
134 dat.addData(item.field_data_type, current_size);
135 dat.addData(",\n", current_size);
136 }
137 dat.addData(tail_str, current_size);
138 dat.addData("\0", current_size);
139 return dat;
140}
141consteval auto getUpdateTableStr(auto arr, auto dat) {
142
143 size_t current_size = 0;
144 for (size_t i = 1; i < arr.size(); ++i) {
145 dat.addData(arr[i].field_name, current_size);
146 dat.addData(" = ", current_size);
147 if (arr[i].field_data_type == "INTEGER") {
148 dat.addData("%", current_size);
149 if (i < 10) {
150 dat.addData(i, current_size);
151 } else {
152 dat.addData(i / 10, current_size);
153 dat.addData(i % 10, current_size);
154 }
155 } else {
156 dat.addData("'%", current_size);
157 if (i < 10) {
158 dat.addData(i, current_size);
159 } else {
160 dat.addData(i / 10, current_size);
161 dat.addData(i % 10, current_size);
162 }
163 dat.addData("'", current_size);
164 }
165 if (i != arr.size() - 1) {
166 dat.addData(",\n", current_size);
167 } else {
168 dat.addData("\n", current_size);
169 }
170 }
171 dat.addData("\0", current_size);
172 return dat;
173}
174consteval auto getSelectTableStr(auto arr, auto dat) {
175 size_t current_size = 0;
176 for (size_t i = 0; i < arr.size(); ++i) {
177 dat.addData(arr[i].field_name, current_size);
178 if (i != arr.size() - 1) {
179 dat.addData(",\n", current_size);
180 } else {
181 dat.addData("\n", current_size);
182 }
183 }
184 dat.addData("\0", current_size);
185 return dat;
186}
187constexpr auto create_page_table_str =
189
194constexpr auto update_page_table_str =
200constexpr auto select_page_table_str =
consteval auto selectStrPageClass()
定义 ModelsSql.h:108
consteval auto getSelectTableStrSize(const std::array< PrinterConfigToTable, N > &arr)
定义 ModelsSql.h:87
constexpr std::string_view page_head_str
定义 ModelsSql.h:97
consteval auto getCreateTableStr(const std::array< PrinterConfigToTable, N > &arr, auto dat)
定义 ModelsSql.h:122
constexpr auto update_config_table_str
only for QString, only fields, No Update etc.
定义 ModelsSql.h:208
consteval auto selectStrConfigClass()
定义 ModelsSql.h:118
consteval auto getSelectTableStr(auto arr, auto dat)
定义 ModelsSql.h:174
consteval auto updateStrPageClass()
定义 ModelsSql.h:105
consteval auto getUpdateTableStrSize(const std::array< PrinterConfigToTable, N > &arr)
定义 ModelsSql.h:67
constexpr auto select_config_table_str
only fields, No Select etc.
定义 ModelsSql.h:214
constexpr auto select_page_table_str
only fields, No Select etc.
定义 ModelsSql.h:200
constexpr auto printed_page_table_helper
定义 ModelsSql.h:44
consteval auto updateStrConfigClass()
定义 ModelsSql.h:115
consteval auto getCreateTableStrSize(const std::array< PrinterConfigToTable, N > &arr)
定义 ModelsSql.h:58
consteval auto creatStrPageClass()
定义 ModelsSql.h:100
constexpr std::string_view tail_str
定义 ModelsSql.h:99
constexpr auto tables_name
定义 ModelsSql.h:96
consteval auto getUpdateTableStr(auto arr, auto dat)
定义 ModelsSql.h:141
constexpr auto create_config_table_str
定义 ModelsSql.h:202
consteval auto creatStrConfigClass()
定义 ModelsSql.h:111
constexpr auto create_page_table_str
定义 ModelsSql.h:187
constexpr auto update_page_table_str
only for QString, only fields, No Update etc.
定义 ModelsSql.h:194
constexpr std::string_view config_head_str
定义 ModelsSql.h:98
constexpr auto printer_config_table_helper
定义 ModelsSql.h:24
定义 ModelsSql.h:6
consteval auto addData(std::string_view str, size_t &current_size) const
定义 ModelsSql.h:9
char data[N]
定义 ModelsSql.h:7
constexpr ConstexprTableStr()=default
consteval auto addData(size_t index, size_t &current_size) const
定义 ModelsSql.h:14
定义 ModelsSql.h:19
std::string_view field_data_type
定义 ModelsSql.h:21
std::string_view field_name
定义 ModelsSql.h:20