本文整理汇总了C++中DatabaseConnection::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::connect方法的具体用法?C++ DatabaseConnection::connect怎么用?C++ DatabaseConnection::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dbConnect
SEXP dbConnect(SEXP dbType_sexp,
SEXP connection_string_sexp,
SEXP user_sexp,
SEXP pass_sexp,
SEXP host_sexp,
SEXP port_sexp,
SEXP tty_sexp,
SEXP dbName_sexp,
SEXP options_sexp) {
SEXP dbi_conn_sexp;
DatabaseConnection* conn = NULL;
const char* dbType = CHAR(STRING_PTR(dbType_sexp)[0]);
const char* connection_string = (connection_string_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(connection_string_sexp)[0]);
const char* user = (user_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(user_sexp)[0]);
const char* pass = (pass_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(pass_sexp)[0]);
const char* host = (host_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(host_sexp)[0]);
const char* port = (port_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(port_sexp)[0]);
const char* tty = (tty_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(tty_sexp)[0]);
const char* dbName = (dbName_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(dbName_sexp)[0]);
const char* options = (options_sexp == R_NilValue) ? NULL : CHAR(STRING_PTR(options_sexp)[0]);
// this test is to check whether the package was compiled with support
// for this specific dbType
try {
conn = DatabaseConnection::init(dbType);
} catch (DriverNotSupported& e) {
REprintf("%s\n",e.what());
return R_NilValue;
}
// if we succeed then return a wrapped connection, otherwise return null
try {
// if user provides connection_string, then use it, otherwise try traditional args
if(connection_string) {
conn->connect(connection_string);
} else {
conn->connect(user,pass,host,port,tty,dbName,options);
}
} catch(BadDatabaseConnection& e) {
REprintf("%s\n",e.what());
return R_NilValue;
}
PROTECT(dbi_conn_sexp = R_MakeExternalPtr(reinterpret_cast<void*>(conn),install("DBI_conn_pointer"),R_NilValue));
R_RegisterCFinalizerEx(dbi_conn_sexp, connFinalizer, TRUE);
UNPROTECT(1);
return dbi_conn_sexp;
}