本文整理匯總了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}