Fixed bug in pooling tests:

Paraneters in set_config() method have to be checked against the list of DSN keywords.
This commit is contained in:
Georg Richter
2020-06-17 08:59:31 +02:00
parent 9076358737
commit 5631d6ed3f
3 changed files with 28 additions and 17 deletions

View File

@ -276,6 +276,7 @@ typedef struct {
unsigned long max_len; unsigned long max_len;
} Mariadb_Conversion; } Mariadb_Conversion;
extern char *dsn_keys[];
/* Exceptions */ /* Exceptions */
extern PyObject *Mariadb_InterfaceError; extern PyObject *Mariadb_InterfaceError;

View File

@ -20,6 +20,20 @@
#include "mariadb_python.h" #include "mariadb_python.h"
#include "docs/connection.h" #include "docs/connection.h"
char *dsn_keys[]= {
"dsn", "host", "user", "password", "database", "port", "unix_socket",
"connect_timeout", "read_timeout", "write_timeout",
"local_infile", "compress", "init_command",
"default_file", "default_group",
"ssl_key", "ssl_ca", "ssl_cert", "ssl_crl",
"ssl_cipher", "ssl_capath", "ssl_crlpath",
"ssl_verify_cert", "ssl",
"client_flags", "pool_name", "pool_size",
"pool_reset_connection", "plugin_dir",
"username", "db", "password",
NULL
};
void void
MrdbConnection_dealloc(MrdbConnection *self); MrdbConnection_dealloc(MrdbConnection *self);
@ -288,21 +302,6 @@ MrdbConnection_Initialize(MrdbConnection *self,
unsigned int connect_timeout=0, read_timeout=0, write_timeout=0, unsigned int connect_timeout=0, read_timeout=0, write_timeout=0,
compress= 0, ssl_verify_cert= 0; compress= 0, ssl_verify_cert= 0;
char *dsn_keys[]= {
"dsn", "host", "user", "password", "database", "port", "unix_socket",
"connect_timeout", "read_timeout", "write_timeout",
"local_infile", "compress", "init_command",
"default_file", "default_group",
"ssl_key", "ssl_ca", "ssl_cert", "ssl_crl",
"ssl_cipher", "ssl_capath", "ssl_crlpath",
"ssl_verify_cert", "ssl",
"client_flags", "pool_name", "pool_size",
"pool_reset_connection", "plugin_dir",
"username", "db", "password",
NULL
};
if (!PyArg_ParseTupleAndKeywords(args, dsnargs, if (!PyArg_ParseTupleAndKeywords(args, dsnargs,
"|sssssisiiibbssssssssssipisibssss:connect", "|sssssisiiibbssssssssssipisibssss:connect",
dsn_keys, dsn_keys,

View File

@ -415,10 +415,21 @@ static PyObject
while(PyDict_Next(kwargs, &pos, &key, &value)) while(PyDict_Next(kwargs, &pos, &key, &value))
{ {
const char *utf8key= PyUnicode_AsUTF8(key); const char *utf8key= PyUnicode_AsUTF8(key);
if (!strncmp(utf8key, "pool", 4)) uint8_t i=0, found=0;
while (dsn_keys[i])
{
if (!strcmp(utf8key, dsn_keys[i]))
{
found= 1;
break;
}
i++;
}
if (!found)
{ {
mariadb_throw_exception(NULL, Mariadb_PoolError, 0, mariadb_throw_exception(NULL, Mariadb_PoolError, 0,
"Invalid parameter '%s'. Only DSN parameters are supported", "Invalid DSN parameter '%s'",
utf8key); utf8key);
return NULL; return NULL;
} }