@MediumTest
  public void testCursorUpdate() {
    mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, d INTEGER, s INTEGER);");
    for (int i = 0; i < 20; i++) {
      mDatabase.execSQL("INSERT INTO test (d, s) VALUES (" + i + "," + i % 2 + ");");
    }

    Cursor c = mDatabase.query("test", null, "s = 0", null, null, null, null);
    int dCol = c.getColumnIndexOrThrow("d");
    int sCol = c.getColumnIndexOrThrow("s");

    int count = 0;
    while (c.moveToNext()) {
      assertTrue(c.updateInt(dCol, 3));
      count++;
    }
    assertEquals(10, count);

    assertTrue(c.commitUpdates());

    assertTrue(c.requery());

    count = 0;
    while (c.moveToNext()) {
      assertEquals(3, c.getInt(dCol));
      count++;
    }

    assertEquals(10, count);
    assertTrue(c.moveToFirst());
    assertTrue(c.deleteRow());
    assertEquals(9, c.getCount());
    c.close();
  }
コード例 #2
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    db = new DBHelper(context);
    mContext = context;
    Calendar c = Calendar.getInstance();
    int yy = c.get(Calendar.YEAR);
    int mm = c.get(Calendar.MONTH) + 1;
    int dd = c.get(Calendar.DATE);
    int hh = c.get(Calendar.HOUR_OF_DAY);
    int mn = c.get(Calendar.MINUTE);
    int nw = (hh * 60) + mn;

    Cursor cur = db.getAllTaskByDate(yy, mm, dd);
    if (cur.moveToFirst()) {
      do {
        int tstime = cur.getInt(cur.getColumnIndex("stime"));
        int tstimem = cur.getInt(cur.getColumnIndex("stimem"));
        int tt = (tstime * 60) + tstimem;
        if ((tt - nw) <= 5 && (tt - nw) > 0) {
          String title = cur.getString(cur.getColumnIndex("tname"));
          showNotification(context, 1, title, "Starts at " + tstime + ":" + tstimem);
        }

      } while (cur.moveToNext());
    }
    cur.close();
    if (mm == 0) {
      Cursor lcur = db.getLogin();
      int id = 0;
      if (lcur.moveToFirst()) {
        id = lcur.getInt(lcur.getColumnIndex("uid"));
      }
      lcur.close();
      Cursor mcur = db.getTaskByPendingSync();

      if (mcur.moveToFirst()) {
        do {
          int tid = mcur.getInt(mcur.getColumnIndex("tid"));
          int rating = mcur.getInt(mcur.getColumnIndex("rating"));
          String feedback = mcur.getString(mcur.getColumnIndex("feedback"));
          if (isNetworkAvailable() && id != 0) {
            new RequestTask()
                .execute(
                    context.getResources().getString(R.string.server)
                        + "services/feedbackcollector.php?"
                        + "id="
                        + id
                        + "&tid="
                        + tid
                        + "&rating="
                        + rating
                        + "&feedback="
                        + feedback);
          }
        } while (mcur.moveToNext());
      }
      mcur.close();
    }
  }
コード例 #3
0
  public List<EdificioMOD> getEdificioListbyTipoSitio(String Nombre) {
    List<EdificioMOD> lista = new ArrayList<EdificioMOD>();
    EdificioMOD _edificioMOD;
    String Idcampus = "";

    String sql1 = "select idEdificio from sitio where tipo='" + Nombre + "'";
    Cursor ccc = database.rawQuery(sql1, null);
    if (ccc.moveToFirst()) {

      do {
        Idcampus = ccc.getString(0);

        String sql =
            "select nombreEdificio from edificio where idEdificio ='"
                + Idcampus
                + "' order by nombreEdificio asc";
        Cursor c = database.rawQuery(sql, null);

        if (c != null && c.moveToFirst()) {
          do {
            _edificioMOD = new EdificioMOD();
            _edificioMOD.setNombreEdificio(c.getString(c.getColumnIndex("nombreEdificio")));

            lista.add(_edificioMOD);
          } while (c.moveToNext());
        }

      } while (ccc.moveToNext());
    }

    return lista;
  }
コード例 #4
0
  private static String contactToNumber(Cursor cur, ContentResolver cr, String id) {
    try {
      if (Integer.parseInt(
              cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))
          > 0) {
        Cursor pCur;

        pCur =
            cr.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                new String[] {id},
                null);

        // first search for default number
        while (pCur.moveToNext()) {

          int defaultIfGreaterThanZero =
              pCur.getInt(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          if (defaultIfGreaterThanZero > 0) {
            return pCur.getString(
                pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          }
        }
        pCur.moveToPosition(-1);
        while (pCur.moveToNext()) {
          return pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        }
        pCur.close();
      }
    } catch (Exception e) {
    }
    return null;
  }
コード例 #5
0
ファイル: CommonDao.java プロジェクト: blueissky/android_oil
 // 获取当月累计油耗
 public String getlitreMonth(Context context, String time_start, String time_end) {
   String year2 = time_start.substring(0, 4);
   String month2 = time_start.substring(5, 7);
   String year1 = year2;
   if (month2.equals("01")) {
     year1 = String.valueOf(Integer.parseInt(year2) - 1);
   }
   String month1 = String.valueOf(Integer.parseInt(month2) - 1);
   dbr = DBHelper.getDBHelper(context).getReadableDatabase();
   double s2 = 0;
   double s1 = 0;
   Cursor cursor = null;
   cursor =
       dbr.rawQuery(
           "select litre from oil WHERE systime BETWEEN ? and ? ORDER BY ID DESC LIMIT 1",
           new String[] {year1 + "-" + month1 + "-" + "01", year1 + "-" + month1 + "-" + "31"});
   while (cursor.moveToNext()) {
     s1 = cursor.getDouble(0); // 上个月最后一次油耗
   }
   cursor.close();
   cursor =
       dbr.rawQuery(
           "select sum(litre)-(select litre from oil where systime BETWEEN ? and ? ORDER BY id desc LIMIT 1)from oil where systime BETWEEN ? and ? ",
           new String[] {time_start, time_end, time_start, time_end});
   while (cursor.moveToNext()) {
     s2 = cursor.getDouble(0);
   }
   cursor.close();
   s1 = s2 + s1;
   return String.valueOf(s1);
 }
コード例 #6
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View myView = inflater.inflate(R.layout.contentp_fragment, container, false);

    // get the one view I need.
    output = (TextView) myView.findViewById(R.id.TextView01);

    appendthis("Query for 2 square");
    // example, select one of them, in this case 2
    Uri onerow = Uri.parse("content://edu.cs4730.provider/square/2");
    Cursor c = getActivity().getContentResolver().query(onerow, null, null, null, null);
    if (c != null) {
      c.moveToFirst();
      do {
        Log.i(TAG, "Value is" + c.getString(0));
        appendthis(c.getString(0) + " value is " + c.getString(1));
      } while (c.moveToNext());
    }

    appendthis("\nQuery all for cube:");
    // now select "all", which will return 1 to 10 cubed.
    Uri allrow = Uri.parse("content://edu.cs4730.provider/cube");
    c = getActivity().getContentResolver().query(allrow, null, null, null, null);
    if (c != null) {
      c.moveToFirst();
      do {
        Log.i(TAG, "Value is " + c.getString(0));
        appendthis(c.getString(0) + " value is " + c.getString(1));
      } while (c.moveToNext());
    }

    return myView;
  }
コード例 #7
0
  public void complaintData() {

    try {
      cursor = dbAccess.getComplaint();
      compMessage = new String[cursor.getCount()];
      comDate = new String[cursor.getCount()];
      blobArray = new byte[cursor.getCount()][];
      if (cursor.moveToNext()) {

        for (int i = 0; i < cursor.getCount(); i++) {
          compMessage[i] = cursor.getString(cursor.getColumnIndex("complaintMessage"));
          comDate[i] = cursor.getString(cursor.getColumnIndex("datetime"));
          blobArray[i] = cursor.getBlob(cursor.getColumnIndex("image"));
          cursor.moveToNext();
        }
      } else {

        Toast.makeText(getApplicationContext(), "databse not created...", Toast.LENGTH_LONG).show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    complaintAdapter = new ComplaintAdapter(this, compMessage, comDate, blobArray);
    listView.setAdapter(complaintAdapter);
  }
コード例 #8
0
 public HashMap<String, String> getAllTermsForCompanyID(String companyCode) {
   System.out.println("TErmes : " + companyCode);
   HashMap<String, String> allTerms = new HashMap<String, String>();
   SQLiteDatabase db = this.getWritableDatabase();
   String id = ApplicationUser.getSharedInstance().getCompanyId();
   System.out.println("TErmes ID : " + companyCode);
   Cursor termCursor =
       db.query(
           TABLE, null, COMPANY_CODE + "=? ", new String[] {companyCode}, null, null, null, null);
   /*String searchSql = "SELECT * FROM "+FRSTermsDB.TABLE+" WHERE "+FRSTermsDB.COMPANY_CODE+"= '"+ApplicationUser.getSharedInstance().getCompanyId()+"'";
   Cursor termCursor = db.rawQuery(searchSql, null);*/
   if (termCursor != null) {
     if (termCursor.moveToNext()) {
       do {
         String desc = termCursor.getString(termCursor.getColumnIndex(DESCRIPTION));
         String term = termCursor.getString(termCursor.getColumnIndex(TERM));
         allTerms.put(desc, term);
       } while (termCursor.moveToNext());
     }
   }
   db.close();
   termCursor.close();
   System.out.println("TErmes End : " + System.currentTimeMillis());
   return allTerms;
 }
コード例 #9
0
  @Test
  public void testTwoConcurrentDbConnections() throws Exception {
    SQLiteDatabase db1 =
        SQLiteDatabase.openDatabase(
            Robolectric.application.getDatabasePath("db1").getPath(), null, 0);
    SQLiteDatabase db2 =
        SQLiteDatabase.openDatabase(
            Robolectric.application.getDatabasePath("db2").getPath(), null, 0);

    db1.execSQL("CREATE TABLE foo(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);");
    db2.execSQL("CREATE TABLE bar(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);");

    ContentValues d1 = new ContentValues();
    d1.put("data", "d1");

    ContentValues d2 = new ContentValues();
    d2.put("data", "d2");

    db1.insert("foo", null, d1);
    db2.insert("bar", null, d2);

    Cursor c = db1.rawQuery("select * from foo", null);
    assertThat(c).isNotNull();
    assertThat(c.getCount()).isEqualTo(1);
    assertThat(c.moveToNext()).isTrue();
    assertThat(c.getString(c.getColumnIndex("data"))).isEqualTo("d1");

    c = db2.rawQuery("select * from bar", null);
    assertThat(c).isNotNull();
    assertThat(c.getCount()).isEqualTo(1);
    assertThat(c.moveToNext()).isTrue();
    assertThat(c.getString(c.getColumnIndex("data"))).isEqualTo("d2");
  }
コード例 #10
0
  @Test
  public void testReplaceIsReplacing() throws Exception {
    final String query = "SELECT first_column FROM table_name WHERE id = ";
    String stringValueA = "column_valueA";
    String stringValueB = "column_valueB";
    long id = 1;

    ContentValues valuesA = new ContentValues();
    valuesA.put("id", id);
    valuesA.put("first_column", stringValueA);

    ContentValues valuesB = new ContentValues();
    valuesB.put("id", id);
    valuesB.put("first_column", stringValueB);

    long firstId = database.replaceOrThrow("table_name", null, valuesA);
    Cursor firstCursor = executeQuery(query + firstId);
    assertThat(firstCursor.moveToNext()).isTrue();
    long secondId = database.replaceOrThrow("table_name", null, valuesB);
    Cursor secondCursor = executeQuery(query + secondId);
    assertThat(secondCursor.moveToNext());

    assertThat(firstId).isEqualTo(id);
    assertThat(secondId).isEqualTo(id);
    assertThat(firstCursor.getString(0)).isEqualTo(stringValueA);
    assertThat(secondCursor.getString(0)).isEqualTo(stringValueB);
  }
コード例 #11
0
  @Test
  public void testExecSQLParams() throws Exception {
    database.execSQL(
        "CREATE TABLE `routine` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `name` VARCHAR , `lastUsed` INTEGER DEFAULT 0 ,  UNIQUE (`name`)) ",
        new Object[] {});
    database.execSQL(
        "INSERT INTO `routine` (`name` ,`lastUsed` ) VALUES (?,?)", new Object[] {"Leg Press", 0});
    database.execSQL(
        "INSERT INTO `routine` (`name` ,`lastUsed` ) VALUES (?,?)",
        new Object[] {"Bench Press", 1});

    Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM `routine`", null);
    assertThat(cursor).isNotNull();
    assertThat(cursor.moveToNext()).isTrue();
    assertThat(cursor.getInt(0)).isEqualTo(2);

    cursor = database.rawQuery("SELECT `id`, `name` ,`lastUsed` FROM `routine`", null);
    assertThat(cursor).isNotNull();
    assertThat(cursor.moveToNext()).isTrue();

    assertThat(cursor.getInt(cursor.getColumnIndex("id"))).isEqualTo(1);
    assertThat(cursor.getInt(cursor.getColumnIndex("lastUsed"))).isEqualTo(0);
    assertThat(cursor.getString(cursor.getColumnIndex("name"))).isEqualTo("Leg Press");

    assertThat(cursor.moveToNext()).isTrue();

    assertThat(cursor.getInt(cursor.getColumnIndex("id"))).isEqualTo(2);
    assertThat(cursor.getInt(cursor.getColumnIndex("lastUsed"))).isEqualTo(1);
    assertThat(cursor.getString(cursor.getColumnIndex("name"))).isEqualTo("Bench Press");
  }
コード例 #12
0
  public void resolve() {
    ContentResolver resolver = getContentResolver();
    Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
    Uri dataUri = Uri.parse("content://com.android.contacts/data");
    Cursor cursor = resolver.query(uri, null, null, null, null);

    while (cursor.moveToNext()) {

      String id = cursor.getString(cursor.getColumnIndex("contact_id"));
      Cursor cursor1 = resolver.query(dataUri, null, "raw_contact_id=?", new String[] {id}, null);

      while (cursor1.moveToNext()) {
        String data = cursor1.getString(cursor1.getColumnIndex("data1"));
        String mimetype = cursor1.getString(cursor1.getColumnIndex("mimetype"));
        String name = cursor1.getString(cursor1.getColumnIndex("display_name"));

        if (mimetype.equals("vnd.android.cursor.item/phone_v2")) {
          data = data.replace(" ", "");
          phoneNumber.add(data);
          getImage(data);
          phoneNumberToId.put(data, id);
          nameList.add(name);
        }
      }

      cursor1.close();
    }
    cursor.close();
  }
コード例 #13
0
  private void updateTables7() {
    final ArrayList<Long> seriesIDs = new ArrayList<Long>();
    Cursor cursor = myDatabase.rawQuery("SELECT series_id,name FROM Series", null);
    while (cursor.moveToNext()) {
      if (cursor.getString(1).length() > 200) {
        seriesIDs.add(cursor.getLong(0));
      }
    }
    cursor.close();
    if (seriesIDs.isEmpty()) {
      return;
    }

    final ArrayList<Long> bookIDs = new ArrayList<Long>();
    for (Long id : seriesIDs) {
      cursor = myDatabase.rawQuery("SELECT book_id FROM BookSeries WHERE series_id=" + id, null);
      while (cursor.moveToNext()) {
        bookIDs.add(cursor.getLong(0));
      }
      cursor.close();
      myDatabase.execSQL("DELETE FROM BookSeries WHERE series_id=" + id);
      myDatabase.execSQL("DELETE FROM Series WHERE series_id=" + id);
    }

    for (Long id : bookIDs) {
      myDatabase.execSQL("DELETE FROM Books WHERE book_id=" + id);
      myDatabase.execSQL("DELETE FROM BookAuthor WHERE book_id=" + id);
      myDatabase.execSQL("DELETE FROM BookTag WHERE book_id=" + id);
    }
  }
コード例 #14
0
  public List<Note> getAllRemindersByTag(String tag) { // only returns notes, NOT reminders
    List<Note> mNotes = new ArrayList<Note>();
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cur =
        db.rawQuery(
            "select id, title, note_text,type from note_tags join notes on note_id = id where type = 1 and tag_name = "
                + tag,
            null);

    if (cur.moveToFirst()) {
      do {
        Note n = new Note();
        n.id = cur.getInt(0);
        n.text = cur.getString(2);
        n.title = cur.getString(1);
        n.type = cur.getInt(3);
        Cursor cur2 = db.rawQuery("select tag_name from note_tags where note_id = " + n.id, null);
        if (cur2.moveToFirst()) {
          do {
            n.tags.add(new String(cur2.getString(0)));
          } while (cur2.moveToNext());
        }
        mNotes.add(n);
      } while (cur.moveToNext());
    }

    return mNotes;
  }
コード例 #15
0
  public List<Note> getAllReminders() {
    List<Note> mNotes = new ArrayList<Note>();
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cur = db.rawQuery("select * from notes where type = 1", null);

    if (cur.moveToFirst()) {
      do {
        Note n = new Note();
        n.id = cur.getInt(cur.getColumnIndex("id"));
        n.text = cur.getString(cur.getColumnIndex("note_text"));
        n.title = cur.getString(cur.getColumnIndex("title"));
        n.type = cur.getInt(cur.getColumnIndex("type"));
        Cursor cur2 = db.rawQuery("select tag_name from note_tags where note_id = " + n.id, null);
        if (cur2.moveToFirst()) {
          do {
            n.tags.add(new String(cur2.getString(0)));
          } while (cur2.moveToNext());
        }
        mNotes.add(n);
      } while (cur.moveToNext());
    }

    return mNotes;
  }
コード例 #16
0
ファイル: SqlUtils.java プロジェクト: junwuwei/yfmcode
  public List<Tel_query> queryTel_query(String name) {
    List<Tel_query> ltt = new ArrayList<Tel_query>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor count =
        db.rawQuery(
            "select count(*) c from (select * from tel_query where ggxh like ?)",
            new String[] {"%" + name + "%"});
    int c = 0;
    if (count.moveToNext()) {
      c = count.getInt(count.getColumnIndex("c"));
    }
    count.close();
    if (c <= 150) {
      Cursor cursor =
          db.rawQuery(
              "select * from tel_query where ggxh like ? order by ggxh",
              new String[] {"%" + name + "%"});
      while (cursor.moveToNext()) {
        Tel_query tt = new Tel_query();
        tt.setGgxh(cursor.getString(cursor.getColumnIndex("ggxh")));
        tt.setText(cursor.getString(cursor.getColumnIndex("text")));
        ltt.add(tt);
      }
      cursor.close();
    }

    return ltt;
  }
コード例 #17
0
ファイル: SqlUtils.java プロジェクト: junwuwei/yfmcode
  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;
  }
コード例 #18
0
 // TODO: query with normalized number
 public String queryName(String number) {
   if (number == null || number.length() == 0) {
     return null;
   }
   String name = null;
   Cursor dataCs =
       mContentResolver.query(
           Data.CONTENT_URI,
           DEFAULT_DATA_PROJECTION,
           DATA_SELECTION_BY_NUMBER,
           new String[] {number},
           null);
   if (dataCs == null) {
     return null;
   }
   if (dataCs.moveToNext()) {
     Uri uri =
         ContentUris.withAppendedId(
             Contacts.CONTENT_URI, dataCs.getLong(DATA_COLUMN_RAW_CONTACT_ID));
     Cursor contactsCs =
         mContentResolver.query(uri, DEFAULT_CONTACTS_PROJECTION, null, null, null);
     if (contactsCs == null) {
       return null;
     }
     if (contactsCs.moveToNext()) {
       name = contactsCs.getString(CONTACTS_COLUMN_DISPLAY_NAME);
     }
     contactsCs.close();
   }
   dataCs.close();
   return name;
 }
コード例 #19
0
  // ------------------------------------------------------ get All phone #s
  // numbers
  public ArrayList<String> getAllNumbers() {
    Uri uri = ContactsContract.Data.CONTENT_URI;

    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    ArrayList<String> tempNumbers = null;

    while (cursor.moveToNext()) {
      String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
      String hasPhone =
          cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

      if (Boolean.parseBoolean(hasPhone)) {
        // You know have the number so now query it like this
        Cursor phones =
            context
                .getContentResolver()
                .query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null,
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
                    null,
                    null);

        while (phones.moveToNext()) {
          String phoneNumber =
              phones.getString(
                  phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          tempNumbers.add(phoneNumber);
        }
        phones.close();
      }
    }
    return tempNumbers;
  }
コード例 #20
0
 public String queryNumber(String words) {
   String[] arg = new String[] {"%" + words + "%"};
   Cursor contactsCursor =
       mContentResolver.query(
           Contacts.CONTENT_URI,
           DEFAULT_CONTACTS_PROJECTION,
           CONTACTS_SELECTION_BY_NAME,
           arg,
           Contacts.SORT_KEY_PRIMARY);
   StringBuilder sb = new StringBuilder();
   if (contactsCursor == null) {
     return null;
   }
   while (contactsCursor.moveToNext()) {
     long id = contactsCursor.getLong(CONTACTS_COLUMN_ID);
     Cursor dataCursor =
         mContentResolver.query(
             Data.CONTENT_URI,
             DEFAULT_DATA_PROJECTION,
             DATA_SELECTION_BY_CONTACT_ID,
             new String[] {String.valueOf(id)},
             null);
     if (dataCursor != null) {
       while (dataCursor.moveToNext()) {
         log(dataCursor.getString(DATA_COLUMN_NUMBER));
         sb.append(dataCursor.getString(DATA_COLUMN_NUMBER));
         sb.append(LINE_NUMBER_SPERATOR);
       }
       dataCursor.close();
     }
   }
   contactsCursor.close();
   return sb.toString();
 }
コード例 #21
0
  public void testTrackingIds() {
    final int count = 3;

    // Test suggested sites with IDs.
    resources.setSuggestedSitesResource(generateSites(count, true, ""));
    SuggestedSites suggestedSites = new SuggestedSites(context);
    Cursor c = suggestedSites.get(DEFAULT_LIMIT);
    assertEquals(count, c.getCount());

    for (int i = 0; i < count; i++) {
      c.moveToNext();
      String url = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.URL));
      assertTrue(suggestedSites.contains(url));
      assertEquals(i, suggestedSites.getTrackingIdForUrl(url));
    }
    c.close();

    // Test suggested sites where IDs are undefined.
    resources.setSuggestedSitesResource(generateSites(count, false, ""));
    suggestedSites = new SuggestedSites(context);
    c = suggestedSites.get(DEFAULT_LIMIT);
    assertEquals(count, c.getCount());

    for (int i = 0; i < count; i++) {
      c.moveToNext();
      String url = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.URL));
      assertTrue(suggestedSites.contains(url));
      assertEquals(SuggestedSites.TRACKING_ID_NONE, suggestedSites.getTrackingIdForUrl(url));
    }
    c.close();
  }
コード例 #22
0
 public Single<List<LocationRecord>> getLocationRecordList() {
   return Single.create(
       singleSubscriber -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           List<LocationRecord> result = new ArrayList<>();
           Cursor unsentCursor =
               mBriteDatabase.query("SELECT * FROM " + LocalUnsentLocationRecordTable.NAME);
           Cursor sentCursor =
               mBriteDatabase.query("SELECT * FROM " + RemoteLocationRecordTable.NAME);
           if (!singleSubscriber.isUnsubscribed()) {
             while (sentCursor.moveToNext()) {
               result.add(RemoteLocationRecordTable.parseCursor(sentCursor));
             }
           }
           if (!singleSubscriber.isUnsubscribed()) {
             while (unsentCursor.moveToNext()) {
               result.add(LocalUnsentLocationRecordTable.parseCursor(unsentCursor));
             }
           }
           unsentCursor.close();
           sentCursor.close();
           singleSubscriber.onSuccess(result);
         } finally {
           transaction.end();
         }
       });
 }
コード例 #23
0
ファイル: CommonDao.java プロジェクト: blueissky/android_oil
 // 查询当月行驶公里数
 public String getKiloMonth(Context context, String time_start, String time_end) {
   String year2 = time_start.substring(0, 4);
   String month2 = time_start.substring(5, 7);
   String year1 = year2;
   if (month2.equals("01")) {
     year1 = String.valueOf(Integer.parseInt(year2) - 1);
   }
   String month1 = String.valueOf(Integer.parseInt(month2) - 1);
   dbr = DBHelper.getDBHelper(context).getReadableDatabase();
   int s2 = 0;
   int s1 = 0;
   Cursor cursor = null;
   cursor =
       dbr.rawQuery(
           "select max(kilo) from oil WHERE systime BETWEEN ? and ?",
           new String[] {year1 + "-" + month1 + "-" + "01", year1 + "-" + month1 + "-" + "31"});
   while (cursor.moveToNext()) {
     s1 = cursor.getInt(0);
   }
   cursor.close();
   cursor =
       dbr.rawQuery(
           "select max(kilo) from oil WHERE systime BETWEEN ? and ?",
           new String[] {time_start, time_end});
   while (cursor.moveToNext()) {
     s2 = cursor.getInt(0);
   }
   cursor.close();
   s1 = s2 - s1;
   return String.valueOf(s1);
 }
コード例 #24
0
  private void Escribe_contactos(Cursor c) {
    if (c.moveToFirst()) {
      do {
        String contactID = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
        String contactDisplayName =
            c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

        Log.v("Content Providers", contactID + ", " + contactDisplayName);
        // ---get phone number---
        int hasPhone = c.getInt(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
        if (hasPhone == 1) {
          Cursor phoneCursor =
              getContentResolver()
                  .query(
                      ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                      null,
                      ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactID,
                      null,
                      null);
          while (phoneCursor.moveToNext()) {
            Log.v(
                "Content Providers",
                phoneCursor.getString(
                    phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
          }
          phoneCursor.close();
        }
      } while (c.moveToNext());
    }
  }
コード例 #25
0
  private static String contactToEmail(Cursor cur, ContentResolver cr, String id) {
    Cursor emailCur =
        cr.query(
            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            null,
            ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
            new String[] {id},
            null);
    // first search for default number
    while (emailCur.moveToNext()) {

      int defaultIfGreaterThanZero =
          emailCur.getInt(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      if (defaultIfGreaterThanZero > 0) {
        return emailCur.getString(
            emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      }
    }
    emailCur.moveToPosition(-1);
    while (emailCur.moveToNext()) {
      // This would allow you get several email addresses
      // if the email addresses were stored in an array
      return emailCur.getString(
          emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
    }
    emailCur.close();
    return null;
  }
コード例 #26
0
 /**
  * starts the mode that was selected
  *
  * @param mode mode to start
  */
 private void startGame(GameModeEnum mode) {
   Intent i;
   if (mode.equals(GameModeEnum.weekly)) {
     // updateWeeklyPuzzle();
     SudroidDatabaseHelper helper = new SudroidDatabaseHelper(this);
     SQLiteDatabase db = helper.getReadableDatabase();
     Cursor cursor =
         db.query(
             "Weekly",
             new String[] {"_id", "place"},
             "place != null or place != 0",
             null,
             null,
             null,
             null);
     if (cursor.moveToNext()) {
       int id = cursor.getInt(0);
       db.query("Puzzle", new String[] {"_id", "time"}, "_id = " + id, null, null, null, null);
       if (cursor.moveToNext()) {
         i = new Intent(this, SudroidHighScoreActivity.class);
         i.putExtra(SudroidHighScoreActivity.finishTime, cursor.getString(1));
         i.putExtra("week", true);
         startActivity(i);
       }
     }
   }
   i = new Intent(this, SudroidGameActivity.class);
   i.putExtra(SudroidGameActivity.mode, mode.ordinal());
   startActivity(i);
 }
コード例 #27
0
 public void cleanOldBlock() {
   SQLiteDatabase db = this.mDb.getReadableDatabase();
   String sql = "select count(0) cnt from blocks";
   Cursor c = db.rawQuery(sql, null);
   int cnt = 0;
   if (c.moveToNext()) {
     int idColumn = c.getColumnIndex("cnt");
     if (idColumn != -1) {
       cnt = c.getInt(idColumn);
     }
   }
   c.close();
   if (cnt > 5000) {
     sql = "select max(block_no) max_block_no from blocks where is_main=1";
     c = db.rawQuery(sql, null);
     int maxBlockNo = 0;
     if (c.moveToNext()) {
       int idColumn = c.getColumnIndex("max_block_no");
       if (idColumn != -1) {
         maxBlockNo = c.getInt(idColumn);
       }
     }
     c.close();
     int blockNo =
         (maxBlockNo - BitherjSettings.BLOCK_DIFFICULTY_INTERVAL)
             - maxBlockNo % BitherjSettings.BLOCK_DIFFICULTY_INTERVAL;
     db = this.mDb.getWritableDatabase();
     db.delete(AbstractDb.Tables.BLOCKS, "block_no<?", new String[] {Integer.toString(blockNo)});
   }
 }
コード例 #28
0
 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
   setContentView(R.layout.mastersetlist);
   data = new DataBaseHelper(this);
   setTitle("Notification Settings");
   lv1 = (ListView) findViewById(R.id.list);
   lv1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
   lv1.setAdapter(
       new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, array));
   lv1.setTextFilterEnabled(true);
   lv1.setOnItemClickListener(this);
   Cursor c9 = data.getnotisettings();
   while (c9.moveToNext()) {
     flag = c9.getInt(0);
     System.out.println("Noti Flag will be......." + flag);
   }
   c9.close();
   Cursor c10 = data.getwinsettings();
   while (c10.moveToNext()) {
     flag1 = c10.getInt(0);
     System.out.println("Win Flag will be......." + flag1);
   }
   c10.close();
   if (flag == 1) {
     lv1.setItemChecked(0, true);
   } else if (flag1 == 1) {
     lv1.setItemChecked(1, true);
   }
 }
コード例 #29
0
ファイル: FeedAdapter.java プロジェクト: Bingle-labake/Vine15
 public void bindView(View paramView, Context paramContext, Cursor paramCursor)
 {
   int i = paramCursor.getPosition();
   FeedViewHolder localFeedViewHolder = (FeedViewHolder)paramView.getTag();
   localFeedViewHolder.post = bindCursorToPost(paramCursor);
   localFeedViewHolder.position = i;
   this.mPosts.put(i, localFeedViewHolder.post);
   boolean bool = paramCursor.moveToNext();
   VinePost localVinePost = null;
   if (bool)
   {
     localVinePost = bindCursorToPost(paramCursor);
     this.mPosts.put(paramCursor.getPosition(), localVinePost);
     if (paramCursor.moveToNext())
     {
       this.mPosts.put(paramCursor.getPosition(), bindCursorToPost(paramCursor));
       paramCursor.moveToPrevious();
     }
     paramCursor.moveToPrevious();
   }
   if (localFeedViewHolder.post == null)
   {
     CrashUtil.logException(new VineException("Post was null: " + i + " nextPost is: " + localVinePost));
     return;
   }
   bindView(localFeedViewHolder);
 }
  private boolean updateSuggestedContactIds(Cursor cursor) {
    int count = cursor.getCount();
    boolean changed = count != mSuggestedContactIds.length;
    if (!changed) {
      while (cursor.moveToNext()) {
        long contactId = cursor.getLong(0);
        if (Arrays.binarySearch(mSuggestedContactIds, contactId) < 0) {
          changed = true;
          break;
        }
      }
    }

    if (changed) {
      mSuggestedContactIds = new long[count];
      cursor.moveToPosition(-1);
      for (int i = 0; i < count; i++) {
        cursor.moveToNext();
        mSuggestedContactIds[i] = cursor.getLong(0);
      }
      Arrays.sort(mSuggestedContactIds);
    }

    return changed;
  }