sqlite & ArrayList 2.0 array just repeats the last record all the way through
in
Contributed Library Questions
•
1 year ago
Hi there, im reading from a pretty simple database and all works fine except when i want to populate an arraylist with the records, for some reason it just keeps the last records of the loop. Can anybody see if im doing something wrong? Here's the code: thanks!
- import de.bezier.data.sql.*;
- SQLite db;
- Vertexgroup[] vgList=new Vertexgroup[0];
- void setup(){
- size(400,400);
- db = new SQLite( this, "data/sevilla_price_map.db" );
- prepareVG();
- for(int i=0;i<vgList.length;i++){
- println(vgList[i].data.size());
- for(int j=0;j<vgList[i].data.size();j++){
- Float x=vgList[i].data.get(j);
- println(x);
- }
- }
- }
- void prepareVG() {
- int idlocalprev=0;
- float coordx;
- String idname;
- ArrayList<Float> data=new ArrayList();
- if ( db.connect() ) {
- db.query("SELECT * FROM base_cartography LIMIT 2000");
- while (db.next()) {
- idname=db.getString("idname");
- coordx=db.getFloat("coordx");
- int idlocal=db.getInt("idlocal");
- data.add(coordx);
- if(idlocal<=idlocalprev){
- Vertexgroup v=new Vertexgroup(idname, coordx, data);
- vgList=(Vertexgroup[]) append(vgList, v);
- data.clear();
- }
- idlocalprev=idlocal;
- }
- }
- db.close();
- }
- class Vertexgroup{
- ArrayList<Float> data;
- String idname;
- float coordx;
- Vertexgroup(String _idname, float _coordx, ArrayList<Float> _data){
- idname=_idname;
- coordx=_coordx;
- data=_data;
- }
- }
1