Search in sources :

Example 41 with SQLException

use of android.database.SQLException in project zxing by zxing.

the class HistoryManager method deleteHistoryItem.

public void deleteHistoryItem(int number) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getWritableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
        cursor.move(number + 1);
        db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
    } catch (SQLException sqle) {
        Log.w(TAG, sqle);
    } finally {
        close(cursor, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 42 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class TestModule method addNativeContactMethod.

public NativeDetail addNativeContactMethod(ContentResolver cr, int id, int kind, boolean isPrimary) {
    ContentValues cv = new ContentValues();
    cv.put(Contacts.ContactMethods.PERSON_ID, id);
    String data = null;
    switch(kind) {
        case CONTACT_METHODS_KIND_EMAIL:
            data = "testtesttest@test.com";
            break;
        case CONTACT_METHODS_KIND_ADDRESS:
            data = generateNativeAddress();
            break;
        default:
            data = generateRandomString();
            break;
    }
    int type = generateRandomInt() & 3;
    if (type == 0) {
        cv.put(Contacts.ContactMethods.LABEL, generateRandomString());
    }
    cv.put(Contacts.ContactMethods.DATA, data);
    cv.put(Contacts.ContactMethods.TYPE, type);
    cv.put(Contacts.ContactMethods.KIND, kind);
    cv.put(Contacts.ContactMethods.ISPRIMARY, (isPrimary ? 1 : 0));
    Uri uriCm;
    try {
        uriCm = cr.insert(Contacts.ContactMethods.CONTENT_URI, cv);
        if (uriCm == null) {
            return null;
        }
    } catch (SQLException e) {
        return null;
    }
    NativeDetail nd = new NativeDetail();
    nd.mValue1 = data;
    nd.mValue2 = String.valueOf(kind);
    nd.mValue3 = String.valueOf(type);
    nd.mIsPrimary = isPrimary;
    nd.mId = (int) ContentUris.parseId(uriCm);
    return nd;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 43 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class TestModule method addNativeOrg.

public boolean addNativeOrg(ContentResolver cr, int id, boolean isPrimary, List<NativeDetail> orgList, List<NativeDetail> titleList) {
    ContentValues cv = new ContentValues();
    String company = generateRandomString();
    String title = generateRandomString();
    int type = generateRandomInt() % 3;
    if (type == 0) {
        cv.put(Contacts.Organizations.LABEL, generateRandomString());
    }
    cv.put(Contacts.Organizations.PERSON_ID, id);
    cv.put(Contacts.Organizations.COMPANY, company);
    cv.put(Contacts.Organizations.TITLE, title);
    cv.put(Contacts.Organizations.TYPE, type);
    cv.put(Contacts.Organizations.ISPRIMARY, (isPrimary ? 1 : 0));
    Uri uriOrg;
    try {
        uriOrg = cr.insert(Contacts.Organizations.CONTENT_URI, cv);
        if (uriOrg == null) {
            return false;
        }
    } catch (SQLException e) {
        return false;
    }
    NativeDetail ndOrg = new NativeDetail();
    ndOrg.mValue1 = company;
    ndOrg.mValue2 = null;
    ndOrg.mValue3 = String.valueOf(type);
    ndOrg.mIsPrimary = isPrimary;
    ndOrg.mId = (int) ContentUris.parseId(uriOrg);
    orgList.add(ndOrg);
    NativeDetail ndTitle = new NativeDetail();
    ndTitle.mValue1 = title;
    ndTitle.mValue2 = null;
    ndTitle.mValue3 = null;
    ndTitle.mIsPrimary = false;
    ndTitle.mId = (int) ContentUris.parseId(uriOrg);
    titleList.add(ndTitle);
    return true;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 44 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class TestModule method addNativeContact.

public NativeContactDetails addNativeContact(ContentResolver cr, NativeNameType nameType, boolean withNote, int phones, int emails, int addresses, int orgs) {
    NativeContactDetails ncd = new NativeContactDetails();
    ncd.mName = createDummyName();
    ncd.mName.midname = generateRandomString();
    switch(nameType) {
        case NO_NAME:
            ncd.mName.firstname = null;
        // Fall through
        case SINGLE_NAME:
            ncd.mName.surname = null;
        // Fall through
        case DOUBLE_NAME:
            ncd.mName.midname = null;
        // Fall through
        case FULL_NAME_NO_TITLE:
            ncd.mName.title = null;
        // Fall through
        case FULL_NAME:
            break;
    }
    ContentValues cv = new ContentValues();
    cv.put(Contacts.People.NAME, ncd.mName.toString());
    if (withNote) {
        String randomString = new String();
        for (int i = 0; i < generateRandomInt() % 10; i++) {
            randomString += generateRandomString() + " ";
        }
        cv.put(Contacts.People.NOTES, randomString);
        ncd.mNote = randomString;
    }
    Uri peopleResult;
    try {
        peopleResult = cr.insert(Contacts.People.CONTENT_URI, cv);
        if (peopleResult == null) {
            return null;
        }
    } catch (SQLException e) {
        return null;
    }
    int id = (int) ContentUris.parseId(peopleResult);
    ncd.mId = id;
    for (int i = 0; i < phones; i++) {
        NativeDetail nd = addNativePhone(cr, id, (i == 0));
        if (nd == null) {
            return null;
        }
        ncd.mPhoneList.add(nd);
    }
    for (int i = 0; i < emails; i++) {
        NativeDetail nd = addNativeContactMethod(cr, id, CONTACT_METHODS_KIND_EMAIL, (i == 0));
        if (nd == null) {
            return null;
        }
        ncd.mEmailList.add(nd);
    }
    for (int i = 0; i < addresses; i++) {
        NativeDetail nd = addNativeContactMethod(cr, id, CONTACT_METHODS_KIND_ADDRESS, (i == 0));
        if (nd == null) {
            return null;
        }
        ncd.mAddressList.add(nd);
    }
    for (int i = 0; i < orgs; i++) {
        if (!addNativeOrg(cr, id, (i == 0), ncd.mOrgList, ncd.mTitleList)) {
            return null;
        }
    }
    return ncd;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 45 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class TestModule method fetchSyncServerId.

public static Long fetchSyncServerId(Long localDetailID, SQLiteDatabase readableDb) {
    Long value = null;
    try {
        Cursor c = readableDb.rawQuery("SELECT " + Field.SERVERSYNCCONTACTID + " FROM ContactDetails WHERE " + Field.DETAILLOCALID + "=" + localDetailID, null);
        if (c.moveToFirst()) {
            if (!c.isNull(0)) {
                value = c.getLong(0);
            }
        }
        c.close();
    } catch (SQLException e) {
    }
    return value;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Aggregations

SQLException (android.database.SQLException)224 ContentValues (android.content.ContentValues)114 Uri (android.net.Uri)60 Cursor (android.database.Cursor)57 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)39 SQLiteException (android.database.sqlite.SQLiteException)18 Intent (android.content.Intent)16 ArrayList (java.util.ArrayList)14 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 HandlerThread (android.os.HandlerThread)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3