DBD-mysqlx
view release on metacpan or search on metacpan
/*
* DBD::mysqlx - DBI X Protocol driver for the MySQL database
*
* Copyright (c) 2018 Daniël van Eeden
*
* You may distribute this under the terms of either the GNU General Public
* License or the Artistic License, as specified in the Perl README file.
*/
#include "dbdimp.h"
DBISTATE_DECLARE;
/* Check if a collation is using UTF-8
*
* To get the ID's:
* SELECT ID FROM information_schema.COLLATIONS WHERE CHARACTER_SET_NAME LIKE
* 'utf8%' ORDER BY IS_DEFAULT DESC, COLLATION_NAME LIKE '%\_general\_%' DESC,
* COLLATION_NAME LIKE '%\_bin%' DESC, COLLATION_NAME LIKE '%\_unicode\_%' DESC,
* COLLATION_NAME LIKE 'utf8mb4_0900\_%' DESC
*
* Note that default and generic collations are moved to the front of the list
*/
bool dbd_mysqlx_is_utf8_collation(uint16_t collation) {
uint16_t utf8collations[] = {
33, 255, 223, 45, 83, 46, 192, 246, 224, 214, 305, 278, 199, 207, 215,
228, 236, 244, 259, 267, 277, 285, 293, 200, 208, 229, 237, 245, 260, 268,
286, 294, 306, 193, 201, 209, 230, 238, 261, 269, 279, 287, 296, 307, 194,
202, 210, 231, 239, 247, 262, 270, 280, 288, 297, 195, 203, 211, 232, 240,
263, 271, 281, 289, 298, 196, 204, 212, 225, 233, 241, 256, 264, 273, 282,
290, 300, 197, 205, 213, 226, 234, 242, 257, 265, 274, 283, 291, 303, 76,
198, 206, 227, 235, 243, 258, 266, 275, 284, 292, 304};
for (int col = 0; col < sizeof(utf8collations) / sizeof(uint16_t); col++) {
if (utf8collations[col] == collation)
return true;
}
return false;
}
static void dbd_drv_error(SV *h, int rc, const char *what) {
D_imp_xxh(h);
DBIh_SET_ERR_CHAR(h, imp_xxh, Nullch, rc, what, Nullch, Nullch);
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "dbd_drv_error\n");
}
void dbd_init(dbistate_t *dbistate) {
DBISTATE_INIT; // Initialize the DBI macros
}
int dbd_db_login6(SV *dbh, imp_dbh_t *imp_dbh, char *dbname, char *uid,
char *pwd, SV *attribs) {
int errcode;
char errstr[255];
dTHX;
D_imp_xxh(dbh);
size_t url_len =
strlen("mysqlx://:@") + strlen(uid) + strlen(pwd) + strlen(dbname) + 1;
char url[url_len];
snprintf(url, url_len, "mysqlx://%s:%s@%s", uid, pwd, dbname);
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "url=%s\n", url);
imp_dbh->sess = mysqlx_get_session_from_url(url, errstr, &errcode);
if (!imp_dbh->sess) {
dbd_drv_error(dbh, errcode, errstr);
return 0;
} else {
DBIc_IMPSET_on(imp_dbh); // request call to destroy
DBIc_ACTIVE_on(imp_dbh); // request call to disconnect
}
return 1;
( run in 3.110 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )