Msql-Mysql-modules
view release on metacpan or search on metacpan
dbd/dbdimp.c view on Meta::CPAN
*
**************************************************************************/
int MyConnect(dbh_t *sock, char* unixSocket, char* host, char* port,
char* user, char* password, char* dbname, imp_dbh_t *imp_dbh) {
int portNr;
if (host && !*host) host = NULL;
if (port && *port) {
portNr = atoi(port);
} else {
portNr = 0;
}
if (user && !*user) user = NULL;
if (password && !*password) password = NULL;
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP,
"imp_dbh->MyConnect: host = %s, port = %d, uid = %s," \
" pwd = %s\n",
host ? host : "NULL", portNr,
user ? user : "NULL",
password ? password : "NULL");
#ifdef DBD_MYSQL
{
#ifdef MYSQL_USE_CLIENT_FOUND_ROWS
unsigned int client_flag = CLIENT_FOUND_ROWS;
#else
unsigned int client_flag = 0;
#endif
mysql_init(*sock);
if (imp_dbh) {
SV* sv = DBIc_IMP_DATA(imp_dbh);
imp_dbh->has_transactions = TRUE;
DBIc_set(imp_dbh, DBIcf_AutoCommit, &sv_yes);
if (sv && SvROK(sv)) {
HV* hv = (HV*) SvRV(sv);
SV** svp;
STRLEN lna;
if ((svp = hv_fetch(hv, "mysql_compression", 17, FALSE)) &&
*svp && SvTRUE(*svp)) {
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP,
"imp_dbh->MyConnect: Enabling" \
" compression.\n");
mysql_options(*sock, MYSQL_OPT_COMPRESS, NULL);
}
if ((svp = hv_fetch(hv, "mysql_connect_timeout", 21, FALSE))
&& *svp && SvTRUE(*svp)) {
int to = SvIV(*svp);
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP,
"imp_dbh->MyConnect: Setting" \
" connect timeout (%d).\n",to);
mysql_options(*sock, MYSQL_OPT_CONNECT_TIMEOUT,
(const char *)&to);
}
if ((svp = hv_fetch(hv, "mysql_read_default_file", 23,
FALSE)) &&
*svp && SvTRUE(*svp)) {
char* df = SvPV(*svp, lna);
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP,
"imp_dbh->MyConnect: Reading" \
" default file %s.\n", df);
mysql_options(*sock, MYSQL_READ_DEFAULT_FILE, df);
}
if ((svp = hv_fetch(hv, "mysql_read_default_group", 24,
FALSE)) &&
*svp && SvTRUE(*svp)) {
char* gr = SvPV(*svp, lna);
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP,
"imp_dbh->MyConnect: Using" \
" default group %s.\n", gr);
mysql_options(*sock, MYSQL_READ_DEFAULT_GROUP, gr);
}
if ((svp = hv_fetch(hv, "mysql_client_found_rows", 23,
FALSE)) && *svp) {
if (SvTRUE(*svp)) {
client_flag |= CLIENT_FOUND_ROWS;
} else {
client_flag &= ~CLIENT_FOUND_ROWS;
}
}
}
}
if (dbis->debug >= 2)
PerlIO_printf(DBILOGFP, "imp_dbh->MyConnect: client_flags = %d\n",
client_flag);
return mysql_real_connect(*sock, host, user, password, dbname,
portNr, unixSocket, client_flag) ?
TRUE : FALSE;
}
#else
{
/*
* Setting a port for msql's client is extremely ugly: We have
* to set an environment variable. Even worse, we cannot trust
* in setenv or putenv being present, thus we need to use
* internal, not documented, perl functions. :-(
*/
char buffer[32];
char* oldPort = NULL;
if (imp_dbh) {
imp_dbh->has_transactions = FALSE;
DBIc_set(imp_dbh, DBIcf_AutoCommit, &sv_yes);
}
sprintf(buffer, "%d", portNr);
if (portNr) {
oldPort = environ[setenv_getix("MSQL_TCP_PORT")];
if (oldPort) {
char* copy = (char*) malloc(strlen(oldPort)+1);
if (!copy) {
return FALSE;
}
( run in 0.715 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )