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:com.rener.sea.DBHelper.java

private long setLocation(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;//ww  w . j a v  a  2  s . c  o m
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);

            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.LOCATION_ID))
                values.put(DBSchema.LOCATION_ID, item.getLong(DBSchema.LOCATION_ID));
            if (!item.isNull(DBSchema.LOCATION_NAME))
                values.put(DBSchema.LOCATION_NAME, item.getString(DBSchema.LOCATION_NAME));
            if (!item.isNull(DBSchema.LOCATION_ADDRESS_ID))
                values.put(DBSchema.LOCATION_ADDRESS_ID, item.getLong(DBSchema.LOCATION_ADDRESS_ID));
            if (!item.isNull(DBSchema.LOCATION_OWNER_ID))
                values.put(DBSchema.LOCATION_OWNER_ID, item.getLong(DBSchema.LOCATION_OWNER_ID));
            if (!item.isNull(DBSchema.LOCATION_MANAGER_ID))
                values.put(DBSchema.LOCATION_MANAGER_ID, item.getLong(DBSchema.LOCATION_MANAGER_ID));
            if (!item.isNull(DBSchema.LOCATION_LICENSE))
                values.put(DBSchema.LOCATION_LICENSE, item.getString(DBSchema.LOCATION_LICENSE));
            if (!item.isNull(DBSchema.LOCATION_AGENT_ID))
                values.put(DBSchema.LOCATION_AGENT_ID, item.getLong(DBSchema.LOCATION_AGENT_ID));
            if (!item.isNull(DBSchema.STATUS))
                values.put(DBSchema.STATUS, item.getLong(DBSchema.STATUS));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);

            db.insertWithOnConflict(DBSchema.TABLE_LOCATION, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.rener.sea.DBHelper.java

private long setReport(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;//  w  ww. ja  va 2 s . c o  m
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);

            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.REPORT_ID))
                values.put(DBSchema.REPORT_ID, item.getLong(DBSchema.REPORT_ID));
            if (!item.isNull(DBSchema.REPORT_CREATOR_ID))
                values.put(DBSchema.REPORT_CREATOR_ID, item.getLong(DBSchema.REPORT_CREATOR_ID));
            if (!item.isNull(DBSchema.REPORT_LOCATION_ID))
                values.put(DBSchema.REPORT_LOCATION_ID, item.getLong(DBSchema.REPORT_LOCATION_ID));
            // if(!item.isNull(DBSchema.REPORT_SUBJECT_ID))
            //                values.put(DBSchema.REPORT_SUBJECT_ID, item.getLong(DBSchema.REPORT_SUBJECT_ID));
            if (!item.isNull(DBSchema.REPORT_FLOWCHART_ID))
                values.put(DBSchema.REPORT_FLOWCHART_ID, item.getLong(DBSchema.REPORT_FLOWCHART_ID));
            if (!item.isNull(DBSchema.REPORT_NOTE))
                values.put(DBSchema.REPORT_NOTE, item.getString(DBSchema.REPORT_NOTE));
            if (!item.isNull(DBSchema.REPORT_DATE_FILED))
                values.put(DBSchema.REPORT_DATE_FILED, item.getString(DBSchema.REPORT_DATE_FILED));
            if (!item.isNull(DBSchema.REPORT_NAME))
                values.put(DBSchema.REPORT_NAME, item.getString(DBSchema.REPORT_NAME));
            if (!item.isNull(DBSchema.REPORT_STATUS))
                values.put(DBSchema.REPORT_STATUS, item.getLong(DBSchema.REPORT_STATUS));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);

            db.insertWithOnConflict(DBSchema.TABLE_REPORT, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}

From source file:com.rener.sea.DBHelper.java

private long setPerson(JSONArray data) {
    SQLiteDatabase db = this.getWritableDatabase();
    int i = -1;/* w w  w.  j a v a 2  s  .c o  m*/
    try {
        for (i = 0; i < data.length(); i++) {
            JSONObject item = data.getJSONObject(i);

            ContentValues values = new ContentValues();
            if (!item.isNull(DBSchema.PERSON_ID))
                values.put(DBSchema.PERSON_ID, item.getLong(DBSchema.PERSON_ID));
            if (!item.isNull(DBSchema.PERSON_LAST_NAME1))
                values.put(DBSchema.PERSON_LAST_NAME1, item.getString(DBSchema.PERSON_LAST_NAME1));
            if (!item.isNull(DBSchema.PERSON_FIRST_NAME))
                values.put(DBSchema.PERSON_FIRST_NAME, item.getString(DBSchema.PERSON_FIRST_NAME));
            if (!item.isNull(DBSchema.PERSON_EMAIL))
                values.put(DBSchema.PERSON_EMAIL, item.getString(DBSchema.PERSON_EMAIL));
            // if(!item.isNull(DBSchema.PERSON_SPEC_ID))
            //                values.put(DBSchema.PERSON_SPEC_ID, item.getLong(DBSchema.PERSON_SPEC_ID));
            if (!item.isNull(DBSchema.PERSON_LAST_NAME2))
                values.put(DBSchema.PERSON_LAST_NAME2, item.getString(DBSchema.PERSON_LAST_NAME2));
            if (!item.isNull(DBSchema.PERSON_MIDDLE_INITIAL))
                values.put(DBSchema.PERSON_MIDDLE_INITIAL, item.getString(DBSchema.PERSON_MIDDLE_INITIAL));
            if (!item.isNull(DBSchema.PERSON_PHONE_NUMBER))
                values.put(DBSchema.PERSON_PHONE_NUMBER, item.getString(DBSchema.PERSON_PHONE_NUMBER));
            if (!item.isNull(DBSchema.STATUS))
                values.put(DBSchema.STATUS, item.getString(DBSchema.STATUS));
            values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO);

            db.insertWithOnConflict(DBSchema.TABLE_PERSON, null, values, 5);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    db.close();
    return i;
}