void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); try { ActiveConnector connector(connectionString(), &_pDB); ActiveResult<int> result = connector.connect(); if (!result.tryWait(getLoginTimeout() * 1000)) throw ConnectionFailedException("Timed out."); int rc = result.data(); if (rc != 0) { close(); Utility::throwException(rc); } } catch (SQLiteException& ex) { throw ConnectionFailedException(ex.displayText()); } _connected = true; }
bool ODBCLib::CODBCSession::startSession() { if(isConnecting()) { return false; } bool result = false; SQLRETURN ret = m_environmentHandle->setVersion(m_ODBCVersion); if(ret == SQL_SUCCESS) { m_connectionHandle.reset(new CConnectionHandle(m_environmentHandle)); if(m_connectionHandle->isHandleEnable()) { ret = m_connectionHandle->connect(connectionString().c_str()); if(ret == SQL_SUCCESS) { m_connectionHandle->setIsolationLevel(SQL_TXN_SS_SNAPSHOT); result = true; } else if(ret == SQL_SUCCESS_WITH_INFO) { m_connectionHandle->setIsolationLevel(SQL_TXN_SS_SNAPSHOT); result = true; // std::wcerr << ODBCLib::CDiagInfo(m_connectionHandle).description() << std::endl; } else { std::wcerr << L"CODBCSession::startSession() CConnectionHandle::connect()=" << ret << std::endl << ODBCLib::CDiagInfo(m_connectionHandle).description() << std::endl; } } } else { std::wcerr << L"CODBCSession::startSession() CEnvironmentHandle::setVersion()=" << ret << std::endl << ODBCLib::CDiagInfo(m_environmentHandle).description() << std::endl; } return result; }
jint Java_app_com_mapviewer_nativeApi_MapDrawer_openMapN ( JNIEnv *env, jobject thiz, jint ptr, jstring path, jint width, jint height, jint dpi) { CMapDrawer* pdrawer = (CMapDrawer*)ptr; if (!pdrawer) { return 0; } const char *string = env->GetStringUTFChars(path, 0); CommonLib::CString connectionString(string, strlen(string)); int ret = pdrawer->openMap(connectionString, width, height, dpi); env->ReleaseStringUTFChars(path, string); return ret; }
int main(int argc, char** argv) { if (argc < 3) { std::cout << "Not enough arguments given." << std::endl; return 0; } edmplugin::PluginManager::Config config; edmplugin::PluginManager::configure(edmplugin::standard::config()); std::vector<edm::ParameterSet> psets; edm::ParameterSet pSet; pSet.addParameter("@service_type", std::string("SiteLocalConfigService")); psets.push_back(pSet); edm::ServiceToken servToken(edm::ServiceRegistry::createSet(psets)); edm::ServiceRegistry::Operate operate(servToken); std::string connectionString("oracle://cms_orcon_adg/CMS_CONDITIONS"); std::string tag = std::string(argv[1]); std::string runTimeType = cond::time::timeTypeName(cond::runnumber); cond::Time_t since = boost::lexical_cast<unsigned long long>(argv[2]); std::cout << "## PNG Histo" << std::endl; BasicPayload_data6 histo1; histo1.process(connectionString, tag, runTimeType, since, since); std::cout << histo1.data() << std::endl; }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); try { ActiveConnector connector(connectionString(), &_pDB); ActiveResult<int> result = connector.connect(); if (!result.tryWait(getLoginTimeout() * 1000)) throw ConnectionFailedException("Timed out."); int rc = result.data(); if (rc != 0) { close(); Utility::throwException(rc); } } catch (SQLiteException& ex) { throw ConnectionFailedException(ex.displayText()); } if (SQLITE_OK != sqlite3_exec(_pDB, "attach database ':memory:' as sys;" "create table sys.dual (dummy);", 0, 0, 0)) { throw ExecutionException("Cannot create system database."); } _connected = true; }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); _handle.init(); unsigned int timeout = static_cast<unsigned int>(getLoginTimeout()); _handle.options(MYSQL_OPT_CONNECT_TIMEOUT, timeout); std::map<std::string, std::string> options; // Default values options["host"] = "localhost"; options["port"] = "3306"; options["user"] = ""; options["password"] = ""; options["db"] = ""; options["compress"] = ""; options["auto-reconnect"] = ""; options["secure-auth"] = ""; options["character-set"] = "utf8"; const std::string& connString = connectionString(); for (std::string::const_iterator start = connString.begin();;) { std::string::const_iterator finish = std::find(start, connString.end(), ';'); std::string::const_iterator middle = std::find(start, finish, '='); if (middle == finish) throw MySQLException("create session: bad connection string format, can not find '='"); options[copyStripped(start, middle)] = copyStripped(middle + 1, finish); if ((finish == connString.end()) || (finish + 1 == connString.end())) break; start = finish + 1; } if (options["user"].empty()) throw MySQLException("create session: specify user name"); const char * db = NULL; if (!options["db"].empty()) db = options["db"].c_str(); unsigned int port = 0; if (!NumberParser::tryParseUnsigned(options["port"], port) || 0 == port || port > 65535) throw MySQLException("create session: specify correct port (numeric in decimal notation)"); if (options["compress"] == "true") _handle.options(MYSQL_OPT_COMPRESS); else if (options["compress"] == "false") ; else if (!options["compress"].empty()) throw MySQLException("create session: specify correct compress option (true or false) or skip it"); if (options["auto-reconnect"] == "true") _handle.options(MYSQL_OPT_RECONNECT, true); else if (options["auto-reconnect"] == "false") _handle.options(MYSQL_OPT_RECONNECT, false); else if (!options["auto-reconnect"].empty()) throw MySQLException("create session: specify correct auto-reconnect option (true or false) or skip it"); if (options["secure-auth"] == "true") _handle.options(MYSQL_SECURE_AUTH, true); else if (options["secure-auth"] == "false") _handle.options(MYSQL_SECURE_AUTH, false); else if (!options["secure-auth"].empty()) throw MySQLException("create session: specify correct secure-auth option (true or false) or skip it"); if (!options["character-set"].empty()) _handle.options(MYSQL_SET_CHARSET_NAME, options["character-set"].c_str()); // Real connect _handle.connect(options["host"].c_str(), options["user"].c_str(), options["password"].c_str(), db, port); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); _connected = true; }
void SociConfig::open (soci::session& s) const { s.open (backendFactory_, connectionString ()); }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); SQLULEN tout = static_cast<SQLULEN>(getLoginTimeout()); if (Utility::isError(SQLSetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) tout, 0))) { if (Utility::isError(SQLGetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, &tout, 0, 0)) || getLoginTimeout() != tout) { ConnectionError e(_db); throw ConnectionFailedException(e.toString()); } } SQLCHAR connectOutput[512] = {0}; SQLSMALLINT result; if (Utility::isError(Poco::Data::ODBC::SQLDriverConnect(_db , NULL ,(SQLCHAR*) connectionString().c_str() ,(SQLSMALLINT) SQL_NTS , connectOutput , sizeof(connectOutput) , &result , SQL_DRIVER_NOPROMPT))) { ConnectionError err(_db); std::string errStr = err.toString(); close(); throw ConnectionFailedException(errStr); } _dataTypes.fillTypeInfo(_db); addProperty("dataTypeInfo", &SessionImpl::setDataTypeInfo, &SessionImpl::dataTypeInfo); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); addFeature("autoBind", &SessionImpl::autoBind, &SessionImpl::isAutoBind); addFeature("autoExtract", &SessionImpl::autoExtract, &SessionImpl::isAutoExtract); addProperty("maxFieldSize", &SessionImpl::setMaxFieldSize, &SessionImpl::getMaxFieldSize); addProperty("queryTimeout", &SessionImpl::setQueryTimeout, &SessionImpl::getQueryTimeout); Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0); if (!canTransact()) autoCommit("", true); }
int main (int argc, char** argv) { std::vector<coral::Option> secondaryOptions; // coral::Option csPar("conn_string"); csPar.flag = "-c"; csPar.helpEntry = "the database connection string"; csPar.type = coral::Option::STRING; secondaryOptions.push_back(csPar); // coral::Option contPar("container"); contPar.flag = "-cn"; contPar.helpEntry = "the selected container name"; contPar.type = coral::Option::STRING; secondaryOptions.push_back(contPar); // coral::Option mvPar("mapping_version"); mvPar.flag = "-mv"; mvPar.helpEntry ="the mapping version"; mvPar.type = coral::Option::STRING; secondaryOptions.push_back(mvPar); // coral::Option cvPar("class_versions"); cvPar.flag = "-cv"; cvPar.helpEntry ="specify the class versions"; cvPar.type = coral::Option::BOOLEAN; secondaryOptions.push_back(cvPar); // coral::Option outPar("output_file"); outPar.flag = "-f"; outPar.helpEntry = "the database host name"; outPar.type = coral::Option::STRING; secondaryOptions.push_back(outPar); // coral::Option authPar("authentication_path"); authPar.flag = "-a"; authPar.helpEntry = "the authentication path"; authPar.type = coral::Option::STRING; secondaryOptions.push_back(authPar); // coral::Option classPar("type_name"); classPar.flag = "-t"; classPar.helpEntry = "the container type name"; classPar.type = coral::Option::STRING; secondaryOptions.push_back(classPar); // coral::Option dictPar("dictionary"); dictPar.flag = "-D"; dictPar.helpEntry = "the list of dictionary libraries"; dictPar.type = coral::Option::STRING; secondaryOptions.push_back(dictPar); // coral::Option debugPar("debug"); debugPar.flag = "-debug"; debugPar.helpEntry ="print the debug messages"; debugPar.type = coral::Option::BOOLEAN; secondaryOptions.push_back(debugPar); // std::vector<coral::Command> mainSet; // coral::Command listCont("list_containers"); listCont.flag = "-list"; listCont.helpEntry = "listing the available containers"; listCont.type = coral::Option::BOOLEAN; listCont.exclusive = true; listCont.addOption(csPar.name); listCont.addOption(authPar.name); listCont.addOption(debugPar.name); mainSet.push_back(listCont); // coral::Command createCont("create"); createCont.flag = "-create"; createCont.helpEntry = "create a database or a container"; createCont.type = coral::Option::BOOLEAN; createCont.exclusive = true; createCont.addOption(csPar.name); createCont.addOption(contPar.name); createCont.addOption(classPar.name); createCont.addOption(dictPar.name); createCont.addOption(authPar.name); createCont.addOption(debugPar.name); mainSet.push_back(createCont); // coral::Command eraseCont("erase"); eraseCont.flag = "-erase"; eraseCont.helpEntry = "erase a database or a container"; eraseCont.type = coral::Option::BOOLEAN; eraseCont.exclusive = true; eraseCont.addOption(csPar.name); eraseCont.addOption(contPar.name); eraseCont.addOption(authPar.name); eraseCont.addOption(debugPar.name); mainSet.push_back(eraseCont); // coral::Command listMapp("list_mappings"); listMapp.flag = "-lm"; listMapp.helpEntry = "listing the available mapping versions"; listMapp.type = coral::Option::BOOLEAN; listMapp.exclusive = true; listMapp.addOption(csPar.name); listMapp.addOption(contPar.name); listMapp.addOption(cvPar.name); listMapp.addOption(authPar.name); listMapp.addOption(debugPar.name); mainSet.push_back(listMapp); // coral::Command dumpMapp("dump_mapping"); dumpMapp.flag = "-dm"; dumpMapp.helpEntry = "dump the specified mapping in xml format"; dumpMapp.type = coral::Option::BOOLEAN; dumpMapp.exclusive = true; dumpMapp.addOption(csPar.name); dumpMapp.addOption(mvPar.name); dumpMapp.addOption(outPar.name); dumpMapp.addOption(authPar.name); dumpMapp.addOption(debugPar.name); mainSet.push_back(dumpMapp); // try{ edmplugin::PluginManager::Config config; edmplugin::PluginManager::configure(edmplugin::standard::config()); std::vector<edm::ParameterSet> psets; edm::ParameterSet pSet; pSet.addParameter("@service_type",std::string("SiteLocalConfigService")); psets.push_back(pSet); static const edm::ServiceToken services(edm::ServiceRegistry::createSet(psets)); static const edm::ServiceRegistry::Operate operate(services); std::string connectionString(""); std::string authenticationPath("CORAL_AUTH_PATH="); std::string containerName(""); std::string mappingVersion(""); std::string fileName(""); std::string className(""); std::string dictionary(""); bool withClassVersion = false; bool debug = false; coral::CommandLine cmd(secondaryOptions,mainSet); cmd.parse(argc,argv); const std::map<std::string,std::string>& ops = cmd.userOptions(); if(cmd.userCommand()==coral::CommandLine::helpOption().name || ops.size()==0){ cmd.help(std::cout); return 0; } else { std::map<std::string,std::string>::const_iterator iO=ops.find(coral::CommandLine::helpOption().name); if(iO!=ops.end()){ cmd.help(cmd.userCommand(),std::cout); return 0; } else { iO = ops.find(csPar.name); if(iO!=ops.end()) { connectionString = iO->second; } else { throw coral::MissingRequiredOptionException(csPar.name); } iO = ops.find(contPar.name); if(iO!=ops.end()) containerName = iO->second; iO = ops.find(mvPar.name); if(iO!=ops.end()) mappingVersion = iO->second; iO = ops.find(authPar.name); if(iO!=ops.end()) { authenticationPath.append(iO->second); ::putenv( (char*)authenticationPath.c_str() ); } iO = ops.find(outPar.name); if(iO!=ops.end()) fileName = iO->second; iO = ops.find(classPar.name); if(iO!=ops.end()) className = iO->second; iO = ops.find(dictPar.name); if(iO!=ops.end()) dictionary = iO->second; iO = ops.find(cvPar.name); if(iO!=ops.end()) withClassVersion = true; iO = ops.find(debugPar.name); if(iO!=ops.end()) debug = true; boost::shared_ptr<ora::ConnectionPool> connection( new ora::ConnectionPool ); connection->configuration().disablePoolAutomaticCleanUp(); ora::Database db( connection ); if( debug ) db.configuration().setMessageVerbosity( coral::Debug ); std::string contTag("container.name"); std::string classTag("type"); std::string nobjTag("n.objects"); std::string mapVerTag("mapping.id"); std::string classVerTag("class.version"); std::string space(" "); size_t contMax = contTag.length(); size_t classMax = classTag.length(); size_t nobjMax = nobjTag.length(); size_t mapVerMax = mapVerTag.length(); size_t classVerMax = classVerTag.length(); if(cmd.userCommand()==listCont.name){ db.connect( connectionString, true ); ora::ScopedTransaction transaction( db.transaction() ); transaction.start(); if( ! db.exists() ){ std::cout << "ORA database does not exists in \""<<connectionString<<"\"."<<std::endl; return 0; } std::set<std::string> conts = db.containers(); std::cout << "ORA database in \""<<connectionString<<"\" has "<<conts.size()<<" container(s)."<<std::endl; std::cout <<std::endl; if( conts.size() ){ // first find the max lenghts for(std::set<std::string>::const_iterator iC = conts.begin(); iC != conts.end(); ++iC ){ ora::Container cont = db.containerHandle( *iC ); if(cont.name().length()>contMax ) contMax = cont.name().length(); if(cont.className().length()>classMax ) classMax = cont.className().length(); } std::cout << std::setiosflags(std::ios_base::left); std::cout <<space<<std::setw(contMax)<<contTag; std::cout <<space<<std::setw(classMax)<<classTag; std::cout <<space<<std::setw(nobjMax)<<nobjTag; std::cout <<std::endl; std::cout <<space<<std::setfill('-'); std::cout<<std::setw(contMax)<<""; std::cout <<space<<std::setw(classMax)<<""; std::cout <<space<<std::setw(nobjMax)<<""; std::cout <<std::endl; std::cout << std::setfill(' '); for(std::set<std::string>::const_iterator iC = conts.begin(); iC != conts.end(); ++iC ){ ora::Container cont = db.containerHandle( *iC ); std::cout <<space<<std::setw(contMax)<<cont.name(); std::cout <<space<<std::setw(classMax)<<cont.className(); std::stringstream ss; ss << std::setiosflags(std::ios_base::right); ss <<space<<std::setw(nobjMax)<<cont.size(); std::cout << ss.str(); std::cout <<std::endl; } } transaction.commit(); return 0; } if(cmd.userCommand()==createCont.name){ db.connect( connectionString ); ora::ScopedTransaction transaction( db.transaction() ); transaction.start(false); if( className.empty() ){ throw coral::MissingRequiredOptionException(classPar.name); } if( !dictionary.empty() ){ ora::SharedLibraryName libName; edmplugin::SharedLibrary shared( libName(dictionary) ); } if( !db.exists() ){ db.create(); } else { std::set<std::string> conts = db.containers(); if( conts.find( containerName )!=conts.end() ){ std::cout << "ERROR: container \"" << containerName << "\" already exists in the database."<<std::endl; return -1; } } db.createContainer( className, containerName ); transaction.commit(); return 0; } if(cmd.userCommand()==eraseCont.name){ db.connect( connectionString ); ora::ScopedTransaction transaction( db.transaction() ); transaction.start(false); if( containerName.empty() ){ throw coral::MissingRequiredOptionException(contPar.name); } if( !db.exists() ){ std::cout << "ERROR: ORA database does not exist."<<std::endl; return -1; } else { std::set<std::string> conts = db.containers(); if( conts.find( containerName )==conts.end() ){ std::cout << "ERROR: container \"" << containerName << "\" does not exists in the database."<<std::endl; return -1; } db.dropContainer( containerName ); transaction.commit(); return 0; } } if(cmd.userCommand()==listMapp.name){ db.connect( connectionString, true ); ora::ScopedTransaction transaction( db.transaction() ); transaction.start(); if( containerName.empty() ){ throw coral::MissingRequiredOptionException(contPar.name); } if( !db.exists() ){ std::cout << "ERROR: ORA database does not exist."<<std::endl; return -1; } else { ora::DatabaseUtility util = db.utility(); if(withClassVersion){ std::map<std::string,std::string> vers = util.listMappings( containerName ); std::cout << "ORA database in \""<<connectionString<<"\" has "<<vers.size()<<" class version(s) for container \""<<containerName<<"\"."<<std::endl; std::cout <<std::endl; if( vers.size() ){ // first find the max lenghts for( std::map<std::string,std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){ if( iM->first.length() > classVerMax ) classVerMax = iM->first.length(); if( iM->second.length() > mapVerMax ) mapVerMax = iM->second.length(); } std::cout << std::setiosflags(std::ios_base::left); std::cout <<space<<std::setw(classVerMax)<<classVerTag; std::cout <<space<<std::setw(mapVerMax)<<mapVerTag; std::cout <<std::endl; std::cout <<space<<std::setfill('-'); std::cout<<std::setw(classVerMax)<<""; std::cout <<space<<std::setw(mapVerMax)<<""; std::cout <<std::endl; std::cout << std::setfill(' '); for( std::map<std::string,std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){ std::cout <<space<<std::setw(classVerMax)<<iM->first; std::cout <<space<<std::setw(mapVerMax)<<iM->second; std::cout <<std::endl; } } } else { std::set<std::string> vers = util.listMappingVersions( containerName ); std::cout << "ORA database in \""<<connectionString<<"\" has "<<vers.size()<<" mapping version(s) for container \""<<containerName<<"\"."<<std::endl; std::cout <<std::endl; if( vers.size() ){ // first find the max lenghts for( std::set<std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){ if( iM->length() > mapVerMax ) mapVerMax = iM->length(); } std::cout << std::setiosflags(std::ios_base::left); std::cout <<space<<std::setw(mapVerMax)<<mapVerTag; std::cout <<std::endl; std::cout <<space<<std::setfill('-'); std::cout <<std::setw(mapVerMax)<<""; std::cout <<std::endl; std::cout << std::setfill(' '); for( std::set<std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){ std::cout <<space<<std::setw(mapVerMax)<<*iM; std::cout <<std::endl; } } } transaction.commit(); return 0; } } if(cmd.userCommand()==dumpMapp.name){ db.connect( connectionString, true ); ora::ScopedTransaction transaction( db.transaction() ); transaction.start(); if( mappingVersion.empty() ){ throw coral::MissingRequiredOptionException(mvPar.name); } if( !db.exists() ){ std::cout << "ERROR: ORA database does not exist."<<std::endl; return -1; } else { ora::DatabaseUtility util = db.utility(); std::auto_ptr<std::fstream> file; std::ostream* outputStream = &std::cout; if( !fileName.empty() ){ file.reset(new std::fstream); file->open( fileName.c_str(),std::fstream::out ); outputStream = file.get(); } bool dump = util.dumpMapping( mappingVersion, *outputStream ); if(!dump){ std::cout << "Mapping with id=\""<<mappingVersion<<"\" has not been found in the database."<<std::endl; } if( !fileName.empty() ){ if( dump ) std::cout << "Mapping with id=\""<<mappingVersion<<"\" dumped in file =\""<<fileName<<"\""<<std::endl; file->close(); } transaction.commit(); return 0; } } } } } catch (const std::exception& e){ std::cout << "ERROR: " << e.what() << std::endl; return -1; } catch (...){ std::cout << "UNEXPECTED FAILURE." << std::endl; return -1; } }