Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insertOrThrow to provide information about errors #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/com/activeandroid/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ else if (ReflectionUtils.isSubclassOf(fieldType, Enum.class)) {
}

if (mId == null) {
mId = db.insert(mTableInfo.getTableName(), null, values);
mId = db.insertOrThrow(mTableInfo.getTableName(), null, values);
}
else {
db.update(mTableInfo.getTableName(), values, idName+"=" + mId, null);
Expand Down
8 changes: 4 additions & 4 deletions src/com/activeandroid/content/ContentProvider.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.activeandroid.content;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
Expand All @@ -15,6 +12,9 @@
import com.activeandroid.Model;
import com.activeandroid.TableInfo;

import java.util.ArrayList;
import java.util.List;

public class ContentProvider extends android.content.ContentProvider {
//////////////////////////////////////////////////////////////////////////////////////
// PRIVATE CONSTANTS
Expand Down Expand Up @@ -93,7 +93,7 @@ public String getType(Uri uri) {
@Override
public Uri insert(Uri uri, ContentValues values) {
final Class<? extends Model> type = getModelType(uri);
final Long id = Cache.openDatabase().insert(Cache.getTableName(type), null, values);
final Long id = Cache.openDatabase().insertOrThrow(Cache.getTableName(type), null, values);

if (id != null && id > 0) {
Uri retUri = createUri(type, id);
Expand Down