00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "../../src/terralib/drivers/MySQL/TeMySQL.h"
00031 #include "../../src/terralib/kernel/TeQuerier.h"
00032 #include "../../src/terralib/kernel/TeQuerierParams.h"
00033
00034 #include <time.h>
00035 #include <iostream>
00036
00037 using std::cout;
00038
00039 int
00040 main()
00041 {
00042
00043
00044 string host = "localhost";
00045 string dbname = "saudavel";
00046 string user = "root";
00047 string pass = "karine";
00048
00049
00050 TeDatabase* db_ = new TeMySQL();
00051 if (!db_->connect(host,user,pass,dbname))
00052 {
00053 cout << "Error: " << db_->errorMessage() << endl;
00054 return 1;
00055 }
00056
00057
00058 TeTheme* coletas = new TeTheme("Coletas");
00059 if (!db_->loadTheme(coletas))
00060 {
00061 cout << "Error: " << db_->errorMessage() << endl;
00062 db_->close();
00063 return 1;
00064 }
00065
00066
00067 bool loadGeometries = false;
00068 TeGroupingAttr attributes;
00069
00070 pair<TeAttributeRep, TeStatisticType> attr1(TeAttributeRep("Coletas.NRO_OVOS_PAL1"), TeSUM);
00071 attributes.push_back(attr1);
00072
00073 pair<TeAttributeRep, TeStatisticType> attr2(TeAttributeRep("Coletas.NRO_OVOS_PAL2"), TeSUM);
00074 attributes.push_back(attr2);
00075
00076 pair<TeAttributeRep, TeStatisticType> attr3(TeAttributeRep("Coletas.NRO_OVOS_PAL3"), TeSUM);
00077 attributes.push_back(attr3);
00078
00079 pair<TeAttributeRep, TeStatisticType> attr4(TeAttributeRep("Coletas.NRO_OVOS"), TeSUM);
00080 attributes.push_back(attr4);
00081
00082
00083 TeQuerierParams querierParams(loadGeometries, attributes);
00084 querierParams.setParams(coletas, TeMONTH);
00085
00086 TeQuerier querier(querierParams);
00087
00088
00089 int numTimeFrames = querier.getNumTimeFrames();
00090
00091
00092 for(int frame=0; frame < numTimeFrames; ++frame)
00093 {
00094 TeTSEntry ts;
00095 querier.getTSEntry(ts, frame);
00096
00097 cout << " Time frame: " << Te2String(frame) << " --------------------------- " << endl << endl;
00098
00099 string initialDate = ts.time_.getInitialDateTime("DDsMMsYYYY");
00100 string finalDate = ts.time_.getFinalDateTime("DDsMMsYYYY");
00101
00102 cout << " Time Interval: " << initialDate << " to " << finalDate << endl << endl;
00103
00104
00105 if(!querier.loadInstances(frame))
00106 continue;
00107
00108
00109 TeSTInstance sti;
00110 while(querier.fetchInstance(sti))
00111 {
00112 cout << " Object: " << sti.objectId() << endl;
00113
00114
00115 TePropertyVector vec = sti.getPropertyVector();
00116 for(unsigned int i=0; i<vec.size(); ++i)
00117 {
00118 string attrName = vec[i].attr_.rep_.name_;
00119 string attrValue = vec[i].value_;
00120
00121 cout << attrName << " : " << attrValue << endl;
00122
00123 }
00124 }
00125
00126 cout << endl << endl;
00127 }
00128
00129 cout << " End " << endl;
00130 getchar();
00131 db_->close ();
00132 return 0;
00133 }
00134
00135
00136
00137