@@ -36,20 +36,19 @@ class db_copy_mgr_t
36
36
*/
37
37
void new_line (std::shared_ptr<db_target_descr_t > const &table)
38
38
{
39
- if (!m_current || !m_current-> target ->same_copy_target (*table)) {
39
+ if (!m_current || !m_current. target ->same_copy_target (*table)) {
40
40
if (m_current) {
41
- m_processor->add_buffer (std::move (m_current));
41
+ m_processor->send_command (std::move (m_current));
42
42
}
43
-
44
- m_current = std::make_unique<db_cmd_copy_delete_t <DELETER>>(table);
43
+ m_current = db_cmd_copy_delete_t <DELETER>(table);
45
44
}
46
- m_committed = m_current-> buffer .size ();
45
+ m_committed = m_current. buffer .size ();
47
46
}
48
47
49
48
void rollback_line ()
50
49
{
51
50
assert (m_current);
52
- m_current-> buffer .resize (m_committed);
51
+ m_current. buffer .resize (m_committed);
53
52
}
54
53
55
54
/* *
@@ -62,16 +61,17 @@ class db_copy_mgr_t
62
61
{
63
62
assert (m_current);
64
63
65
- auto &buf = m_current-> buffer ;
64
+ auto &buf = m_current. buffer ;
66
65
assert (!buf.empty ());
67
66
68
67
// Expect that a column has been written last which ended in a '\t'.
69
68
// Replace it with the row delimiter '\n'.
70
69
assert (buf.back () == ' \t ' );
71
70
buf.back () = ' \n ' ;
72
71
73
- if (m_current->is_full ()) {
74
- m_processor->add_buffer (std::move (m_current));
72
+ if (m_current.is_full ()) {
73
+ m_processor->send_command (std::move (m_current));
74
+ m_current = {};
75
75
}
76
76
}
77
77
@@ -96,15 +96,15 @@ class db_copy_mgr_t
96
96
void add_column (T value)
97
97
{
98
98
add_value (value);
99
- m_current-> buffer += ' \t ' ;
99
+ m_current. buffer += ' \t ' ;
100
100
}
101
101
102
102
/* *
103
103
* Add an empty column.
104
104
*
105
105
* Adds a NULL value for the column.
106
106
*/
107
- void add_null_column () { m_current-> buffer += " \\ N\t " ; }
107
+ void add_null_column () { m_current. buffer += " \\ N\t " ; }
108
108
109
109
/* *
110
110
* Start an array column.
@@ -113,7 +113,7 @@ class db_copy_mgr_t
113
113
*
114
114
* Must be finished with a call to finish_array().
115
115
*/
116
- void new_array () { m_current-> buffer += " {" ; }
116
+ void new_array () { m_current. buffer += " {" ; }
117
117
118
118
/* *
119
119
* Add a single value to an array column.
@@ -124,7 +124,7 @@ class db_copy_mgr_t
124
124
void add_array_elem (osmid_t value)
125
125
{
126
126
add_value (value);
127
- m_current-> buffer += ' ,' ;
127
+ m_current. buffer += ' ,' ;
128
128
}
129
129
130
130
/* *
@@ -135,13 +135,13 @@ class db_copy_mgr_t
135
135
*/
136
136
void finish_array ()
137
137
{
138
- assert (!m_current-> buffer .empty ());
139
- if (m_current-> buffer .back () == ' {' ) {
140
- m_current-> buffer += ' }' ;
138
+ assert (!m_current. buffer .empty ());
139
+ if (m_current. buffer .back () == ' {' ) {
140
+ m_current. buffer += ' }' ;
141
141
} else {
142
- m_current-> buffer .back () = ' }' ;
142
+ m_current. buffer .back () = ' }' ;
143
143
}
144
- m_current-> buffer += ' \t ' ;
144
+ m_current. buffer += ' \t ' ;
145
145
}
146
146
147
147
/* *
@@ -172,11 +172,11 @@ class db_copy_mgr_t
172
172
*/
173
173
void add_hash_elem (char const *k, char const *v)
174
174
{
175
- m_current-> buffer += ' "' ;
175
+ m_current. buffer += ' "' ;
176
176
add_escaped_string (k);
177
- m_current-> buffer += " \" =>\" " ;
177
+ m_current. buffer += " \" =>\" " ;
178
178
add_escaped_string (v);
179
- m_current-> buffer += " \" ," ;
179
+ m_current. buffer += " \" ," ;
180
180
}
181
181
182
182
/* *
@@ -187,11 +187,11 @@ class db_copy_mgr_t
187
187
*/
188
188
void add_hash_elem_noescape (char const *k, char const *v)
189
189
{
190
- m_current-> buffer += ' "' ;
191
- m_current-> buffer += k;
192
- m_current-> buffer += " \" =>\" " ;
193
- m_current-> buffer += v;
194
- m_current-> buffer += " \" ," ;
190
+ m_current. buffer += ' "' ;
191
+ m_current. buffer += k;
192
+ m_current. buffer += " \" =>\" " ;
193
+ m_current. buffer += v;
194
+ m_current. buffer += " \" ," ;
195
195
}
196
196
197
197
/* *
@@ -207,11 +207,11 @@ class db_copy_mgr_t
207
207
template <typename T>
208
208
void add_hstore_num_noescape (char const *k, T const value)
209
209
{
210
- m_current-> buffer += ' "' ;
211
- m_current-> buffer += k;
212
- m_current-> buffer += " \" =>\" " ;
213
- m_current-> buffer += std::to_string (value);
214
- m_current-> buffer += " \" ," ;
210
+ m_current. buffer += ' "' ;
211
+ m_current. buffer += k;
212
+ m_current. buffer += " \" =>\" " ;
213
+ m_current. buffer += std::to_string (value);
214
+ m_current. buffer += " \" ," ;
215
215
}
216
216
217
217
/* *
@@ -222,11 +222,11 @@ class db_copy_mgr_t
222
222
*/
223
223
void finish_hash ()
224
224
{
225
- auto const idx = m_current-> buffer .size () - 1 ;
226
- if (!m_current-> buffer .empty () && m_current-> buffer [idx] == ' ,' ) {
227
- m_current-> buffer [idx] = ' \t ' ;
225
+ auto const idx = m_current. buffer .size () - 1 ;
226
+ if (!m_current. buffer .empty () && m_current. buffer [idx] == ' ,' ) {
227
+ m_current. buffer [idx] = ' \t ' ;
228
228
} else {
229
- m_current-> buffer += ' \t ' ;
229
+ m_current. buffer += ' \t ' ;
230
230
}
231
231
}
232
232
@@ -241,10 +241,10 @@ class db_copy_mgr_t
241
241
242
242
for (auto c : wkb) {
243
243
unsigned int const num = static_cast <unsigned char >(c);
244
- m_current-> buffer += lookup_hex[(num >> 4U ) & 0xfU ];
245
- m_current-> buffer += lookup_hex[num & 0xfU ];
244
+ m_current. buffer += lookup_hex[(num >> 4U ) & 0xfU ];
245
+ m_current. buffer += lookup_hex[num & 0xfU ];
246
246
}
247
- m_current-> buffer += ' \t ' ;
247
+ m_current. buffer += ' \t ' ;
248
248
}
249
249
250
250
/* *
@@ -257,14 +257,15 @@ class db_copy_mgr_t
257
257
void delete_object (ARGS &&... args)
258
258
{
259
259
assert (m_current);
260
- m_current-> add_deletable (std::forward<ARGS>(args)...);
260
+ m_current. add_deletable (std::forward<ARGS>(args)...);
261
261
}
262
262
263
263
void flush ()
264
264
{
265
265
// flush current buffer if there is one
266
266
if (m_current) {
267
- m_processor->add_buffer (std::move (m_current));
267
+ m_processor->send_command (std::move (m_current));
268
+ m_current = {};
268
269
}
269
270
// close any ongoing copy operations
270
271
m_processor->end_copy ();
@@ -285,7 +286,7 @@ class db_copy_mgr_t
285
286
template <typename T>
286
287
void add_value (T value)
287
288
{
288
- m_current-> buffer += fmt::to_string (value);
289
+ m_current. buffer += fmt::to_string (value);
289
290
}
290
291
291
292
void add_value (std::string const &s) { add_value (s.c_str ()); }
@@ -296,22 +297,22 @@ class db_copy_mgr_t
296
297
for (char const *c = s; *c; ++c) {
297
298
switch (*c) {
298
299
case ' "' :
299
- m_current-> buffer += " \\\" " ;
300
+ m_current. buffer += " \\\" " ;
300
301
break ;
301
302
case ' \\ ' :
302
- m_current-> buffer += " \\\\ " ;
303
+ m_current. buffer += " \\\\ " ;
303
304
break ;
304
305
case ' \n ' :
305
- m_current-> buffer += " \\ n" ;
306
+ m_current. buffer += " \\ n" ;
306
307
break ;
307
308
case ' \r ' :
308
- m_current-> buffer += " \\ r" ;
309
+ m_current. buffer += " \\ r" ;
309
310
break ;
310
311
case ' \t ' :
311
- m_current-> buffer += " \\ t" ;
312
+ m_current. buffer += " \\ t" ;
312
313
break ;
313
314
default :
314
- m_current-> buffer += *c;
315
+ m_current. buffer += *c;
315
316
break ;
316
317
}
317
318
}
@@ -322,29 +323,29 @@ class db_copy_mgr_t
322
323
for (char const *c = s; *c; ++c) {
323
324
switch (*c) {
324
325
case ' "' :
325
- m_current-> buffer += R"( \\")" ;
326
+ m_current. buffer += R"( \\")" ;
326
327
break ;
327
328
case ' \\ ' :
328
- m_current-> buffer += R"( \\\\)" ;
329
+ m_current. buffer += R"( \\\\)" ;
329
330
break ;
330
331
case ' \n ' :
331
- m_current-> buffer += " \\ n" ;
332
+ m_current. buffer += " \\ n" ;
332
333
break ;
333
334
case ' \r ' :
334
- m_current-> buffer += " \\ r" ;
335
+ m_current. buffer += " \\ r" ;
335
336
break ;
336
337
case ' \t ' :
337
- m_current-> buffer += " \\ t" ;
338
+ m_current. buffer += " \\ t" ;
338
339
break ;
339
340
default :
340
- m_current-> buffer += *c;
341
+ m_current. buffer += *c;
341
342
break ;
342
343
}
343
344
}
344
345
}
345
346
346
347
std::shared_ptr<db_copy_thread_t > m_processor;
347
- std::unique_ptr< db_cmd_copy_delete_t <DELETER> > m_current;
348
+ db_cmd_copy_delete_t <DELETER> m_current;
348
349
std::size_t m_committed = 0 ;
349
350
};
350
351
0 commit comments