vector<MaintenanceContainer> SqlInterface::getMaintenanceData(){ ResultSet *rset; MaintenanceContainer mContainer; int temp2 = 0; string query = "select * from maintenance"; vector<MaintenanceContainer> vContainer; if(this == 0 || this == NULL) return vContainer; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); mContainer.setCarId(temp2); break; case 1: mContainer.setDamages(temp); break; case 2: temp2 = atoi(temp.c_str()); mContainer.setCosts(temp2); break; case 3: mContainer.setStartDate(temp); break; case 4: mContainer.setFinishDate(temp); break; } } vContainer.push_back(mContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
int BillingInstance::queryStaticIP(std::string ip, std::string server, queryResult &_rv) { if(_conn == NULL) { return 0; } int retval = 0; Statement *sth = NULL; try { sth = _conn->createStatement(QUERY_STATIC_IP); sth->setAutoCommit(true); sth->setString(1, ip); sth->setString(2, server); std::cerr << "Query execute" << std::endl; ResultSet *rs = sth->executeQuery(); const std::vector<MetaData> md = rs->getColumnListMetaData(); if(rs) { while( rs->next() ) { std::multimap<std::string, std::string> tmp; tmp.clear(); for(int i=0; i < md.size(); ++i) { tmp.insert(std::pair<std::string, std::string>(md.at(i).getString(MetaData::ATTR_NAME), rs->getString(i+1))); } _rv.push_back(tmp); } } sth->closeResultSet(rs); retval = 0; } catch (SQLException &sqlExcp) { std::cerr <<sqlExcp.getErrorCode() << " at " << __FILE__ << "/" << __LINE__ << ": " << sqlExcp.getMessage() << std::endl; retval = sqlExcp.getErrorCode(); } if(sth != NULL) { try { _conn->terminateStatement(sth); } catch (SQLException &sqlExcp) { std::cerr <<sqlExcp.getErrorCode() << " at " << __FILE__ << "/" << __LINE__ << ": " << sqlExcp.getMessage() << std::endl; retval = sqlExcp.getErrorCode(); } } return retval; }
vector<SalesContainer> SqlInterface::getSalesData(){ ResultSet *rset; SalesContainer sContainer; int temp2 = 0; string query = "select * from sales"; vector<SalesContainer> vContainer; if(this == 0 || this == NULL) return vContainer; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); sContainer.setCarId(temp2); break; case 1: sContainer.setAvailability(temp); break; case 2: sContainer.setDeliveryDate(temp); break; case 3: temp2 = atoi(temp.c_str()); sContainer.setCost(temp2); break; case 4: sContainer.setDateSold(temp); break; case 5: sContainer.setFirstName(temp); break; case 6: sContainer.setLastName(temp); break; case 7: sContainer.setMake(temp); break; case 8: sContainer.setModel(temp); break; } } vContainer.push_back(sContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
vector<CarContainer> SqlInterface::getCarData(){ ResultSet *rset; CarContainer cContainer; int temp2 = 0; vector<CarContainer> vContainer; string query = "select * from cars"; if(this == 0 || this == NULL) return vContainer; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); cContainer.setCarId(temp2); break; case 1: cContainer.setPerformance(temp); break; case 2: cContainer.setHandeling(temp); break; case 3: cContainer.setInstrumentation(temp); break; case 4: cContainer.setSafetySecurity(temp); break; case 5: cContainer.setDesign(temp); break; case 6: cContainer.setAudio(temp); break; case 7: cContainer.setComfort(temp); break; case 8: cContainer.setMaintenance(temp); break; case 9: cContainer.setWarranty(temp); break; case 10: cContainer.setPackages(temp); break; case 11: cContainer.setMake(temp); break; case 12: cContainer.setModel(temp); break; } } vContainer.push_back(cContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
vector<CustomerContainer> SqlInterface::getCustomerData(){ ResultSet *rset; CustomerContainer cContainer; int temp2 = 0; vector<CustomerContainer> vContainer; string query = "select * from customers"; if(this == 0 || this == NULL) return vContainer; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); cContainer.setCarId(temp2); break; case 1: cContainer.setFirstName(temp); break; case 2: cContainer.setLastName(temp); break; case 3: cContainer.setAddress(temp); break; case 4: cContainer.setState(temp); break; case 5:temp2 = atoi(temp.c_str()); cContainer.setZip(temp2); break; case 6: cContainer.setDeliveryDate(temp); break; case 7: cContainer.setScheduledMaintenance(temp); break; case 8: cContainer.setUnscheduledRepairs(temp); break; } } vContainer.push_back(cContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
vector<MaintenanceContainer> SqlInterface::searchMaintenanceData(MaintenanceContainer container){ ResultSet *rset; vector<MaintenanceContainer> vContainer; int temp2 = 0; string query = "select * from Maintenance where "; string buffer1; string buffer2; bool firstValue = true; if(container.getCarId() != 0){ stringstream ss; ss << container.getCarId(); buffer1 = ss.str(); if(firstValue == false) query = query + "and "; query = query + "car_id=" + buffer1 + " "; firstValue = false; } if(strcmp(container.getDamages().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "damages='" + container.getDamages() + "' "; firstValue = false; } if(container.getCost() != 0){ stringstream ss2; ss2 << container.getCost(); buffer2 = ss2.str(); if(firstValue == false) query = query + "and "; query = query + "costs=" + buffer2 + " "; firstValue = false; } if(strcmp(container.getStartDate().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "start_date='" + container.getStartDate() + "' "; firstValue = false; } if(strcmp(container.getFinishDate().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "completion_date='" + container.getFinishDate() + "' "; firstValue = false; } if(firstValue == true) query = "select * from Sales where car_id=0"; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ MaintenanceContainer mContainer; for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); mContainer.setCarId(temp2); break; case 1: mContainer.setDamages(temp); break; case 2: temp2 = atoi(temp.c_str()); mContainer.setCosts(temp2); break; case 3: mContainer.setStartDate(temp); break; case 4: mContainer.setFinishDate(temp); break; } } vContainer.push_back(mContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
vector<CarContainer> SqlInterface::searchCarData(CarContainer container){ ResultSet *rset; int temp2 = 0; string query = "select * from Cars where "; string buffer1; bool firstValue = true; vector<CarContainer> vContainer; if(container.getCarId() != 0){ stringstream ss; ss << container.getCarId(); buffer1 = ss.str(); if(firstValue == false) query = query + "and "; query = query + "car_id=" + buffer1 + " "; firstValue = false; } if(strcmp(container.getMake().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "make='" + container.getMake() + "' "; firstValue = false; } if(strcmp(container.getModel().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "model='" + container.getModel() + "' "; firstValue = false; } if(strcmp(container.getPerformance().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "performance='" + container.getPerformance() + "' "; firstValue = false; } if(strcmp(container.getHandeling().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "handling='" + container.getHandeling() + "' "; firstValue = false; } if(strcmp(container.getInstrumentation().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "instrumentation='" + container.getInstrumentation() + "' "; firstValue = false; } if(strcmp(container.getSafetySecurity().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "safety_security='" + container.getSafetySecurity() + "' "; firstValue = false; } if(strcmp(container.getDesign().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "design='" + container.getDesign() + "' "; firstValue = false; } if(strcmp(container.getAudio().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "audio='" + container.getAudio() + "' "; firstValue = false; } if(strcmp(container.getComfort().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "comfort='" + container.getComfort() + "' "; firstValue = false; } if(strcmp(container.getMaintenance().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "maintenance='" + container.getMaintenance() + "' "; firstValue = false; } if(strcmp(container.getWarranty().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "warranty='" + container.getWarranty() + "' "; firstValue = false; } if(strcmp(container.getPackages().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "packages='" + container.getPackages() + "' "; firstValue = false; } if(firstValue == true) query = "select * from Sales where car_id=0"; cout << query << endl; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ CarContainer cContainer; for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); cContainer.setCarId(temp2); break; case 1: cContainer.setPerformance(temp); break; case 2: cContainer.setHandeling(temp); break; case 3: cContainer.setInstrumentation(temp); break; case 4: cContainer.setSafetySecurity(temp); break; case 5: cContainer.setDesign(temp); break; case 6: cContainer.setAudio(temp); break; case 7: cContainer.setComfort(temp); break; case 8: cContainer.setMaintenance(temp); break; case 9: cContainer.setWarranty(temp); break; case 10: cContainer.setPackages(temp); break; case 11: cContainer.setMake(temp); break; case 12: cContainer.setModel(temp); break; } } vContainer.push_back(cContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
vector<CustomerContainer> SqlInterface::searchCustomerData(CustomerContainer container){ ResultSet *rset; int temp2 = 0; vector<CustomerContainer> vContainer; string query = "select * from Customers where "; string buffer1; string buffer2; bool firstValue = true; if(container.getCarId() != 0){ stringstream ss; ss << container.getCarId(); buffer1 = ss.str(); if(firstValue == false) query = query + "and "; query = query + "car_id=" + buffer1 + " "; firstValue = false; } if(strcmp(container.getFirstName().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "first_name='" + container.getFirstName() + "' "; firstValue = false; } if(strcmp(container.getLastName().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "last_name='" + container.getLastName() + "' "; firstValue = false; } if(container.getZip() != 0){ stringstream ss2; ss2 << container.getZip(); buffer2 = ss2.str(); if(firstValue == false) query = query + "and "; query = query + "zip=" + buffer2 + " "; firstValue = false; } if(strcmp(container.getAddress().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "address='" + container.getAddress() + "' "; firstValue = false; } if(strcmp(container.getState().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "state='" + container.getState() + "' "; firstValue = false; } if(strcmp(container.getDeliveryDate().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "delivery_date='" + container.getDeliveryDate() + "' "; firstValue = false; } if(strcmp(container.getScheduledMaintenance().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "scheduled_maintenance='" + container.getScheduledMaintenance() + "' "; firstValue = false; } if(strcmp(container.getUnscheduledRepairs().c_str(), "") != 0){ if(firstValue == false) query = query + "and "; query = query + "unscheduled_repairs='" + container.getUnscheduledRepairs() + "' "; firstValue = false; } if(firstValue == true) query = "select * from Sales where car_id=0"; stmt = conn->createStatement(query); try{ rset = stmt->executeQuery(); } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } vector<MetaData> data = rset->getColumnListMetaData(); try{ while(rset->next()){ CustomerContainer cContainer; for(unsigned int i = 0; i < data.size(); i++){ temp = rset->getString(i+1); switch(i) { case 0: temp2 = atoi(temp.c_str()); cContainer.setCarId(temp2); break; case 1: cContainer.setFirstName(temp); break; case 2: cContainer.setLastName(temp); break; case 3: cContainer.setAddress(temp); break; case 4: cContainer.setState(temp); break; case 5:temp2 = atoi(temp.c_str()); cContainer.setZip(temp2); break; case 6: cContainer.setDeliveryDate(temp); break; case 7: cContainer.setScheduledMaintenance(temp); break; case 8: cContainer.setUnscheduledRepairs(temp); break; } } vContainer.push_back(cContainer); } } catch(SQLException ex){ cout<<"Exception thrown for select"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; } stmt->closeResultSet (rset); conn->terminateStatement (stmt); return vContainer; }
void occi_datasource::bind() const { if (is_bound_) return; #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::bind"); #endif // connect to environment if (use_connection_pool_) { try { Environment* env = occi_environment::get_environment(); pool_ = env->createStatelessConnectionPool( *params_.get<std::string>("user"), *params_.get<std::string>("password"), *params_.get<std::string>("host"), *params_.get<int>("max_size", 5), *params_.get<int>("initial_size", 1), 1, StatelessConnectionPool::HOMOGENEOUS); } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } else { try { Environment* env = occi_environment::get_environment(); conn_ = env->createConnection( *params_.get<std::string>("user"), *params_.get<std::string>("password"), *params_.get<std::string>("host")); } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } // extract real table name table_name_ = mapnik::sql_utils::table_from_sql(table_); // get SRID and/or GEOMETRY_FIELD from metadata table only if we need to if (! srid_initialized_ || geometry_field_ == "") { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_srid_and_geometry_field"); #endif std::ostringstream s; s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE"; s << " LOWER(table_name) = LOWER('" << table_name_ << "')"; if (geometry_field_ != "") { s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; } MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str(); try { occi_connection_ptr conn; if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); ResultSet* rs = conn.execute_query(s.str()); if (rs && rs->next ()) { if (! srid_initialized_) { srid_ = rs->getInt(1); srid_initialized_ = true; } if (geometry_field_ == "") { geometry_field_ = rs->getString(2); } } } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } // get columns description { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_column_description"); #endif std::ostringstream s; s << "SELECT " << fields_ << " FROM (" << table_name_ << ") WHERE rownum < 1"; MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str(); try { occi_connection_ptr conn; if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); ResultSet* rs = conn.execute_query(s.str()); if (rs) { std::vector<MetaData> listOfColumns = rs->getColumnListMetaData(); for (unsigned int i = 0; i < listOfColumns.size(); ++i) { MetaData columnObj = listOfColumns[i]; std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); /* int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); if (type_code == OCCI_TYPECODE_OBJECT) { desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); continue; } */ switch (type_oid) { case oracle::occi::OCCIBOOL: case oracle::occi::OCCIINT: case oracle::occi::OCCIUNSIGNED_INT: case oracle::occi::OCCIROWID: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer)); break; case oracle::occi::OCCIFLOAT: case oracle::occi::OCCIBFLOAT: case oracle::occi::OCCIDOUBLE: case oracle::occi::OCCIBDOUBLE: case oracle::occi::OCCINUMBER: case oracle::occi::OCCI_SQLT_NUM: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); break; case oracle::occi::OCCICHAR: case oracle::occi::OCCISTRING: case oracle::occi::OCCI_SQLT_AFC: case oracle::occi::OCCI_SQLT_AVC: case oracle::occi::OCCI_SQLT_CHR: case oracle::occi::OCCI_SQLT_LVC: case oracle::occi::OCCI_SQLT_RDD: case oracle::occi::OCCI_SQLT_STR: case oracle::occi::OCCI_SQLT_VCS: case oracle::occi::OCCI_SQLT_VNU: case oracle::occi::OCCI_SQLT_VBI: case oracle::occi::OCCI_SQLT_VST: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String)); break; case oracle::occi::OCCIDATE: case oracle::occi::OCCITIMESTAMP: case oracle::occi::OCCIINTERVALDS: case oracle::occi::OCCIINTERVALYM: case oracle::occi::OCCI_SQLT_DAT: case oracle::occi::OCCI_SQLT_DATE: case oracle::occi::OCCI_SQLT_TIME: case oracle::occi::OCCI_SQLT_TIME_TZ: case oracle::occi::OCCI_SQLT_TIMESTAMP: case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: case oracle::occi::OCCI_SQLT_INTERVAL_YM: case oracle::occi::OCCI_SQLT_INTERVAL_DS: case oracle::occi::OCCIANYDATA: case oracle::occi::OCCIBLOB: case oracle::occi::OCCIBFILE: case oracle::occi::OCCIBYTES: case oracle::occi::OCCICLOB: case oracle::occi::OCCIVECTOR: case oracle::occi::OCCIMETADATA: case oracle::occi::OCCIPOBJECT: case oracle::occi::OCCIREF: case oracle::occi::OCCIREFANY: case oracle::occi::OCCISTREAM: case oracle::occi::OCCICURSOR: case oracle::occi::OCCI_SQLT_FILE: case oracle::occi::OCCI_SQLT_CFILE: case oracle::occi::OCCI_SQLT_REF: case oracle::occi::OCCI_SQLT_CLOB: case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_RSET: MAPNIK_LOG_WARN(occi) << "occi_datasource: Unsupported datatype " << occi_enums::resolve_datatype(type_oid) << " (type_oid=" << type_oid << ")"; break; default: MAPNIK_LOG_WARN(occi) << "occi_datasource: Unknown datatype " << "(type_oid=" << type_oid << ")"; break; } } } } catch (SQLException& ex) { throw datasource_exception(ex.getMessage()); } } is_bound_ = true; }
int main(int argc, char **argv) { if (argc != 6) { Usage(); return 0; } bool bPrint = false; if (strcmp(argv[1], "-p") == 0) { bPrint = true; } struct timeval tv_start, tv_end; gettimeofday(&tv_start, NULL); // create Environment Environment *env = Environment::createEnvironment(); if (env == NULL) { cout << "createEnvironment failed!" << endl; return -1; } // use the Environment instance to create connections; Connection *conn = env->createConnection(argv[2], argv[3], argv[4]); if (conn == NULL) { cout << "createConnection failed!" << endl; return -1; } // use Statement to execute sql and get result Statement *stmt = conn->createStatement(argv[5]); if (stmt == NULL) { cout << "createStatement failed!" << endl; return -1; } // execute sql and get result set ResultSet *rs = stmt->executeQuery(); if (rs == NULL) { cout << "executeQuery failed!" << endl; return -1; } // ResultSet::next() fetch rows and return FALSE // when no more rows int nColumns; long long llCount = 0; string strTemp; vector<MetaData> vecColumns = rs->getColumnListMetaData(); nColumns = vecColumns.size(); while (rs->next() == true) { // get values using the getXXX() methods of Resultset for (int i = 0; i < nColumns; ++i) { strTemp = rs->getString(i + 1); if (bPrint) { cout << strTemp << "\t"; } } if (bPrint) { cout << endl; } ++llCount; } // close result stmt->closeResultSet(rs); // close statement conn->terminateStatement(stmt); // close connection env->terminateConnection(conn); // close Environment Environment::terminateEnvironment(env); gettimeofday(&tv_end, NULL); long long llUsed = (tv_end.tv_sec - tv_start.tv_sec) * 1000000 + tv_end.tv_usec - tv_start.tv_usec; cout << "read data " << llCount << " used " << llUsed / 1000000.0 << " sec." << endl; return 0; }
occi_datasource::occi_datasource(parameters const& params) : datasource (params), type_(datasource::Vector), fields_(*params.get<std::string>("fields", "*")), geometry_field_(*params.get<std::string>("geometry_field", "")), srid_initialized_(false), extent_initialized_(false), bbox_token_("!bbox!"), scale_denom_token_("!scale_denominator!"), pixel_width_token_("!pixel_width!"), pixel_height_token_("!pixel_height!"), desc_(occi_datasource::name(), *params.get<std::string>("encoding", "utf-8")), use_wkb_(*params.get<mapnik::boolean_type>("use_wkb", false)), row_limit_(*params.get<mapnik::value_integer>("row_limit", 0)), row_prefetch_(*params.get<mapnik::value_integer>("row_prefetch", 100)), pool_(0), conn_(0) { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::init"); #endif if (! params.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified"); if (! params.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified"); if (! params.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified"); boost::optional<std::string> table = params.get<std::string>("table"); if (! table) { throw datasource_exception("OCCI Plugin: no <table> parameter specified"); } else { table_ = *table; } estimate_extent_ = *params.get<mapnik::boolean_type>("estimate_extent",false); use_spatial_index_ = *params.get<mapnik::boolean_type>("use_spatial_index",true); use_connection_pool_ = *params.get<mapnik::boolean_type>("use_connection_pool",true); boost::optional<std::string> ext = params.get<std::string>("extent"); if (ext) extent_initialized_ = extent_.from_string(*ext); boost::optional<mapnik::value_integer> srid = params.get<mapnik::value_integer>("srid"); if (srid) { srid_ = *srid; srid_initialized_ = true; } // connect to environment if (use_connection_pool_) { try { pool_ = occi_environment::instance().create_pool( *params.get<std::string>("user"), *params.get<std::string>("password"), *params.get<std::string>("host"), *params.get<mapnik::value_integer>("max_size", 5), *params.get<mapnik::value_integer>("initial_size", 1), 1); } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } else { try { conn_ = occi_environment::instance().create_connection( *params.get<std::string>("user"), *params.get<std::string>("password"), *params.get<std::string>("host")); } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } // extract real table name table_name_ = mapnik::sql_utils::table_from_sql(table_); // get SRID and/or GEOMETRY_FIELD from metadata table only if we need to if (! srid_initialized_ || geometry_field_ == "") { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_srid_and_geometry_field"); #endif std::ostringstream s; s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE"; s << " LOWER(table_name) = LOWER('" << table_name_ << "')"; if (geometry_field_ != "") { s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; } MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str(); try { occi_connection_ptr conn; if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); ResultSet* rs = conn.execute_query(s.str()); if (rs && rs->next ()) { if (! srid_initialized_) { srid_ = rs->getInt(1); srid_initialized_ = true; } if (geometry_field_ == "") { geometry_field_ = rs->getString(2); } } } catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } // get columns description { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_column_description"); #endif std::ostringstream s; s << "SELECT " << fields_ << " FROM (" << table_name_ << ") WHERE ROWNUM < 1"; MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str(); try { occi_connection_ptr conn; if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); ResultSet* rs = conn.execute_query(s.str()); if (rs) { std::vector<MetaData> listOfColumns = rs->getColumnListMetaData(); for (unsigned int i = 0; i < listOfColumns.size(); ++i) { MetaData columnObj = listOfColumns[i]; std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); /* int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); if (type_code == OCCI_TYPECODE_OBJECT) { desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); continue; } */ switch (type_oid) { case oracle::occi::OCCIBOOL: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Boolean)); break; case oracle::occi::OCCIINT: case oracle::occi::OCCIUNSIGNED_INT: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer)); break; case oracle::occi::OCCIFLOAT: case oracle::occi::OCCIBFLOAT: case oracle::occi::OCCIDOUBLE: case oracle::occi::OCCIBDOUBLE: case oracle::occi::OCCINUMBER: case oracle::occi::OCCI_SQLT_NUM: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); break; case oracle::occi::OCCICHAR: case oracle::occi::OCCISTRING: case oracle::occi::OCCI_SQLT_AFC: case oracle::occi::OCCI_SQLT_AVC: case oracle::occi::OCCI_SQLT_CHR: case oracle::occi::OCCI_SQLT_LNG: case oracle::occi::OCCI_SQLT_LVC: case oracle::occi::OCCI_SQLT_STR: case oracle::occi::OCCI_SQLT_VCS: case oracle::occi::OCCI_SQLT_VNU: case oracle::occi::OCCI_SQLT_VBI: case oracle::occi::OCCI_SQLT_VST: case oracle::occi::OCCIROWID: case oracle::occi::OCCI_SQLT_RDD: case oracle::occi::OCCI_SQLT_RID: case oracle::occi::OCCIDATE: case oracle::occi::OCCI_SQLT_DAT: case oracle::occi::OCCI_SQLT_DATE: case oracle::occi::OCCI_SQLT_TIME: case oracle::occi::OCCI_SQLT_TIME_TZ: case oracle::occi::OCCITIMESTAMP: case oracle::occi::OCCI_SQLT_TIMESTAMP: case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String)); break; case oracle::occi::OCCIINTERVALDS: case oracle::occi::OCCIINTERVALYM: case oracle::occi::OCCI_SQLT_INTERVAL_YM: case oracle::occi::OCCI_SQLT_INTERVAL_DS: case oracle::occi::OCCIANYDATA: case oracle::occi::OCCIBLOB: case oracle::occi::OCCIBFILE: case oracle::occi::OCCIBYTES: case oracle::occi::OCCICLOB: case oracle::occi::OCCIVECTOR: case oracle::occi::OCCIMETADATA: case oracle::occi::OCCIPOBJECT: case oracle::occi::OCCIREF: case oracle::occi::OCCIREFANY: case oracle::occi::OCCISTREAM: case oracle::occi::OCCICURSOR: case oracle::occi::OCCI_SQLT_FILE: case oracle::occi::OCCI_SQLT_CFILE: case oracle::occi::OCCI_SQLT_REF: case oracle::occi::OCCI_SQLT_CLOB: case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_RSET: MAPNIK_LOG_WARN(occi) << "occi_datasource: Unsupported datatype " << occi_enums::resolve_datatype(type_oid) << " (type_oid=" << type_oid << ")"; break; default: MAPNIK_LOG_WARN(occi) << "occi_datasource: Unknown datatype " << "(type_oid=" << type_oid << ")"; break; } } } } catch (SQLException& ex) { throw datasource_exception(ex.getMessage()); } } }
int _tmain(int argc, _TCHAR* argv[]) { const char* userName = "******"; const char* password = "******"; const char* connectString = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=80.67.144.206)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=XE)))"; const char* sql = "SELECT * FROM ALL_TABLES"; int i = 0; int rows = 0; try { Environment *env = Environment::createEnvironment(Environment::THREADED_MUTEXED); cout << "createEnvironment" << endl; Connection *conn = env->createConnection((char*)userName, (char*)password, (char*)connectString); cout << " createConnection" << endl; for (i=100; i>0; --i) { Statement *stmt = conn->createStatement(sql); cout << " createStatement" << endl; ResultSet *rs = stmt->executeQuery(); cout << " executeQuery" << endl; #if 0 vector<MetaData> listOfColumns = rs->getColumnListMetaData(); cout << " getColumnListMetaData" << endl; cout << i << " columns " << listOfColumns.size() << endl; for (i=0; i < listOfColumns.size(); i++) { MetaData columnObj=listOfColumns[i]; //cout << (columnObj.getString(MetaData::ATTR_NAME)) // << "(" << (columnObj.getInt(MetaData::ATTR_DATA_TYPE)) << "), "; } #endif rows = 0; while(rs->next()) { ++rows; /*for (i=0; i < listOfColumns.size(); i++) string str = rs->getString(i+1); //cout << rs->getString(j+1) << ", "; //cout << endl;*/ } cout << " itr " << i << " rows " << rows << endl; stmt->closeResultSet(rs); cout << " closeResultSet" << endl; conn->terminateStatement(stmt); cout << " terminateStatement" << endl; } env->terminateConnection(conn); cout << " terminateConnection" << endl; Environment::terminateEnvironment(env); cout << "terminateEnvironment" << endl; } catch (std::exception const & ex) { cout << ex.what() << endl; } catch (std::string const & ex) { cout << ex << endl; } catch (...) { // ... } return 0; }