Example usage for android.database.sqlite SQLiteDatabase insertWithOnConflict

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

Introduction

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

Prototype

public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues,
        int conflictAlgorithm) 

Source Link

Document

General method for inserting a row into the database.

Usage

From source file:github.popeen.dsub.util.SongDBHandler.java

protected synchronized void addSongsImpl(SQLiteDatabase db, int serverKey, List<Pair<String, String>> entries) {
    db.beginTransaction();/*from  w w  w  . j a va  2s.c o m*/
    try {
        for (Pair<String, String> entry : entries) {
            ContentValues values = new ContentValues();
            values.put(SONGS_SERVER_KEY, serverKey);
            values.put(SONGS_SERVER_ID, entry.getFirst());
            values.put(SONGS_COMPLETE_PATH, entry.getSecond());

            db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        }

        db.setTransactionSuccessful();
    } catch (Exception e) {
    }

    db.endTransaction();
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void insert(T item, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {//ww w  . jav a2  s.c  o m
        db.beginTransaction();
        db.insertWithOnConflict(mTableName, null, itemToRow(item), conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void insert(SQLiteDatabase db, ObjectNode item, int conflictAlgorithm)
        throws IllegalAccessException, ParseException {
    db.insertWithOnConflict(mTableName, null, jsonToRow(item), conflictAlgorithm);
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void insert(List<T> items, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {/*from   ww w . j a v  a 2 s .  c om*/
        db.beginTransaction();
        for (T item : items)
            db.insertWithOnConflict(mTableName, null, itemToRow(item), conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:org.qeo.android.service.ApplicationSecurityStandalone.java

@Override
public void insertAppInfo() {
    if (mAppName == null) {
        throw new SecurityException("\"appname\" not set in security manifest");
    }/*from  w ww.  j a va2 s. c  o  m*/
    if (mVersion == -1) {
        throw new SecurityException("\"version\" not set in security manifest");
    }
    SQLiteDatabase db = mService.getDatabase();
    ContentValues values = new ContentValues();
    values.put(TableManifestMeta.C_ID, mUid);
    values.put(TableManifestMeta.C_PKG_NAME, mPkgName);
    values.put(TableManifestMeta.C_APP_NAME, mAppName);
    values.put(TableManifestMeta.C_VERSION, mVersion);
    values.put(TableManifestMeta.C_APP_VERSION, mAppVersion);
    db.insertWithOnConflict(TableManifestMeta.NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
    mAppName = null;
    mVersion = 0;
}

From source file:org.qeo.android.service.ApplicationSecurity.java

/**
 * Insert manifest appinfo block the database. Clear the mAppName and mVersion when everything is saved in the
 * database.// w ww  . jav  a2 s .c  o m
 */
public void insertAppInfo() {
    if (mAppName == null) {
        throw new SecurityException("\"appname\" not set in security manifest");
    }
    if (mVersion == -1) {
        throw new SecurityException("\"version\" not set in security manifest");
    }
    SQLiteDatabase db = mService.getDatabase();
    ContentValues values = new ContentValues();
    values.put(TableManifestMeta.C_ID, mUid);
    values.put(TableManifestMeta.C_PKG_NAME, mPkgName);
    values.put(TableManifestMeta.C_APP_NAME, mAppName);
    values.put(TableManifestMeta.C_VERSION, mVersion);
    values.put(TableManifestMeta.C_APP_VERSION, mAppVersion);
    db.insertWithOnConflict(TableManifestMeta.NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
    mAppName = null;
    mVersion = 0;
}

From source file:github.popeen.dsub.util.SongDBHandler.java

public void importData(JSONArray array) {
    SQLiteDatabase db = this.getReadableDatabase();
    try {/*ww  w .j  a v  a2  s .  c  om*/
        for (int i = 0; i < array.length(); i++) {
            JSONObject row = array.getJSONObject(i);
            ContentValues values = new ContentValues();
            values.put(SONGS_ID, row.getInt("SONGS_ID"));
            values.put(SONGS_SERVER_KEY, row.getInt("SONGS_SERVER_KEY"));
            values.put(SONGS_SERVER_ID, row.getString("SONGS_SERVER_ID"));
            values.put(SONGS_COMPLETE_PATH, row.getString("SONGS_COMPLETE_PATH"));
            values.put(SONGS_LAST_PLAYED, row.getInt("SONGS_LAST_PLAYED"));
            values.put(SONGS_LAST_COMPLETED, row.getInt("SONGS_LAST_COMPLETED"));
            db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        }
    } catch (Exception e) {
    }
}

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

public void insertIngredients(ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {//from  w  ww  . j  a  v a  2  s. c o m
            db.insertWithOnConflict(INGREDIENTS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}

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

public void insertDirections(ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {//from  www  .  j av a  2 s . c o  m
            db.insertWithOnConflict(DIRECTIONS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}

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

public void insertTags(ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {/*  w  ww .  j a v a2s .c o  m*/
            db.insertWithOnConflict(TAGS_TABLE, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}