@@ -39,11 +39,12 @@ string EscapeConnectionString(const string &input) {
39
39
return result;
40
40
}
41
41
42
- string AddConnectionOption (const KeyValueSecret &kv_secret, const string &name, const unordered_set<string> &existing_params) {
42
+ string AddConnectionOption (const KeyValueSecret &kv_secret, const string &name,
43
+ const unordered_set<string> &existing_params) {
43
44
if (existing_params.find (name) != existing_params.end ()) {
44
- // option already provided in connection string
45
- return string ();
46
- }
45
+ // option already provided in connection string
46
+ return string ();
47
+ }
47
48
Value input_val = kv_secret.TryGetValue (name);
48
49
if (input_val.IsNull ()) {
49
50
// not provided
@@ -83,13 +84,13 @@ string UnescapePercentage(const string &input, idx_t start, idx_t end) {
83
84
auto url_escapes = " 20 3C<3E>23#25%2B+7B{7D}7C|5C\\ 5E^7E~5B[5D]60`3B;2F/3F?3A;40@3D=26&24$" ;
84
85
85
86
string result;
86
- for (idx_t i = start; i < end; i++) {
87
+ for (idx_t i = start; i < end; i++) {
87
88
if (i + 2 < end && input[i] == ' %' ) {
88
89
// find the escape code
89
90
char first_char = StringUtil::CharacterToUpper (input[i + 1 ]);
90
91
char second_char = StringUtil::CharacterToUpper (input[i + 2 ]);
91
92
char escape_result = ' \0 ' ;
92
- for (idx_t esc_pos = 0 ; url_escapes[esc_pos]; esc_pos += 3 ) {
93
+ for (idx_t esc_pos = 0 ; url_escapes[esc_pos]; esc_pos += 3 ) {
93
94
if (first_char == url_escapes[esc_pos] && second_char == url_escapes[esc_pos + 1 ]) {
94
95
// found the correct escape
95
96
escape_result = url_escapes[esc_pos + 2 ];
@@ -111,25 +112,25 @@ string UnescapePercentage(const string &input, idx_t start, idx_t end) {
111
112
112
113
vector<URIToken> ParseURITokens (const string &dsn, idx_t start) {
113
114
vector<URIToken> result;
114
- for (idx_t pos = start; pos < dsn.size (); pos++) {
115
- switch (dsn[pos]) {
116
- case ' :' :
117
- case ' @' :
118
- case ' /' :
119
- case ' ?' :
120
- case ' =' :
121
- case ' &' : {
122
- // found a delimiter
123
- URIToken token;
124
- token.value = UnescapePercentage (dsn, start, pos);
125
- token.delimiter = dsn[pos];
126
- start = pos + 1 ;
127
- result.push_back (std::move (token));
128
- break ;
129
- }
130
- default :
131
- // include in token
132
- break ;
115
+ for (idx_t pos = start; pos < dsn.size (); pos++) {
116
+ switch (dsn[pos]) {
117
+ case ' :' :
118
+ case ' @' :
119
+ case ' /' :
120
+ case ' ?' :
121
+ case ' =' :
122
+ case ' &' : {
123
+ // found a delimiter
124
+ URIToken token;
125
+ token.value = UnescapePercentage (dsn, start, pos);
126
+ token.delimiter = dsn[pos];
127
+ start = pos + 1 ;
128
+ result.push_back (std::move (token));
129
+ break ;
130
+ }
131
+ default :
132
+ // include in token
133
+ break ;
133
134
}
134
135
}
135
136
URIToken token;
@@ -140,7 +141,8 @@ vector<URIToken> ParseURITokens(const string &dsn, idx_t start) {
140
141
}
141
142
142
143
struct URIValue {
143
- URIValue (string name_p, string value_p) : name(std::move(name_p)), value(std::move(value_p)) {}
144
+ URIValue (string name_p, string value_p) : name(std::move(name_p)), value(std::move(value_p)) {
145
+ }
144
146
145
147
string name;
146
148
string value;
@@ -207,13 +209,14 @@ vector<string> GetAttributeNames(const vector<URIToken> &tokens, idx_t token_cou
207
209
return result;
208
210
}
209
211
210
- void ParseMainAttributes (const vector<URIToken> &tokens, idx_t token_count, vector<URIValue> &result, ErrorData &error) {
212
+ void ParseMainAttributes (const vector<URIToken> &tokens, idx_t token_count, vector<URIValue> &result,
213
+ ErrorData &error) {
211
214
auto attribute_names = GetAttributeNames (tokens, token_count, error);
212
215
if (error.HasError ()) {
213
216
return ;
214
217
}
215
218
D_ASSERT (attribute_names.size () == token_count);
216
- for (idx_t i = 0 ; i < token_count; i++) {
219
+ for (idx_t i = 0 ; i < token_count; i++) {
217
220
result.emplace_back (attribute_names[i], tokens[i].value );
218
221
}
219
222
}
@@ -232,7 +235,7 @@ void ParseAttributes(const vector<URIToken> &tokens, idx_t attribute_start, vect
232
235
uri_attribute_map[" ssl-key" ] = " ssl_key" ;
233
236
234
237
// parse key=value attributes
235
- for (idx_t i = attribute_start; i < tokens.size (); i += 2 ) {
238
+ for (idx_t i = attribute_start; i < tokens.size (); i += 2 ) {
236
239
// check if the format is correct
237
240
if (i + 1 >= tokens.size () || tokens[i].delimiter != ' =' ) {
238
241
throw ParserException (" Invalid URI string - expected attribute=value pairs after ?" );
@@ -243,13 +246,14 @@ void ParseAttributes(const vector<URIToken> &tokens, idx_t attribute_start, vect
243
246
auto entry = uri_attribute_map.find (tokens[i].value );
244
247
if (entry == uri_attribute_map.end ()) {
245
248
string supported_options;
246
- for (auto &entry : uri_attribute_map) {
249
+ for (auto &entry : uri_attribute_map) {
247
250
if (!supported_options.empty ()) {
248
251
supported_options += " , " ;
249
252
}
250
253
supported_options += entry.first ;
251
254
}
252
- throw ParserException (" Invalid URI string - unsupported attribute \" %s\"\n Supported options: %s" , tokens[i].value , supported_options);
255
+ throw ParserException (" Invalid URI string - unsupported attribute \" %s\"\n Supported options: %s" ,
256
+ tokens[i].value , supported_options);
253
257
}
254
258
result.emplace_back (entry->second , tokens[i + 1 ].value );
255
259
}
@@ -262,15 +266,15 @@ vector<URIValue> ExtractURIValues(const vector<URIToken> &tokens, ErrorData &err
262
266
if (tokens.empty ()) {
263
267
return result;
264
268
}
265
-
269
+
266
270
// If we only have one empty token with no delimiter, don't treat it as a host
267
271
if (tokens.size () == 1 && tokens[0 ].value .empty () && tokens[0 ].delimiter == ' \0 ' ) {
268
272
return result;
269
273
}
270
-
274
+
271
275
// figure out how many "non-attribute" tokens we have
272
276
idx_t attribute_start = tokens.size ();
273
- for (idx_t i = 0 ; i < tokens.size (); i++) {
277
+ for (idx_t i = 0 ; i < tokens.size (); i++) {
274
278
if (tokens[i].delimiter == ' ?' ) {
275
279
// found a question-mark - this is a token
276
280
attribute_start = i + 1 ;
@@ -296,8 +300,8 @@ bool TryConvertURIInternal(const string &dsn, idx_t start_pos, string &connectio
296
300
}
297
301
298
302
unordered_set<string> added_params;
299
-
300
- for (auto &val : values) {
303
+
304
+ for (auto &val : values) {
301
305
// Skip duplicate parameters
302
306
if (added_params.find (val.name ) != added_params.end ()) {
303
307
continue ;
@@ -321,7 +325,7 @@ void TryConvertURI(string &dsn) {
321
325
if (dsn.empty ()) {
322
326
return ;
323
327
}
324
-
328
+
325
329
// [scheme://][user[:[password]]@]host[:port][/schema][?attribute1=value1&attribute2=value2...
326
330
idx_t start_pos = 0 ;
327
331
// skip the past the scheme (either mysql:// or mysqlx://)
@@ -376,7 +380,7 @@ string MySQLCatalog::GetConnectionString(ClientContext &context, const string &a
376
380
// Build a new connection string with parameters from the secret that don't
377
381
// already exist in the original connection string
378
382
string new_connection_info;
379
-
383
+
380
384
new_connection_info += AddConnectionOption (kv_secret, " user" , existing_params);
381
385
new_connection_info += AddConnectionOption (kv_secret, " password" , existing_params);
382
386
new_connection_info += AddConnectionOption (kv_secret, " host" , existing_params);
@@ -431,15 +435,16 @@ void MySQLCatalog::ScanSchemas(ClientContext &context, std::function<void(Schema
431
435
schemas.Scan (context, [&](CatalogEntry &schema) { callback (schema.Cast <MySQLSchemaEntry>()); });
432
436
}
433
437
434
- optional_ptr<SchemaCatalogEntry> MySQLCatalog::GetSchema (CatalogTransaction transaction, const string &schema_name,
435
- OnEntryNotFound if_not_found,
436
- QueryErrorContext error_context) {
438
+ optional_ptr<SchemaCatalogEntry> MySQLCatalog::LookupSchema (CatalogTransaction transaction,
439
+ const EntryLookupInfo &schema_lookup,
440
+ OnEntryNotFound if_not_found) {
441
+ auto schema_name = schema_lookup.GetEntryName ();
437
442
if (schema_name == DEFAULT_SCHEMA) {
438
443
if (default_schema.empty ()) {
439
444
throw InvalidInputException (" Attempting to fetch the default schema - but no database was "
440
445
" provided in the connection string" );
441
446
}
442
- return GetSchema (transaction, default_schema, if_not_found, error_context) ;
447
+ schema_name = default_schema;
443
448
}
444
449
auto entry = schemas.GetEntry (transaction.GetContext (), schema_name);
445
450
if (!entry && if_not_found != OnEntryNotFound::RETURN_NULL) {
0 commit comments