Ejemplo n.º 1
0
  public List<Tel_text> queryTel_text(String phonenum) {
    if (phonenum.startsWith("0")) {
      phonenum = phonenum.substring(phonenum.indexOf("0"));
    }

    List<Tel_text> ltt = new ArrayList<Tel_text>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor count =
        db.rawQuery(
            "select count(*) c from (SELECT tel,GROUP_CONCAT(text,'\r\n') text from tel_text where tel LIKE ? GROUP BY tel)",
            new String[] {"%" + phonenum + "%"});
    int c = 0;
    if (count.moveToNext()) {
      c = count.getInt(count.getColumnIndex("c"));
    }
    count.close();
    if (c <= 150) {
      Cursor cursor =
          db.rawQuery(
              "SELECT tel,GROUP_CONCAT(text,'\r\n') text from tel_text where tel LIKE ? GROUP BY tel ORDER BY serial,tel",
              new String[] {"%" + phonenum + "%"});
      Log.i("Tel_query", phonenum);
      while (cursor.moveToNext()) {
        Tel_text tt = new Tel_text();
        tt.setTel(cursor.getString(cursor.getColumnIndex("tel")));
        tt.setText(cursor.getString(cursor.getColumnIndex("text")));
        ltt.add(tt);
      }
      cursor.close();
    }

    return ltt;
  }
Ejemplo n.º 2
0
 public void saveTel_texts(List<Tel_text> lst) {
   SQLiteDatabase db = null;
   try {
     db = this.getWritableDatabase();
     db.beginTransaction();
     db.execSQL("delete from tel_text");
     for (Tel_text tt : lst) {
       Log.i("Tel_text", tt.getTel() + "--" + tt.getText());
       db.execSQL(
           "insert into tel_text(tel,text,serial) values (?,?,?)",
           new String[] {tt.getTel(), tt.getText(), tt.getSerial()});
     }
     db.setTransactionSuccessful();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } finally {
     db.endTransaction();
   }
 }