@@ -119,6 +119,13 @@ inline string quote(bool bulk, string s) {
119
119
120
120
inline string quote (string s) { return quote (false , s); }
121
121
122
+ inline string quote_bytea (bool bulk, string s) {
123
+ if (bulk)
124
+ return " \\\\ x" + s;
125
+ else
126
+ return " '\\ x" + s + " '" ;
127
+ }
128
+
122
129
template <typename T>
123
130
string sql_str (pqxx::connection& c, bool bulk, const T& obj);
124
131
@@ -159,14 +166,14 @@ string sql_str(pqxx::connection&, bool bulk, varuint32 v) { return stri
159
166
string sql_str (pqxx::connection&, bool bulk, varint32 v) { return string (v); }
160
167
string sql_str (pqxx::connection&, bool bulk, int128 v) { return string (v); }
161
168
string sql_str (pqxx::connection&, bool bulk, uint128 v) { return string (v); }
162
- string sql_str (pqxx::connection&, bool bulk, float128 v) { if (bulk) return " \\\\ x " + string (v); return " ' \\ x " + string (v) + " ' " ; }
163
- string sql_str (pqxx::connection&, bool bulk, name v) { auto s = v.value ? string (v) : " " s; if (bulk) return s; return " ' " + s + " ' " ; }
169
+ string sql_str (pqxx::connection&, bool bulk, float128 v) { return quote_bytea (bulk, string (v)) ; }
170
+ string sql_str (pqxx::connection&, bool bulk, name v) { return quote (bulk, v.value ? string (v) : " " s) ; }
164
171
string sql_str (pqxx::connection&, bool bulk, time_point v) { return quote (bulk, string (v)); }
165
172
string sql_str (pqxx::connection&, bool bulk, time_point_sec v) { return quote (bulk, string (v)); }
166
173
string sql_str (pqxx::connection&, bool bulk, block_timestamp v) { return quote (bulk, string (v)); }
167
174
string sql_str (pqxx::connection&, bool bulk, checksum256 v) { return quote (bulk, string (v)); }
168
- string sql_str (pqxx::connection&, bool bulk, const public_key& v) { if (bulk) return public_key_to_string (v); return " ' " + public_key_to_string (v) + " ' " ; }
169
- string sql_str (pqxx::connection&, bool bulk, transaction_status v) { if (bulk) return to_string (v); return " ' " + to_string (v) + " ' " ; }
175
+ string sql_str (pqxx::connection&, bool bulk, const public_key& v) { return quote (bulk, public_key_to_string (v)) ; }
176
+ string sql_str (pqxx::connection&, bool bulk, transaction_status v) { return quote (bulk, to_string (v)) ; }
170
177
// clang-format on
171
178
172
179
template <typename T>
@@ -218,29 +225,17 @@ string bin_to_sql<bytes>(pqxx::connection&, bool bulk, input_buffer& bin) {
218
225
if (size > bin.end - bin.pos )
219
226
throw error (" invalid bytes size" );
220
227
string result;
221
- if (bulk)
222
- result = " \\\\ x" ;
223
- else
224
- result = " '\\ x" ;
225
228
boost::algorithm::hex (bin.pos , bin.pos + size, back_inserter (result));
226
229
bin.pos += size;
227
- if (!bulk)
228
- result += " '" ;
229
- return result;
230
+ return quote_bytea (bulk, result);
230
231
}
231
232
232
233
template <>
233
234
string native_to_sql<bytes>(pqxx::connection&, bool bulk, const void * p) {
234
235
auto & obj = reinterpret_cast <const bytes*>(p)->data ;
235
236
string result;
236
- if (bulk)
237
- result = " \\\\ x" ;
238
- else
239
- result = " '\\ x" ;
240
237
boost::algorithm::hex (obj.data (), obj.data () + obj.size (), back_inserter (result));
241
- if (!bulk)
242
- result += " '" ;
243
- return result;
238
+ return quote_bytea (bulk, result);
244
239
}
245
240
246
241
template <>
@@ -252,14 +247,8 @@ template <>
252
247
string native_to_sql<input_buffer>(pqxx::connection&, bool bulk, const void * p) {
253
248
auto & obj = *reinterpret_cast <const input_buffer*>(p);
254
249
string result;
255
- if (bulk)
256
- result = " \\\\ x" ;
257
- else
258
- result = " '\\ x" ;
259
250
boost::algorithm::hex (obj.pos , obj.end , back_inserter (result));
260
- if (!bulk)
261
- result += " '" ;
262
- return result;
251
+ return quote_bytea (bulk, result);
263
252
}
264
253
265
254
// clang-format off
@@ -1091,29 +1080,16 @@ struct session : enable_shared_from_this<session> {
1091
1080
1092
1081
string fields = " block_index, block_id, timestamp, producer, confirmed, previous, transaction_mroot, action_mroot, "
1093
1082
" schedule_version, new_producers_version, new_producers" ;
1094
- string values;
1095
- if (bulk)
1096
- values = to_string (block_index) + " \t " + //
1097
- string (block_id) + " \t " + //
1098
- string (block.timestamp ) + " \t " + //
1099
- string (block.producer ) + " \t " + //
1100
- to_string (block.confirmed ) + " \t " + //
1101
- string (block.previous ) + " \t " + //
1102
- string (block.transaction_mroot ) + " \t " + //
1103
- string (block.action_mroot ) + " \t " + //
1104
- to_string (block.schedule_version ) + " \t " + //
1105
- to_string (block.new_producers ? block.new_producers ->version : 0 ); //
1106
- else
1107
- values = to_string (block_index) + " , " + //
1108
- quote (string (block_id)) + " , " + //
1109
- quote (string (block.timestamp )) + " , " + //
1110
- quote (string (block.producer )) + " , " + //
1111
- to_string (block.confirmed ) + " , " + //
1112
- quote (string (block.previous )) + " , " + //
1113
- quote (string (block.transaction_mroot )) + " , " + //
1114
- quote (string (block.action_mroot )) + " , " + //
1115
- to_string (block.schedule_version ) + " , " + //
1116
- to_string (block.new_producers ? block.new_producers ->version : 0 ); //
1083
+ string values = to_string (block_index) + sep (bulk) + //
1084
+ quote (bulk, string (block_id)) + sep (bulk) + //
1085
+ quote (bulk, string (block.timestamp )) + sep (bulk) + //
1086
+ quote (bulk, string (block.producer )) + sep (bulk) + //
1087
+ to_string (block.confirmed ) + sep (bulk) + //
1088
+ quote (bulk, string (block.previous )) + sep (bulk) + //
1089
+ quote (bulk, string (block.transaction_mroot )) + sep (bulk) + //
1090
+ quote (bulk, string (block.action_mroot )) + sep (bulk) + //
1091
+ to_string (block.schedule_version ) + sep (bulk) + //
1092
+ to_string (block.new_producers ? block.new_producers ->version : 0 ); //
1117
1093
1118
1094
if (block.new_producers ) {
1119
1095
if (bulk)
0 commit comments