Example usage for android.database.sqlite SQLiteDatabase insert

List of usage examples for android.database.sqlite SQLiteDatabase insert

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase insert.

Prototype

public long insert(String table, String nullColumnHack, ContentValues values) 

Source Link

Document

Convenience method for inserting a row into the database.

Usage

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public boolean addPendingNotification(PendingNotification pendingNotification) {
    String appInfo = pendingNotification.app_info;
    String permissions = pendingNotification.permission;
    String appName = pendingNotification.app_name;
    int notificationId = pendingNotification.id;
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_APP_INFO, appInfo);//from  w w w .jav  a  2s  .  co m
    values.put(KEY_APP_NAME, appName);
    values.put(KEY_PERMISSIONS, permissions);
    values.put(KEY_NOTIFICATION_ID, notificationId);
    int id = (int) db.insert(TABLE_PENDING_NOTIFICATIONS, null, values);
    return id >= 0;
}

From source file:export.UploadManager.java

private void uploadOK(Uploader uploader, ProgressDialog copySpinner, SQLiteDatabase copyDB, long id) {
    copySpinner.setMessage("Saving");
    ContentValues tmp = new ContentValues();
    tmp.put(Constants.DB.EXPORT.ACCOUNT, uploader.getId());
    tmp.put(Constants.DB.EXPORT.ACTIVITY, id);
    tmp.put(Constants.DB.EXPORT.STATUS, 0);
    copyDB.insert(Constants.DB.EXPORT.TABLE, null, tmp);
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public int createResponseFilter(ResponseFilter responseFilter) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_CONTENT, responseFilter.getContent().trim());
    values.put(KEY_SOURCE, responseFilter.getSource());
    values.put(KEY_MODIFIED, getDateTime());

    // insert row
    int id = (int) db.insert(TABLE_RESPONSE_FILTERS, null, values);

    return id;/*from w w w .  j ava 2s  . co m*/
}

From source file:com.maxwen.wallpaper.board.databases.Database.java

public void addWallpapers(@NonNull List<Wallpaper> wallpapers) {
    SQLiteDatabase db = this.getWritableDatabase();
    long insertTime = System.currentTimeMillis();
    for (int i = 0; i < wallpapers.size(); i++) {
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, wallpapers.get(i).getName());
        values.put(KEY_AUTHOR, wallpapers.get(i).getAuthor());
        values.put(KEY_URL, wallpapers.get(i).getUrl());
        values.put(KEY_THUMB_URL, wallpapers.get(i).getThumbUrl());
        values.put(KEY_CATEGORY, wallpapers.get(i).getCategory());
        values.put(KEY_ADDED_ON, insertTime);

        db.insert(TABLE_WALLPAPERS, null, values);
    }/*ww w  .  j a  v  a 2 s  . c o m*/
    db.close();
}

From source file:org.runnerup.export.UploadManager.java

private void uploadOK(Uploader uploader, ProgressDialog copySpinner, SQLiteDatabase copyDB, long id) {
    copySpinner.setMessage(getResources().getString(R.string.saving));
    ContentValues tmp = new ContentValues();
    tmp.put(DB.EXPORT.ACCOUNT, uploader.getId());
    tmp.put(DB.EXPORT.ACTIVITY, id);/*from   w w  w  . j  a va2s  .c  om*/
    tmp.put(DB.EXPORT.STATUS, 0);
    copyDB.insert(DB.EXPORT.TABLE, null, tmp);
}

From source file:com.appsimobile.appsii.module.home.provider.HomeContentProvider.java

@Override
public int bulkInsert(Uri uri, @NonNull ContentValues[] values) {
    SqlArguments args = new SqlArguments(uri);

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    db.beginTransaction();//from  w  w  w  . ja  v  a  2  s  . co m
    try {
        int numValues = values.length;
        for (int i = 0; i < numValues; i++) {
            ContentValues value = values[i];
            if (db.insert(args.table, null, value) < 0)
                return 0;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    sendNotify(uri);
    return values.length;
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public int createDomainFilter(DomainFilter domainFilter) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_CONTENT, domainFilter.getContent().trim());
    values.put(KEY_SOURCE, domainFilter.getSource());
    values.put(KEY_WILDCARD, domainFilter.getWildcard());
    values.put(KEY_MODIFIED, getDateTime());

    // insert row
    int id = (int) db.insert(TABLE_DOMAIN_FILTERS, null, values);

    return id;//from w w w  .  j  a  v  a 2  s  .  com
}

From source file:com.maxwen.wallpaper.board.databases.Database.java

public void addWallpapers(@NonNull WallpaperJson wallpapers) {
    SQLiteDatabase db = this.getWritableDatabase();
    long insertTime = System.currentTimeMillis();
    for (int i = 0; i < wallpapers.getWallpapers.size(); i++) {
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, wallpapers.getWallpapers.get(i).name);
        values.put(KEY_AUTHOR, wallpapers.getWallpapers.get(i).author);
        values.put(KEY_URL, wallpapers.getWallpapers.get(i).url);
        values.put(KEY_THUMB_URL, wallpapers.getWallpapers.get(i).thumbUrl);
        values.put(KEY_CATEGORY, wallpapers.getWallpapers.get(i).category);
        values.put(KEY_ADDED_ON, insertTime);

        db.insert(TABLE_WALLPAPERS, null, values);
    }/*from  ww  w  .  j av  a 2s.  co m*/
    db.close();
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

private void handleResponse() {
    Log.i(this.getClass().getName(), "in handleResponse()");
    // close progress notification
    mNotificationManager.cancel(NOTIFICATION_ID);

    String notificationMessage = getString(R.string.upload_success);

    // notification intent with result
    final Intent notificationIntent = new Intent(getBaseContext(), ImageDetails.class);

    if (mImgurResponse == null) {
        notificationMessage = getString(R.string.connection_failed);
    } else if (mImgurResponse.get("error") != null) {
        notificationMessage = getString(R.string.unknown_error) + mImgurResponse.get("error");
    } else {//from  www.  j  av  a 2s.  c  o  m
        // create thumbnail
        if (mImgurResponse.get("image_hash").length() > 0) {
            createThumbnail(imageLocation);
        }

        // store result in database
        final HistoryDatabase histData = new HistoryDatabase(getBaseContext());
        final SQLiteDatabase data = histData.getWritableDatabase();

        final HashMap<String, String> dataToSave = new HashMap<String, String>();
        dataToSave.put("delete_hash", mImgurResponse.get("delete_hash"));
        dataToSave.put("image_url", mImgurResponse.get("original"));
        final Uri imageUri = Uri
                .parse(getFilesDir() + "/" + mImgurResponse.get("image_hash") + THUMBNAIL_POSTFIX);
        dataToSave.put("local_thumbnail", imageUri.toString());
        dataToSave.put("upload_time", "" + System.currentTimeMillis());

        for (final Map.Entry<String, String> entry : dataToSave.entrySet()) {
            final ContentValues content = new ContentValues();
            content.put("hash", mImgurResponse.get("image_hash"));
            content.put("key", entry.getKey());
            content.put("value", entry.getValue());
            data.insert("imgur_history", null, content);
        }

        //set intent to go to image details
        notificationIntent.putExtra("hash", mImgurResponse.get("image_hash"));
        notificationIntent.putExtra("image_url", mImgurResponse.get("original"));
        notificationIntent.putExtra("delete_hash", mImgurResponse.get("delete_hash"));
        notificationIntent.putExtra("local_thumbnail", imageUri.toString());

        data.close();
        histData.close();

        // if the main activity is already open then refresh the gridview
        sendBroadcast(new Intent(BROADCAST_ACTION));
    }

    //assemble notification
    final Notification notification = new Notification(R.drawable.icon, notificationMessage,
            System.currentTimeMillis());
    notification.setLatestEventInfo(this, getString(R.string.app_name), notificationMessage, PendingIntent
            .getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:net.potterpcs.recipebook.RecipeData.java

public void insertCacheEntry(String uri, String cached) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(CT_URI, uri);/*from w ww  . ja  v  a  2s.  com*/
        values.put(CT_CACHED, cached);

        if (isCached(uri)) {
            db.update(CACHE_TABLE, values, CT_URI + " = ?", new String[] { cached });
        } else {
            db.insert(CACHE_TABLE, null, values);
        }
    }
}