DBD-ODBC
view release on metacpan or search on metacpan
while (*cp != '\0') {
*cp = toupper(*cp);
cp++; /* see rt 79190 was a sequence point error*/
}
return (strstr(upper_dsn, "UID=") != 0 || strstr(upper_dsn, "PWD=") != 0);
}
/************************************************************************/
/* */
/* dbd_db_login */
/* ============ */
/* */
/* NOTE: This is the old 5 argument version with no attribs */
/* */
/************************************************************************/
int dbd_db_login(
SV *dbh,
imp_dbh_t *imp_dbh,
char *dbname,
char *uid,
char *pwd)
{
return dbd_db_login6(dbh, imp_dbh, dbname, uid, pwd, Nullsv);
}
/************************************************************************/
/* */
/* dbd_db_login6_sv */
/* ================ */
/* */
/* This API was introduced in DBI after 1.607 (subversion revision */
/* 11723) and is the same as dbd_db_login6 except the connection */
/* strings are SVs so we can detect unicode strings and call */
/* SQLDriveConnectW. */
/* */
/************************************************************************/
int dbd_db_login6_sv(
SV *dbh,
imp_dbh_t *imp_dbh,
SV *dbname,
SV *uid,
SV *pwd,
SV *attr)
{
dTHX;
#ifndef WITH_UNICODE
if (DBIc_TRACE(imp_dbh, CONNECTION_TRACING, 0, 0))
TRACE0(imp_dbh, "non-Unicode login6_sv\n");
return dbd_db_login6(dbh, imp_dbh, SvPV_nolen(dbname),
(SvOK(uid) ? SvPV_nolen(uid) : NULL),
(SvOK(pwd) ? SvPV_nolen(pwd) : NULL), attr);
#else
D_imp_drh_from_dbh;
SQLRETURN rc;
SV *wconstr; /* copy of connection string in wide chrs */
/* decoded connection string in wide characters and its length to work
around an issue in older unixODBCs */
SQLWCHAR dc_constr[512];
STRLEN dc_constr_len;
if (DBIc_TRACE(imp_dbh, CONNECTION_TRACING, 0, 0)) {
TRACE2(imp_dbh, "Unicode login6 dbname=%s, uid=%s, pwd=xxxxx\n",
SvPV_nolen(dbname), neatsvpv(uid, 0));
}
imp_dbh->out_connect_string = Nullsv;
if (!imp_drh->connects) {
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &imp_drh->henv);
dbd_error(dbh, rc, "db_login6_sv/SQLAllocHandle(env)");
if (!SQL_SUCCEEDED(rc)) return 0;
if (set_odbc_version(aTHX_ dbh, imp_dbh, attr) != 1) return 0;
}
imp_dbh->henv = imp_drh->henv; /* needed for dbd_error */
/* If odbc_trace_file set, set it in ODBC */
{
SV **attr_sv;
char *file;
if ((attr_sv =
DBD_ATTRIB_GET_SVP(attr, "odbc_trace_file",
(I32)strlen("odbc_trace_file"))) != NULL) {
if (SvPOK(*attr_sv)) {
file = SvPV_nolen(*attr_sv);
rc = SQLSetConnectAttr(NULL, SQL_ATTR_TRACEFILE,
file, strlen(file));
if (!SQL_SUCCEEDED(rc)) {
warn("Failed to set trace file");
}
}
}
}
/* If odbc_trace enabled, turn ODBC tracing on */
{
UV dc = 0;
SV **svp;
DBD_ATTRIB_GET_IV(attr, "odbc_trace", 10, svp, dc);
if (svp && dc) {
rc = SQLSetConnectAttr(NULL, SQL_ATTR_TRACE,
(SQLPOINTER)SQL_OPT_TRACE_ON, 0);
if (!SQL_SUCCEEDED(rc)) {
warn("Failed to enable tracing");
}
}
}
rc = SQLAllocHandle(SQL_HANDLE_DBC, imp_drh->henv, &imp_dbh->hdbc);
if (!SQL_SUCCEEDED(rc)) {
dbd_error(dbh, rc, "db_login6_sv/SQLAllocHandle(dbc)");
if (imp_drh->connects == 0) {
SQLFreeHandle(SQL_HANDLE_ENV, imp_drh->henv);
imp_drh->henv = SQL_NULL_HENV;
( run in 0.679 second using v1.01-cache-2.11-cpan-39bf76dae61 )