Skip to content

Commit 5631d6e

Browse files
committed
Fixed bug in pooling tests:
Paraneters in set_config() method have to be checked against the list of DSN keywords.
1 parent 9076358 commit 5631d6e

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

include/mariadb_python.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ typedef struct {
276276
unsigned long max_len;
277277
} Mariadb_Conversion;
278278

279+
extern char *dsn_keys[];
279280

280281
/* Exceptions */
281282
extern PyObject *Mariadb_InterfaceError;

src/mariadb_connection.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
#include "mariadb_python.h"
2121
#include "docs/connection.h"
2222

23+
char *dsn_keys[]= {
24+
"dsn", "host", "user", "password", "database", "port", "unix_socket",
25+
"connect_timeout", "read_timeout", "write_timeout",
26+
"local_infile", "compress", "init_command",
27+
"default_file", "default_group",
28+
"ssl_key", "ssl_ca", "ssl_cert", "ssl_crl",
29+
"ssl_cipher", "ssl_capath", "ssl_crlpath",
30+
"ssl_verify_cert", "ssl",
31+
"client_flags", "pool_name", "pool_size",
32+
"pool_reset_connection", "plugin_dir",
33+
"username", "db", "password",
34+
NULL
35+
};
36+
2337
void
2438
MrdbConnection_dealloc(MrdbConnection *self);
2539

@@ -288,21 +302,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
288302
unsigned int connect_timeout=0, read_timeout=0, write_timeout=0,
289303
compress= 0, ssl_verify_cert= 0;
290304

291-
char *dsn_keys[]= {
292-
"dsn", "host", "user", "password", "database", "port", "unix_socket",
293-
"connect_timeout", "read_timeout", "write_timeout",
294-
"local_infile", "compress", "init_command",
295-
"default_file", "default_group",
296-
"ssl_key", "ssl_ca", "ssl_cert", "ssl_crl",
297-
"ssl_cipher", "ssl_capath", "ssl_crlpath",
298-
"ssl_verify_cert", "ssl",
299-
"client_flags", "pool_name", "pool_size",
300-
"pool_reset_connection", "plugin_dir",
301-
"username", "db", "password",
302-
NULL
303-
};
304-
305-
306305
if (!PyArg_ParseTupleAndKeywords(args, dsnargs,
307306
"|sssssisiiibbssssssssssipisibssss:connect",
308307
dsn_keys,

src/mariadb_pooling.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,21 @@ static PyObject
415415
while(PyDict_Next(kwargs, &pos, &key, &value))
416416
{
417417
const char *utf8key= PyUnicode_AsUTF8(key);
418-
if (!strncmp(utf8key, "pool", 4))
418+
uint8_t i=0, found=0;
419+
420+
while (dsn_keys[i])
421+
{
422+
if (!strcmp(utf8key, dsn_keys[i]))
423+
{
424+
found= 1;
425+
break;
426+
}
427+
i++;
428+
}
429+
if (!found)
419430
{
420431
mariadb_throw_exception(NULL, Mariadb_PoolError, 0,
421-
"Invalid parameter '%s'. Only DSN parameters are supported",
432+
"Invalid DSN parameter '%s'",
422433
utf8key);
423434
return NULL;
424435
}

0 commit comments

Comments
 (0)