public boolean isSecureTextSupported(String e164number) throws NotInDirectoryException {
    if (e164number == null || e164number.length() == 0) {
      return false;
    }

    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor = null;

    try {
      cursor =
          db.query(
              TABLE_NAME,
              new String[] {REGISTERED},
              NUMBER + " = ?",
              new String[] {e164number},
              null,
              null,
              null);

      if (cursor != null && cursor.moveToFirst()) {
        return cursor.getInt(0) == 1;
      } else {
        throw new NotInDirectoryException();
      }

    } finally {
      if (cursor != null) cursor.close();
    }
  }
示例#2
0
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   // SQL查询构造器
   SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
   // If no sort order is specified use the default
   String orderBy = "";
   switch (mUriMatcher.match(uri)) {
     case NOTEITEMS_ITEM: // 注意:没有使用break,我们让它使用后面一条case语句的break
       // 组建SQL的where
       queryBuilder.appendWhere(NoteItems._ID + " = " + uri.getPathSegments().get(1));
     case NOTEITEMS:
       // 设置待查询的表
       queryBuilder.setTables(TABLE_NOTEITEMS);
       // 设置要查询的列
       queryBuilder.setProjectionMap(mProjectionMap_NoteItems);
       // 设置排序
       if (TextUtils.isEmpty(sortOrder)) {
         orderBy = NoteItems.DEFAULT_SORT_ORDER;
       } else {
         orderBy = sortOrder;
       }
       break;
     default:
       throw new IllegalArgumentException("Unknown URI " + uri);
   }
   SQLiteDatabase db = mOpenHelper.getReadableDatabase();
   Cursor c = queryBuilder.query(db, projection, selection, selectionArgs, null, null, orderBy);
   // Tell the cursor what uri to watch, so it knows when its source data
   // changes
   c.setNotificationUri(getContext().getContentResolver(), uri);
   ILog.d(MainActivity.TAG, "ContentProvider==>query()");
   return c;
 }
示例#3
0
 /**
  * 查询去重数据库
  *
  * @param context
  * @param db
  * @param Table_Name
  * @param colums 获取数据的列名称
  * @param selection where后面的内容
  * @param selectionArgs where后面内容的参数
  * @param groupBy GROUP BY后面的字符串
  * @param having HAVING后面的字符串
  * @param orderBy ORDER BY后面的字符串
  * @param limit 返回的数量
  * @param distinct 是否去重
  * @return
  */
 protected Cursor distinctQuery(
     Context context,
     String db,
     String Table_Name,
     String[] colums,
     String selection,
     String[] selectionArgs,
     String groupBy,
     String having,
     String orderBy,
     String limit,
     boolean distinct,
     String distinctType) {
   databaseHelper = CreateTable.getInstance(context, db);
   sqLiteDatabase = databaseHelper.getReadableDatabase();
   try {
     if (distinct) {
       String content = "";
       if (colums != null) {
         for (int i = 0; i < colums.length; i++) {
           content += "," + colums[i];
         }
       }
       String sql = "select distinct(" + distinctType + ")" + content + " from " + Table_Name;
       return sqLiteDatabase.rawQuery(sql, new String[] {});
     } else {
       return sqLiteDatabase.query(
           Table_Name, colums, selection, selectionArgs, groupBy, having, orderBy, limit);
     }
   } catch (Exception e) {
     return null;
   }
 }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(DatabaseHelper.TABLE_ITEM);

    int uriType = mURImatcher.match(uri);

    switch (uriType) {
      case ITEMS_ID:
        queryBuilder.appendWhere(DatabaseHelper.KEY_ITEM_ID + "=" + uri.getLastPathSegment());
        break;
      case ITEMS:
        break;
      default:
        throw new IllegalArgumentException("Unknown URI");
    }

    Cursor cursor =
        queryBuilder.query(
            mDatabaseHelper.getReadableDatabase(),
            projection,
            selection,
            selectionArgs,
            null,
            null,
            sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
  }
  /** Query the database */
  private Cursor query(String selection, String[] selectionArgs) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    // main INNER JOIN frequency ON (main._id=freq.pair_id)
    qb.setTables(
        MAIN_TABLE_NAME
            + " INNER JOIN "
            + FREQ_TABLE_NAME
            + " ON ("
            + MAIN_TABLE_NAME
            + "."
            + MAIN_COLUMN_ID
            + "="
            + FREQ_TABLE_NAME
            + "."
            + FREQ_COLUMN_PAIR_ID
            + ")");

    qb.setProjectionMap(sDictProjectionMap);

    // Get the database and run the query
    SQLiteDatabase db = sOpenHelper.getReadableDatabase();
    Cursor c =
        qb.query(
            db,
            new String[] {MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD2, FREQ_COLUMN_FREQUENCY},
            selection,
            selectionArgs,
            null,
            null,
            null);
    return c;
  }
示例#6
0
  private void setQuestion(Integer questionNo) {
    DatabaseHelper dbHelper = new DatabaseHelper(this);
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    String sql =
        "SELECT Pref, City0, City1, City2, City3, City4 FROM MyTable WHERE _id="
            + questionNo.toString();

    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();

    String Kenmei = c.getString(c.getColumnIndex("Pref"));
    String Choice1 = c.getString(c.getColumnIndex("City1"));
    String Choice2 = c.getString(c.getColumnIndex("City2"));
    String Choice3 = c.getString(c.getColumnIndex("City3"));
    String Choice4 = c.getString(c.getColumnIndex("City4"));

    Seikai = c.getString(c.getColumnIndex("City0"));

    c.close();
    db.close();

    ((TextView) findViewById(R.id.textQuestion)).setText(Kenmei);
    ((Button) findViewById(R.id.button1)).setText(Choice1);
    ((Button) findViewById(R.id.button2)).setText(Choice2);
    ((Button) findViewById(R.id.button3)).setText(Choice3);
    ((Button) findViewById(R.id.button4)).setText(Choice4);
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    /* DEV
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    .detectDiskReads()
    .detectDiskWrites()
    .detectNetwork()   // or .detectAll() for all detectable problems
    .penaltyLog()
    .build());
    */
    super.onCreate(savedInstanceState);

    setContentView(R.layout.playgame);

    mGameMode = getIntent().getStringExtra("mode");

    final DatabaseHelper mOpenHelper = new DatabaseHelper(this, "wordlist");
    m_db = mOpenHelper.getReadableDatabase();

    m_playboard = (PlayBoard) findViewById(R.id.playboard);
    m_playboard.setBoardSize(5, 5);
    mBoardGameLogic.setBoard(m_playboard);

    m_word = (TextView) findViewById(R.id.word);
    mPlayTime = (TextView) findViewById(R.id.play_time);
    mScoreText = (TextView) findViewById(R.id.score);

    // Temporary components
    m_text_status = (TextView) findViewById(R.id.status);
    m_start_button = (Button) findViewById(R.id.restart_game);

    startGame(0);
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (!accept()) {
      return null;
    }

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(SHARING_TABLE_NAME);

    switch (uriMatcher.match(uri)) {
      case SHARING_ALL:
        qb.setProjectionMap(sharingProjectionMap);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // Get the database and run the query
    SQLiteDatabase db = databaseHelper.getReadableDatabase();

    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null);

    // Tell the cursor what uri to watch, so it knows when its source data
    // changes
    c.setNotificationUri(getContext().getContentResolver(), uri);

    return c;
  }
  @Override
  public Cursor query(
      final Uri uri,
      final String[] columns,
      final String where,
      final String[] whereArgs,
      final String order) {
    Cursor c = null;

    final int match = sUriMatcher.match(uri);

    // get a readable database access
    SQLiteDatabase db = sDbHelper.getReadableDatabase();

    // log message
    Out.d(TAG, "BusinessObjectProvider.query: uri=" + uri + ", match is " + match);

    // we get the table and then query to the database
    String table = getTableName(match);
    c = db.query(table, columns, where, whereArgs, null, null, order);

    // we notify that a change happened if it actually occurred
    if ((c != null) && !isTemporary()) {
      c.setNotificationUri(sContext.getContentResolver(), uri);
    }
    return c;
  }
示例#10
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch (sUriMatcher.match(uri)) {
      case INCOMING_CONTACT_COLLECTION_URI_INDICATOR:
        qb.setTables(ContactTableMetaData.TABLE_NAME);
        qb.setProjectionMap(sContactProjectMap);
        break;
      case INCOMING_SIGNLE_CONTACT_URI_INDICATOR:
        qb.setTables(ContactTableMetaData.TABLE_NAME);
        qb.setProjectionMap(sContactProjectMap);
        qb.appendWhere(ContactTableMetaData.CONTACT_ACCOUNT + "=" + uri.getPathSegments().get(1));
        break;

      default:
        throw new IllegalArgumentException("Unknow URI " + uri);
    }

    String orderBy =
        TextUtils.isEmpty(sortOrder) ? ContactTableMetaData.DEFAULT_SORT_ORDER : sortOrder;

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);

    c.setNotificationUri(getContext().getContentResolver(), uri);

    return c;
  }
示例#11
0
  private void prepararEdicao() {
    SQLiteDatabase db = helper.getReadableDatabase();

    Cursor cursor =
        db.rawQuery(
            "SELECT TIPO_VIAGEM, DESTINO, DATA_CHEGADA, "
                + "DATA_SAIDA, QUANTIDADE_PESSOAS, ORCAMENTO "
                + "FROM VIAGEM WHERE _ID = ?",
            new String[] {id});
    cursor.moveToFirst();

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

    if (cursor.getInt(0) == Constantes.VIAGEM_LAZER) {
      radioGroup.check(R.id.lazer);
    } else {
      radioGroup.check(R.id.negocios);
    }

    destino.setText(cursor.getString(1));
    dataChegada = new Date(cursor.getLong(2));
    dataSaida = new Date(cursor.getLong(3));
    dataChegadaButton.setText(dateFormat.format(dataChegada));
    dataSaidaButton.setText(dateFormat.format(dataSaida));
    quantidadePessoas.setText(cursor.getString(4));
    orcamento.setText(cursor.getString(5));
    cursor.close();
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    switch (sUriMatcher.match(uri)) {
      case DEVICES:
        qb.setTables(DEVICES_TABLE_NAME);
        qb.setProjectionMap(devicesProjectionMap);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor c =
        db.query(
            DEVICES_TABLE_NAME,
            projection,
            selection,
            selectionArgs,
            null,
            null,
            sortOrder); // qb.query(db, projection, selection, selectionArgs, null, null,
                        // sortOrder);

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
  }
示例#13
0
 public boolean removall() {
   SQLiteDatabase sdb = dbHelper.getReadableDatabase();
   String sql = "delete from friend";
   sdb.execSQL(sql);
   sdb.close();
   return true;
 }
示例#14
0
 public static List<Line> getLines(Context context) {
   DatabaseHelper dbHelper = new DatabaseHelper(context);
   SQLiteDatabase db = dbHelper.getReadableDatabase();
   Cursor cursor = null;
   List<Line> lines = new ArrayList<Line>();
   try {
     String[] columns = {
       LineDb.COL_ID,
       LineDb.COL_NAME,
       LineDb.COL_DESCRIPTION,
       LineDb.COL_REGION,
       LineDb.COL_POINTS,
       LineDb.COL_DIRECTION
     };
     cursor = db.query(LineDb.TABLE, columns, null, null, null, null, null);
     while (cursor.moveToNext()) {
       Line line = new Line();
       line.setId(cursor.getString(0));
       line.setName(cursor.getString(1));
       line.setDescription(cursor.getString(2));
       line.setRegion(cursor.getString(3));
       line.setPoints(Point.fromText(cursor.getString(4)));
       line.setDirection(cursor.getString(5));
       lines.add(line);
     }
     return lines;
   } finally {
     if (null != cursor) cursor.close();
     if (null != db) db.close();
   }
 }
  // Check if a printer exists to avoid multiple insertions
  public static boolean checkExisting(ModelPrinter m) {

    boolean exists = true;

    // Gets the data repository in read mode
    mDb = mDbHelper.getReadableDatabase();

    String selectQuery =
        "SELECT * FROM "
            + FeedEntry.TABLE_NAME
            + " WHERE "
            + FeedEntry.DEVICES_NAME
            + " = '"
            + m.getName()
            + "' AND "
            + FeedEntry.DEVICES_ADDRESS
            + " = '"
            + m.getAddress()
            + "'";

    Cursor c = mDb.rawQuery(selectQuery, null);

    if (c.moveToFirst()) {

      exists = true;

    } else {

      exists = false;
    }

    closeDb();

    return exists;
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteDatabase db = helper.getReadableDatabase();
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

    switch (sURIMatcher.match(uri)) {
      case PRODUCTS_LIST:
        builder.setTables(ProductsTable.TABLE_PRODUCTS);
        if (TextUtils.isEmpty(sortOrder)) {
          sortOrder = ProductsTable.SORT_ORDER_DEFAULT;
        }
        break;
      case PRODUCTS_ID:
        builder.setTables(ProductsTable.TABLE_PRODUCTS);
        builder.appendWhere(ProductsTable.COLUMN_ID + " = " + uri.getLastPathSegment());
        break;

      default:
        throw new IllegalArgumentException("Unsupported URI: " + uri);
    }

    Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
  }
  public ArrayList<AuctionItem> getAllAuctions() {
    ArrayList<AuctionItem> allAuctions = new ArrayList<AuctionItem>();
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT * FROM " + AUCTIONS_TABLE + ";", null);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
          AuctionItem auction = new AuctionItem();

          auction.id = cursor.getInt(cursor.getColumnIndex("ID"));
          auction.name = cursor.getString(cursor.getColumnIndex(AUCTIONS_NAME));
          auction.starting_price =
              Double.parseDouble(cursor.getString(cursor.getColumnIndex(AUCTIONS_STARTING_PRICE)));
          auction.created_by = cursor.getString(cursor.getColumnIndex(AUCTIONS_CREATED_BY));
          auction.highest_bid =
              Double.parseDouble(cursor.getString(cursor.getColumnIndex(AUCTIONS_HIGHEST_BID)));
          auction.highest_bidder = cursor.getString(cursor.getColumnIndex(AUCTIONS_HIGHEST_BIDDER));
          auction.hours_active =
              Integer.parseInt(cursor.getString(cursor.getColumnIndex(AUCTIONS_HOURS_ACTIVE)));

          allAuctions.add(auction);
          cursor.moveToNext();
        }
      }
      cursor.close();
    }

    return allAuctions;
  }
  public AuctionItem getAuctionItem(int id) {
    db = dbHelper.getReadableDatabase();
    AuctionItem auction = new AuctionItem();

    Cursor cursor =
        db.query(
            AUCTIONS_TABLE,
            null,
            " ID" + " =?",
            new String[] {String.valueOf(id)},
            null,
            null,
            null);
    if (cursor.getCount() < 1) // item doesn't exist
    {
      cursor.close();
      return null;
    }
    cursor.moveToFirst();

    auction.name = cursor.getString(cursor.getColumnIndex(AUCTIONS_NAME));
    auction.starting_price =
        Double.parseDouble(cursor.getString(cursor.getColumnIndex(AUCTIONS_STARTING_PRICE)));
    auction.created_by = cursor.getString(cursor.getColumnIndex(AUCTIONS_CREATED_BY));
    auction.highest_bid =
        Double.parseDouble(cursor.getString(cursor.getColumnIndex(AUCTIONS_HIGHEST_BID)));
    auction.highest_bidder = cursor.getString(cursor.getColumnIndex(AUCTIONS_HIGHEST_BIDDER));
    auction.hours_active =
        Integer.parseInt(cursor.getString(cursor.getColumnIndex(AUCTIONS_HOURS_ACTIVE)));

    db.close();
    return auction;
  }
  public UserItem getUserItem(String userName) {
    db = dbHelper.getReadableDatabase();
    UserItem user = new UserItem();
    user.username = userName;
    Cursor cursor =
        db.query(
            USERS_TABLE,
            null,
            " " + USERS_USERNAME + " =?",
            new String[] {userName},
            null,
            null,
            null);
    if (cursor.getCount() < 1) // Username doesn't exist
    {
      cursor.close();
      return null;
    }
    cursor.moveToFirst();

    user.id = cursor.getInt(cursor.getColumnIndex("ID"));
    user.email = cursor.getString(cursor.getColumnIndex(USERS_EMAIL));
    user.password = cursor.getString(cursor.getColumnIndex(USERS_PASSWORD));
    user.all_bids =
        convertStringArrayToIntegerArray(
            convertStringToArray(cursor.getString(cursor.getColumnIndex(USERS_ALL_BIDS))));
    cursor.close();
    db.close();
    return user;
  }
  private Cursor getContactFromUri(String uri) {
    // Only interested in the ID
    /*
    String[] columns = {
          DatabaseContract.ContactEntry._ID,
    };
    */

    // Add the WHERE clause
    String selection = DatabaseContract.ContactEntry.COLUMN_NAME_URI + " LIKE ?";
    String[] selectionArgs = {uri};

    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor =
        db.query(
            DatabaseContract.ContactEntry.TABLE_NAME, // The table to query
            null, // The columns to return (all)
            selection, // The columns for the WHERE clause
            selectionArgs, // The values for the WHERE clause
            null, // don't group the rows
            null, // don't filter by row groups
            null, // don't sort the results
            "1" // only keep one entry
            );

    return cursor;
  }
示例#21
0
    @Override
    protected HistoryAdapter doInBackground(AppCompatActivity... activity) {
      ArrayList<String> history = new ArrayList<>();

      DatabaseHelper helper = new DatabaseHelper(MainActivity.mContext);
      SQLiteDatabase db = helper.getReadableDatabase();

      Cursor c =
          db.query(
              DatabaseHelper.Columns.TABLE_NAME,
              new String[] {
                DatabaseHelper.Columns.COLUMN_INPUT, DatabaseHelper.Columns.COLUMN_RESULT
              },
              null,
              null,
              null,
              null,
              DatabaseHelper.Columns._ID + " DESC");

      if (c.moveToFirst()) {
        do history.add(c.getString(0) + " = " + c.getString(1));
        while (c.moveToNext());
      }
      c.close();
      db.close();
      helper.close();

      if (activity.length > 0) return new HistoryAdapter(history, activity[0]);
      else return new HistoryAdapter(history, null);
    }
  public ArrayList<ActionEvent> getAllItems(Context context, boolean isHistory) {
    DatabaseHelper dh = new DatabaseHelper(context, TABLE_NAME);
    SQLiteDatabase db = dh.getReadableDatabase();

    ArrayList<ActionEvent> aeList = new ArrayList<ActionEvent>();
    Cursor c =
        db.query(
            TABLE_NAME,
            null,
            KEY_IS_HISTORY + "='" + getBooleanToLong(isHistory) + "'",
            null,
            null,
            null,
            "_id" + " DESC");
    while (c.moveToNext()) {
      ActionEvent ae =
          new ActionEvent(
              c.getString(c.getColumnIndex(KEY_ACTION_NAME)),
              c.getLong(c.getColumnIndex(KEY_START_TIMESTAMP)),
              c.getString(c.getColumnIndex(KEY_ACTION_NOTE)),
              getLongToBoolean(c.getLong(c.getColumnIndex(KEY_IS_HISTORY))),
              c.getLong(c.getColumnIndex(KEY_START_DEALY)),
              c.getLong(c.getColumnIndex(KEY_START_DEALY)));
      ae.setBreakTimestamp(c.getLong(c.getColumnIndex(KEY_BREAK_TIMESTAMP)));
      ae.setState(c.getString(c.getColumnIndex(KEY_STATE)));
      aeList.add(ae);
    }
    c.close();
    db.close();
    return aeList;
  }
  public String getAddressFromId(long id) {
    String cachedAddress = idCache.get(id);

    if (cachedAddress != null) return cachedAddress;

    Cursor cursor = null;

    try {
      Log.w("CanonicalAddressDatabase", "Hitting DB on query [ID].");

      SQLiteDatabase db = databaseHelper.getReadableDatabase();
      cursor = db.query(TABLE, null, ID_COLUMN + " = ?", new String[] {id + ""}, null, null, null);

      if (!cursor.moveToFirst()) return "Anonymous";

      String address = cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS_COLUMN));

      if (address == null || address.trim().equals("")) {
        return "Anonymous";
      } else {
        idCache.put(id, address);
        return address;
      }
    } finally {
      if (cursor != null) cursor.close();
    }
  }
示例#24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    // 初回時のみデータベース作成
    DatabaseHelper databaseHelper = new DatabaseHelper(this);
    SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();
    sqLiteDatabase.close();

    // いただきますボタン
    BootstrapButton startButton = (BootstrapButton) findViewById(R.id.start_button);
    startButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent intent = new Intent(MyActivity.this, EatingActivity.class);
            startActivity(intent);
          }
        });
    // Yummyの記録ボタン
    BootstrapButton historyButton = (BootstrapButton) findViewById(R.id.history_button);
    historyButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent intent = new Intent(MyActivity.this, HistoryActivity.class);
            startActivity(intent);
          }
        });
  }
 @Override
 public boolean onCreate() {
   Context context = getContext();
   DatabaseHelper dbHelper = new DatabaseHelper(context);
   PruebaBD = dbHelper.getWritableDatabase();
   PruebaBD = dbHelper.getReadableDatabase();
   return (PruebaBD == null) ? false : true; // es un If
 }
示例#26
0
 public boolean removeuser(String userid) {
   SQLiteDatabase sdb = dbHelper.getReadableDatabase();
   String sql = "delete from friend where userid=?";
   Object obj[] = {userid};
   sdb.execSQL(sql, obj);
   sdb.close();
   return true;
 }
示例#27
0
  public boolean isLinhaFavorita(Long idUsuario, Long idLinha) {
    String whereClause = LinhaFavorita.ID_USUARIO + " = ? and " + LinhaFavorita.ID_LINHA + " = ? ";
    String whereArgs[] = new String[] {idUsuario.toString(), idLinha.toString()};

    long count =
        DatabaseUtils.queryNumEntries(
            helper.getReadableDatabase(), LinhaFavorita.TABLE_NAME, whereClause, whereArgs);
    return count > 0;
  }
  // Retrieve the cursor with the elements from the database
  public static Cursor retrieveDeviceList() {

    // Gets the data repository in read mode
    mDb = mDbHelper.getReadableDatabase();

    String selectQuery = "SELECT * FROM " + FeedEntry.TABLE_NAME;

    Cursor c = mDb.rawQuery(selectQuery, null);

    return c;
  }
  // ---- Message table
  // Retrieve all messages for a contact ordered by timestamp
  ArrayList<Map<String, String>> retrieveMessages(String contactName) {
    if (databaseHelper == null) {
      throw new RuntimeException("Database hasn't been opened yet, please call open()");
    }

    SQLiteDatabase db = databaseHelper.getReadableDatabase();

    // Add the WHERE clause
    String[] selectionArgs = {contactName};

    // Here's an example: SELECT * FROM message INNER JOIN contact ON message.contact_id =
    // contact._id WHERE contact.name LIKE ? ORDER BY timestamp ASC
    String sqlQuery =
        "SELECT * FROM "
            + DatabaseContract.MessageEntry.TABLE_NAME
            + " INNER JOIN "
            + DatabaseContract.ContactEntry.TABLE_NAME
            + " ON message."
            + DatabaseContract.MessageEntry.COLUMN_NAME_CONTACT_ID
            + " = contact."
            + DatabaseContract.ContactEntry._ID
            + " "
            + "WHERE "
            + DatabaseContract.ContactEntry.TABLE_NAME
            + "."
            + DatabaseContract.ContactEntry.COLUMN_NAME_NAME
            + " LIKE ? "
            + "ORDER BY "
            + DatabaseContract.MessageEntry.COLUMN_NAME_TIMESTAMP
            + " ASC";

    Log.i(TAG, "Query String: " + sqlQuery);
    Cursor cursor = db.rawQuery(sqlQuery, selectionArgs);

    ArrayList<Map<String, String>> messageList = new ArrayList<Map<String, String>>();

    // moveToFirst() fails if cursor is empty
    if (cursor.moveToFirst()) {
      // iterate the rows, read from db and populate contactList
      do {
        messageList.add(
            createMessageEntry(
                cursor.getString(
                    cursor.getColumnIndexOrThrow(DatabaseContract.MessageEntry.COLUMN_NAME_TYPE)),
                cursor.getString(
                    cursor.getColumnIndexOrThrow(DatabaseContract.ContactEntry.COLUMN_NAME_NAME)),
                cursor.getString(
                    cursor.getColumnIndexOrThrow(DatabaseContract.MessageEntry.COLUMN_NAME_TEXT))));
      } while (cursor.moveToNext());
    }
    cursor.close();

    return messageList;
  }
示例#30
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Log.v("mk", "query(), uri = " + uri);
    // Constructs a new query builder and sets its table name
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(FiltersList.Filter.TABLE_NAME);

    switch (sUriMatcher.match(uri)) {
        // If the incoming URI is for notes, chooses the Notes projection
      case FILTERS:
        Log.v("mk", "match FILTERS");
        qb.setProjectionMap(sFiltersProjectionMap);
        break;
      case FILTERS_ID:
        Log.v("mk", "match FILTERS_ID");
        qb.setProjectionMap(sFiltersProjectionMap);
        qb.appendWhere(
            FiltersList.Filter._ID
                + // the name of the ID column
                "="
                +
                // the position of the note ID itself in the incoming URI
                uri.getPathSegments().get(FiltersList.Filter.FILTER_ID_PATH_POSITION));
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    String orderBy;
    if (TextUtils.isEmpty(sortOrder)) {
      orderBy = FiltersList.Filter.DEFAULT_SORT_ORDER;
    } else {
      orderBy = sortOrder;
    }

    // Opens the database object in "read" mode, since no writes need to be done.
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    Cursor c =
        qb.query(
            db, // The database to query
            projection, // The columns to return from the query
            selection, // The columns for the where clause
            selectionArgs, // The values for the where clause
            null, // don't group the rows
            null, // don't filter by row groups
            orderBy // The sort order
            );

    // Tells the Cursor what URI to watch, so it knows when its source data changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
  }