This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimit_accessor.h
139 lines (104 loc) · 3.81 KB
/
limit_accessor.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#pragma once
#include <sqlite3.h>
#include <map> // std::map
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include "connection_holder.h"
namespace sqlite_orm {
namespace internal {
struct limit_accessor {
using get_connection_t = std::function<connection_ref()>;
limit_accessor(get_connection_t get_connection_) : get_connection(std::move(get_connection_)) {}
int length() {
return this->get(SQLITE_LIMIT_LENGTH);
}
void length(int newValue) {
this->set(SQLITE_LIMIT_LENGTH, newValue);
}
int sql_length() {
return this->get(SQLITE_LIMIT_SQL_LENGTH);
}
void sql_length(int newValue) {
this->set(SQLITE_LIMIT_SQL_LENGTH, newValue);
}
int column() {
return this->get(SQLITE_LIMIT_COLUMN);
}
void column(int newValue) {
this->set(SQLITE_LIMIT_COLUMN, newValue);
}
int expr_depth() {
return this->get(SQLITE_LIMIT_EXPR_DEPTH);
}
void expr_depth(int newValue) {
this->set(SQLITE_LIMIT_EXPR_DEPTH, newValue);
}
int compound_select() {
return this->get(SQLITE_LIMIT_COMPOUND_SELECT);
}
void compound_select(int newValue) {
this->set(SQLITE_LIMIT_COMPOUND_SELECT, newValue);
}
int vdbe_op() {
return this->get(SQLITE_LIMIT_VDBE_OP);
}
void vdbe_op(int newValue) {
this->set(SQLITE_LIMIT_VDBE_OP, newValue);
}
int function_arg() {
return this->get(SQLITE_LIMIT_FUNCTION_ARG);
}
void function_arg(int newValue) {
this->set(SQLITE_LIMIT_FUNCTION_ARG, newValue);
}
int attached() {
return this->get(SQLITE_LIMIT_ATTACHED);
}
void attached(int newValue) {
this->set(SQLITE_LIMIT_ATTACHED, newValue);
}
int like_pattern_length() {
return this->get(SQLITE_LIMIT_LIKE_PATTERN_LENGTH);
}
void like_pattern_length(int newValue) {
this->set(SQLITE_LIMIT_LIKE_PATTERN_LENGTH, newValue);
}
int variable_number() {
return this->get(SQLITE_LIMIT_VARIABLE_NUMBER);
}
void variable_number(int newValue) {
this->set(SQLITE_LIMIT_VARIABLE_NUMBER, newValue);
}
int trigger_depth() {
return this->get(SQLITE_LIMIT_TRIGGER_DEPTH);
}
void trigger_depth(int newValue) {
this->set(SQLITE_LIMIT_TRIGGER_DEPTH, newValue);
}
#if SQLITE_VERSION_NUMBER >= 3008007
int worker_threads() {
return this->get(SQLITE_LIMIT_WORKER_THREADS);
}
void worker_threads(int newValue) {
this->set(SQLITE_LIMIT_WORKER_THREADS, newValue);
}
#endif
protected:
get_connection_t get_connection;
friend struct storage_base;
/**
* Stores limit set between connections.
*/
std::map<int, int> limits;
int get(int id) {
auto connection = this->get_connection();
return sqlite3_limit(connection.get(), id, -1);
}
void set(int id, int newValue) {
this->limits[id] = newValue;
auto connection = this->get_connection();
sqlite3_limit(connection.get(), id, newValue);
}
};
}
}