String fields = po.getFieldList();
String orderBy = "";
fields = fields.replace("|", ",");
Extent ext = new Extent();
double raio = radius * 9.7125097125097125097125097125097e-6;
ext.setXMin(point.getX() - raio);
ext.setXMax(point.getX() + raio);
ext.setYMin(point.getY() + raio);
ext.setYMax(point.getY() - raio);
if (fields.split(Pattern.quote(",")).length > 0)
orderBy = " , " + fields.split(Pattern.quote(","))[0];
if (whereClause[0] != "")
whereClause[0] = "and " + whereClause[0];
strSelect = "select count(1) as total from dados_clientes." + tb[i] + " where x<>0 and ((x>=" + ext.getXMin() + " and x<=" + ext.getXMax() + ") and (y>=" + ext.getYMin() + " and y<="
+ ext.getYMax() + "))" + whereClause[0];
Connection con = dataBase.getConnection("DADOS_WEBSERVICES");
Statement st = con.createStatement();
ResultSet rr = st.executeQuery(strSelect.toUpperCase());
rr.next();
int nrReg = rr.getInt("total");
rr.close();
st.close();
con.close();
if (po.getResultRange().getRecordsPerPage() > 50)
po.getResultRange().setRecordsPerPage(50);
if (po.getResultRange().getRecordsPerPage() < 1)
po.getResultRange().setRecordsPerPage(5);
Pagination pg = Functions.definePage(nrReg, po.getResultRange().getRecordsPerPage(), po.getResultRange().getPageIndex());
strSelect = "select tabela, x, y, 102960 * SQRT(POWER(x - " + point.getX() + ",2) + POWER(y - " + point.getY() + ",2)) as distancia, " + fields + " from dados_clientes." + tb[i]
+ " where x<>0 and ((x>=" + ext.getXMin() + " and x<=" + ext.getXMax() + ") and (y>=" + ext.getYMin() + " and y<=" + ext.getYMax() + "))" + whereClause[0] + " order by distancia "
+ orderBy + " LIMIT " + (pg.getRecordsInitial() - 1) + "," + (pg.getRecordsFinal());
con = dataBase.getConnection("DADOS_WEBSERVICES");
st = con.createStatement();