android - Only get 1st element of TABLE in SQLite -
i have code:
public linkedlist<product> getallproduct(string idtask){ linkedlist<product> products = new linkedlist<product>(); cursor localcursor = this.getwritabledatabase().rawquery("select * "+table_product+" "+key_id_product_task+"='"+idtask+"'", null); product product; if (localcursor.movetofirst()) { product = new product(); product.setkey_id_unique_product(localcursor.getstring(0)); product.setkey_id_product_task(localcursor.getstring(1)); product.setkey_id_product(localcursor.getstring(2)); product.setkey_name_product(localcursor.getstring(3)); product.setkey_qty_product(localcursor.getstring(4)); product.setkey_size_product(localcursor.getstring(5)); products.add(product); } while (localcursor.movetonext()); return products; }
i 1 row, when particular idtasks, have 2 elements. please me, don't know whats problem. because, when debugging add 2 products idtask in table product, when try these products idtask, first.
here code add products int table product
public void addproduct(product product) { sqlitedatabase localsqlitedatabase = getwritabledatabase(); contentvalues localcontentvalues = new contentvalues(); if (!isexistidproduct(product.getkey_id_product())){ localcontentvalues.put(key_id_product_task, product.getkey_id_product_task()); localcontentvalues.put(key_id_product, product.getkey_id_product()); localcontentvalues.put(key_name_product, product.getkey_name_product()); localcontentvalues.put(key_qty_product, product.getkey_qty_product()); localcontentvalues.put(key_size_product, product.getkey_size_product()); localsqlitedatabase.insert(table_product, null, localcontentvalues); } }
if using test data reuses same product ids, following test preventing adding second row:
if (!isexistidproduct(product.getkey_id_product()))
Comments
Post a Comment