当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteConstraintException类代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteConstraintException的典型用法代码示例。如果您正苦于以下问题:Java SQLiteConstraintException类的具体用法?Java SQLiteConstraintException怎么用?Java SQLiteConstraintException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SQLiteConstraintException类属于android.database.sqlite包,在下文中一共展示了SQLiteConstraintException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readExceptionFromParcel

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) {
    switch (code) {
        case 2:
            throw new IllegalArgumentException(msg);
        case 3:
            throw new UnsupportedOperationException(msg);
        case 4:
            throw new SQLiteAbortException(msg);
        case 5:
            throw new SQLiteConstraintException(msg);
        case 6:
            throw new SQLiteDatabaseCorruptException(msg);
        case 7:
            throw new SQLiteFullException(msg);
        case 8:
            throw new SQLiteDiskIOException(msg);
        case 9:
            throw new SQLiteException(msg);
        case 11:
            throw new OperationCanceledException(msg);
        default:
            reply.readException(code, msg);
    }
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:25,代码来源:ShadowDatabaseUtils.java

示例2: insert

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    MovieUriEnum matchingUriEnum = mUriMatcher.matchUri(uri);

    if (matchingUriEnum.table != null) {
        try {
            db.insertOrThrow(matchingUriEnum.table, null, values);
        } catch (SQLiteConstraintException e) {
            throw e;
        }
    }

    switch (matchingUriEnum) {
        case MOVIES:
            return Movies.buildMovieUri(values.getAsString(Movies.MOVIE_ID));
        case TVS:
            return TVs.buildTVUri(values.getAsString(TVs.TV_ID));
        case PERSONS:
            return Persons.buildPersonUri(values.getAsString(Persons.PERSON_ID));
        default:
            throw new UnsupportedOperationException("Unknown insert URI: " + uri);
    }
}
 
开发者ID:qqq3,项目名称:inventum,代码行数:26,代码来源:MovieProvider.java

示例3: getTask

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
/**
 * Returns a Task (with Reminder and Attachments) given a taskId
 * @param taskId    The ID of the Task to get.
 */
public Task getTask(int taskId) throws CouldNotGetDataException, SQLiteConstraintException {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    Cursor cursor = db.query(RemindyContract.TaskTable.TABLE_NAME, null, RemindyContract.PlaceTable._ID + "=?",
            new String[]{String.valueOf(taskId)}, null, null, null);

    if (cursor.getCount() == 0)
        throw new CouldNotGetDataException("Specified Task not found in the database. Passed id=" + taskId);
    if (cursor.getCount() > 1)
        throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one record found. Passed value=" + taskId);

    cursor.moveToNext();
    Task task = getTaskFromCursor(cursor);
    task.setAttachments(getAttachmentsOfTask(taskId));

    if(task.getReminderType() != ReminderType.NONE)
        task.setReminder(getReminderOfTask(taskId, task.getReminderType()));
    return task;
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:23,代码来源:RemindyDAO.java

示例4: insertEmoticonBean

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
public synchronized long insertEmoticonBean(EmoticonBean bean, String beanSetName) {
    SQLiteDatabase db = mOpenDbHelper.getWritableDatabase();
    long result = -1;
    if (bean == null || db == null) {
        return result;
    }
    ContentValues values = new ContentValues();
    values.put(TableColumns.EmoticonColumns.EVENT_TYPE, bean.getEventType());
    values.put(TableColumns.EmoticonColumns.TAG, bean.getTag());
    values.put(TableColumns.EmoticonColumns.NAME, bean.getName());
    values.put(TableColumns.EmoticonColumns.ICON_URI, bean.getIconUri());
    values.put(TableColumns.EmoticonColumns.MSG_URI, bean.getMsgUri());
    values.put(TableColumns.EmoticonColumns.EMOTICON_SET_NAME, beanSetName);
    try {
        result = db.insert(TABLE_NAME_EMOTICONS, null, values);
    } catch (SQLiteConstraintException e) {
        Log.e(TAG, "insert failed", e);
    }
    return result;
}
 
开发者ID:yangchaojiang,项目名称:ChatKeyboard-master,代码行数:21,代码来源:EmoticonDBHelper.java

示例5: addNewUser

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
public void addNewUser()
{
    User person = new User();
    person.setFirstname(getData(txtFirstname));
    person.setAge(getData(txtAge));
    person.setNic(getData(txtNIC));
    person.setSurname(getData(txtSurname));
    try {
        long f = user.insert(person);

        if (f > 0) {
            showToast("User added");
            clearAllTextData();
        }
        else
        {
            showToast("User not added");
        }
    }
    catch (SQLiteConstraintException e)
    {
        showToast("User with the same NFC id Exists");
    }
}
 
开发者ID:tawaasalage,项目名称:GreenDAOCrud,代码行数:25,代码来源:UserCRUD.java

示例6: testStatementConstraint

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
@MediumTest
public void testStatementConstraint() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");

    // Try to insert NULL, which violates the constraint
    try {
        statement.clearBindings();
        statement.execute();
        fail("expected exception not thrown");
    } catch (SQLiteConstraintException e) {
        // expected
    }

    // Make sure the statement can still be used
    statement.bindLong(1, 1);
    statement.execute();
    statement.close();

    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    long num = c.getLong(numCol);
    assertEquals(1, num);
    c.close();
}
 
开发者ID:doppllib,项目名称:core-doppl,代码行数:27,代码来源:DatabaseStatementTest.java

示例7: insertAchievementExplorer

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
public boolean insertAchievementExplorer(final Context preferenceContext, String email, int idAchievement) {
    try{
        setAction(false);
        AchievementExplorerRequest achievementExplorerRequest = new AchievementExplorerRequest(email, idAchievement);
        achievementExplorerRequest.requestUpdateAchievements(preferenceContext, new AchievementExplorerRequest.Callback() {
            @Override
            public void callbackResponse(boolean response) {
                setResponse(true);
                setAction(true);
            }

            @Override
            public void callbackResponse(List<Achievement> achievements) {}
        });
    }catch(SQLiteConstraintException exception){
        exception.printStackTrace();
    }

    return true;
}
 
开发者ID:fga-gpp-mds,项目名称:2016.2-MissaoNascente,代码行数:21,代码来源:AchievementController.java

示例8: insertExplorerElement

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
public boolean insertExplorerElement(final Context preferenceContext, String email, int idElement, String userImage, String catchDate) {
    try{
        setAction(false);
        ElementExplorerRequest elementExplorerRequest = new ElementExplorerRequest(email,idElement,userImage,catchDate);
        elementExplorerRequest.requestUpdateElements(preferenceContext, new ElementExplorerRequest.Callback() {
            @Override
            public void callbackResponse(boolean response) {
                setResponse(true);
                setAction(true);
            }
            MainController mainController = new MainController();

            @Override
            public void callbackResponse(List<Element> elements) {}
        });
    }catch(SQLiteConstraintException exception){
        throw exception;
    }

    return true;
}
 
开发者ID:fga-gpp-mds,项目名称:2016.2-MissaoNascente,代码行数:22,代码来源:ExplorerController.java

示例9: insert

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
public static boolean insert(DBHelper dbHelper, NewGankData.Results data) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(Constants.DB_ITEM_DESC, data.getDesc());
        values.put(Constants.DB_ITEM_TYPE, data.getType());
        values.put(Constants.DB_ITEM_URL, data.getUrl());
        db.insert(Constants.DB_TABLE_NAME, null, values);
        db.setTransactionSuccessful();
        return true;
    } catch (SQLiteConstraintException e) {
        LogUtils.e("DBTools -> insert", "insert data error");
        return false;
    } finally {
        db.endTransaction();
    }
}
 
开发者ID:Temoa,项目名称:GankIO,代码行数:19,代码来源:DBTools.java

示例10: addUserDevice

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
/**
 * Add a new UserDevice.
 *
 * @param userDevice The new UserDevice.
 */
public void addUserDevice(UserDevice userDevice) throws DatabaseControllerException {
    try {
        databaseConnector.executeSql("insert into "
                        + DatabaseContract.UserDevice.TABLE_NAME
                        + " (" + DatabaseContract.UserDevice.COLUMN_NAME + ","
                        + DatabaseContract.UserDevice.COLUMN_FINGERPRINT + ","
                        + DatabaseContract.UserDevice.COLUMN_GROUP_ID + ") values (?, ?,("
                        + DatabaseContract.SqlQueries.GROUP_ID_FROM_NAME_SQL_QUERY + "))",
                new String[]{userDevice.getName(), userDevice.getUserDeviceID().getIDString(),
                        userDevice.getInGroup()});
    } catch (SQLiteConstraintException sqlce) {
        throw new DatabaseControllerException(
                "Either the given Group does not exist in the database"
                        + " or a UserDevice already has the given name or fingerprint.", sqlce);
    }
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:22,代码来源:UserManagementController.java

示例11: addHolidayLogEntry

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
/**
 * Add a new action to the database.
 *
 * @param action     Action to be added to the database.
 * @param moduleName Module where the action occurs.
 * @param timestamp  The timestamp of the action.
 */
public void addHolidayLogEntry(String action, String moduleName, long timestamp) throws UnknownReferenceException {
    if (Strings.isNullOrEmpty(moduleName)) {
        databaseConnector.executeSql(
                "insert into " + DatabaseContract.HolidayLog.TABLE_NAME
                        + " (" + DatabaseContract.HolidayLog.COLUMN_ACTION
                        + ", " + DatabaseContract.HolidayLog.COLUMN_TIMESTAMP + ") values (?, ?)",
                new String[]{action, String.valueOf(timestamp)}
        );
    } else {
        try {
            databaseConnector.executeSql(
                    "insert into " + DatabaseContract.HolidayLog.TABLE_NAME
                            + " (" + DatabaseContract.HolidayLog.COLUMN_ACTION
                            + ", " + DatabaseContract.HolidayLog.COLUMN_ELECTRONIC_MODULE_ID
                            + ", " + DatabaseContract.HolidayLog.COLUMN_TIMESTAMP + ") values (?,("
                            + DatabaseContract.SqlQueries.MODULE_ID_FROM_NAME_SQL_QUERY + "),?)",
                    new String[]{action, moduleName, String.valueOf(timestamp)}
            );
        } catch (SQLiteConstraintException sqlce) {
            throw new UnknownReferenceException("The given module doesn't exist.", sqlce);
        }
    }
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:31,代码来源:HolidayController.java

示例12: addModule

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
/**
 * Add a new Module.
 *
 * @param module Module to add.
 */
public void addModule(Module module) throws DatabaseControllerException {
    try {
        //Notice: Changed order of values to avoid having to concat twice!
        databaseConnector.executeSql("insert into "
                        + DatabaseContract.ElectronicModule.TABLE_NAME + " ("
                        + DatabaseContract.ElectronicModule.COLUMN_GPIO_PIN + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_USB_PORT + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_WLAN_PORT + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_WLAN_USERNAME + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_WLAN_PASSWORD + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_WLAN_IP + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_MODULE_TYPE + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_CONNECTOR_TYPE + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_SLAVE_ID + ", "
                        + DatabaseContract.ElectronicModule.COLUMN_NAME + ") values "
                        + "(?, ?, ?, ?, ?, ?, ?, ?, (" + DatabaseContract.SqlQueries.SLAVE_ID_FROM_FINGERPRINT_SQL_QUERY + "), ?)",
                ObjectArrays.concat(
                        createCombinedModulesAccessInformationFromSingle(module.getModuleAccessPoint()),
                        new String[]{module.getModuleType().toString(), module.getModuleAccessPoint().getType(),
                                module.getAtSlave().getIDString(), module.getName()}, String.class));
    } catch (SQLiteConstraintException sqlce) {
        throw new DatabaseControllerException("The given Slave does not exist in the database"
                + " or the name is already used by another Module", sqlce);
    }
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:31,代码来源:SlaveController.java

示例13: addPermission

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
/**
 * Adds a new Permission to the database.
 *
 * @param permission Permission to add.
 * @param moduleName Module the permission applies for.
 */
public void addPermission(de.unipassau.isl.evs.ssh.core.sec.Permission permission,
                          String moduleName) throws DatabaseControllerException {
    try {
        if (Strings.isNullOrEmpty(moduleName)) {
            databaseConnector.executeSql("insert into "
                    + DatabaseContract.Permission.TABLE_NAME
                    + " (" + DatabaseContract.Permission.COLUMN_NAME + ")"
                    + " values (?)", new String[] { permission.toString() }
            );
        } else {
            databaseConnector.executeSql("insert into "
                            + DatabaseContract.Permission.TABLE_NAME
                            + " (" + DatabaseContract.Permission.COLUMN_NAME
                            + ", " + DatabaseContract.Permission.COLUMN_ELECTRONIC_MODULE_ID + ")"
                            + "values (?, (" + DatabaseContract.SqlQueries.MODULE_ID_FROM_NAME_SQL_QUERY + "))",
                    new String[] { permission.toString(), moduleName }
            );
        }
    } catch (SQLiteConstraintException sqlce) {
        throw new DatabaseControllerException("Either the name-module combination is already exists in the database"
                + " or the given module doesn't exist.", sqlce);
    }
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:30,代码来源:PermissionController.java

示例14: testOnUpgradeWithColumnChangeToNotNull

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
@Test
public void testOnUpgradeWithColumnChangeToNotNull() throws Exception {
    getHelperInstance()
            .getReadableDatabase()
            .execSQL("CREATE TABLE testTable3 ("
                    + "    `xx` INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + "    `str` TEXT,"
                    + "    `unique` UNIQUE,"
                    + "    `foreign` INTEGER,"
                    + "    FOREIGN KEY(`foreign`) REFERENCES test_table(`unique`)"
                    + ");"
            );

    SQLiteOperator<TestTable3> operator = SQLiteOperator.from(getContext(), TestTable3.class);
    TestTable3 t = new TestTable3();
    operator.save(t).executeBlocking();
    operator.delete(t).executeBlocking();
    getHelperInstance().onUpgrade(getHelperInstance().getWritableDatabase(), 1, 2);
    exception.expect(SQLiteConstraintException.class);
    operator.save(new TestTable3()).executeBlocking();
}
 
开发者ID:jeppeman,项目名称:HighLite,代码行数:22,代码来源:SQLiteOperatorTest.java

示例15: testOnUpgradeWithColumnChangeToUnique

import android.database.sqlite.SQLiteConstraintException; //导入依赖的package包/类
@Test
public void testOnUpgradeWithColumnChangeToUnique() throws Exception {
    getHelperInstance()
            .getReadableDatabase()
            .execSQL("CREATE TABLE testTable3 ("
                    + "    `xx` INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + "    `str` TEXT,"
                    + "    `unique` TEXT,"
                    + "    `foreign` INTEGER,"
                    + "    FOREIGN KEY(`foreign`) REFERENCES test_table(`unique`)"
                    + ");"
            );

    SQLiteOperator<TestTable3> operator = SQLiteOperator.from(getContext(), TestTable3.class);
    getHelperInstance().onUpgrade(getHelperInstance().getWritableDatabase(), 1, 2);
    exception.expect(SQLiteConstraintException.class);
    TestTable3 t = new TestTable3();
    t.str = "not null";
    t.unique = "a";
    operator.save(t).executeBlocking();
    t = new TestTable3();
    t.str = "xxx";
    t.unique = "a";
    operator.save(t).executeBlocking();
}
 
开发者ID:jeppeman,项目名称:HighLite,代码行数:26,代码来源:SQLiteOperatorTest.java


注:本文中的android.database.sqlite.SQLiteConstraintException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。