Package android.database

Examples of android.database.Cursor


    return update(statement, args, argFieldTypes);
  }

  public <T> Object queryForOne(String statement, Object[] args, FieldType[] argFieldTypes,
      GenericRowMapper<T> rowMapper) throws SQLException {
    Cursor cursor = null;

    try {
      cursor = db.rawQuery(statement, toStrings(args));
      AndroidDatabaseResults results = new AndroidDatabaseResults(cursor);
      if (!results.next()) {
        return null;
      } else {
        T first = rowMapper.mapRow(results);
        if (results.next()) {
          return MORE_THAN_ONE;
        } else {
          return first;
        }
      }
    } catch (android.database.SQLException e) {
      throw SqlExceptionUtil.create("queryForOne from database failed: " + statement, e);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
View Full Code Here


            // db.execSQL("DROP TABLE IF EXISTS test");
            // log("dropped");
            db.execSQL("CREATE TABLE if not exists test(ID INTEGER PRIMARY KEY, NAME VARCHAR)");
            log("created");
            for (int j = 0; j < 10; j++) {
                Cursor c = db.rawQuery("select * from test", new String[0]);
                int count = c.getCount();
                for (int i = 0; i < count; i++) {
                    c.move(1);
                    c.getInt(0);
                    c.getString(1);
                }
                c.close();
            }
            // log("select " + count);
            db.execSQL("delete from test");
            log("delete");
            db.beginTransaction();
            for (int i = 0; i < 1000; i++) {
                db.execSQL("INSERT INTO TEST VALUES(?, 'Hello')", new Object[] { i });
            }
            db.setTransactionSuccessful();
            db.endTransaction();
            log("inserted");
            for (int i = 0; i < 10; i++) {
                Cursor c = db.rawQuery("select * from test where id=?", new String[] { "" + i });
                int count = c.getCount();
                if (count > 0) {
                    c.move(1);
                    c.getInt(0);
                    c.getString(1);
                }
                c.close();
            }
            log("select");
        } finally {
            db.close();
            log("closed");
View Full Code Here

    /**
     * Store highest image id from image table
     */
    private void setMaxIdFromDatabase() {
        String columns[] = new String[]{Media._ID, Media.DISPLAY_NAME, Media.MINI_THUMB_MAGIC};
        Cursor cursor = managedQuery( Media.EXTERNAL_CONTENT_URI, columns, null, null, Media._ID + " DESC" );
        maxId = cursor.moveToFirst() ? cursor.getInt( cursor.getColumnIndex( Media._ID ) ) : -1;
    }
View Full Code Here

     *
     * @return highest image id in database or -1 if conditions fail
     */
    public int getId() {
        String[] columns = new String[]{Media._ID, Media.ORIENTATION};
        Cursor cursor = application.managedQuery( Media.EXTERNAL_CONTENT_URI, columns, null, null, Media._ID + " DESC" );

        // check if table has any rows at all
        if( !cursor.moveToFirst() ) {
            return -1;
        }

        // get latest id from db and stored id in application
        latestId = cursor.getInt( cursor.getColumnIndex( Media._ID ) );
        int maxId = application.getMaxId();

        // if id from db is equal or lower to stored id it means user changed or
        // deleted somewhere in table so store the new highest id and return
        if( latestId <= maxId ) {
            application.setMaxId( latestId );
            return -1;
        }

        // If orientation is null it means new image is not a photo but we will
        // store highest id and return
        String orientation = cursor.getString( cursor.getColumnIndex( Media.ORIENTATION ) );

        if( orientation == null ) {
            application.setMaxId( latestId );
            return -1;
        }
View Full Code Here

        // loop until break
        while( true ) {
            // get latest image from table
            Uri image = ContentUris.withAppendedId( Media.EXTERNAL_CONTENT_URI, latestId );
            Cursor cursor = application.managedQuery( image, columns, null, null, null );

            // check if cursus has rows, if not break and exit loop
            if( cursor.moveToFirst() ) {
                // get thumbnail field
                String imageThumb = cursor.getString( cursor.getColumnIndex( Media.MINI_THUMB_MAGIC ) );

                // if thumbnail field is not null it means image is written to sdcard
                // create new image item and break loop otherwise restart loop to check again
                if( imageThumb != null ) {
                    item = new ImageItem();
                    item.imageId = cursor.getInt( cursor.getColumnIndex( Media._ID ) );
                    item.imagePath = cursor.getString( cursor.getColumnIndex( Media.DATA ) );
                    item.imageName = cursor.getString( cursor.getColumnIndex( Media.DISPLAY_NAME ) );
                    item.imageType = cursor.getString( cursor.getColumnIndex( Media.MIME_TYPE ) );
                    item.imageSize = cursor.getInt( cursor.getColumnIndex( Media.SIZE ) );

                    break;
                }
            } else {
                break;
View Full Code Here

TOP

Related Classes of android.database.Cursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.