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


Java SQLiteDatabase.insertOrThrow方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.insertOrThrow方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.insertOrThrow方法的具体用法?Java SQLiteDatabase.insertOrThrow怎么用?Java SQLiteDatabase.insertOrThrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


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

示例1: updateCache

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void updateCache(String tablename) {
    this.errorString = "";
    SQLiteDatabase db = MFBMain.mDBHelper.getWritableDatabase();

    try {
        deleteTableEntry(db, tablename);
        ContentValues values = new ContentValues();
        Date dt = new Date();
        SimpleDateFormat s = new SimpleDateFormat(MFBConstants.TIMESTAMP, Locale.US);

        values.put(COL_LASTREFRESH, s.format(dt));
        values.put(COL_TABLENAME, tablename);

        db.insertOrThrow(CACHE_TABLE, null, values);
    } catch (Exception ex) {
        this.errorString = "Error updating cache for table " + tablename + ex.getMessage();
        Log.e(MFBConstants.LOG_TAG, this.errorString);
    }
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:20,代码来源:DBCache.java

示例2: addCinema

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addCinema(Cinema cinema) {
    if(getCinemaByID(cinema.getID()) != null) {
        updateCinema(cinema);
    } else {
        SQLiteDatabase db = getWritableDatabase();
        db.beginTransaction();
        try {
            db.insertOrThrow("Cinemas", null, cinema.toContentValues());
            db.setTransactionSuccessful();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            db.endTransaction();
        }
    }
}
 
开发者ID:jpelgrom,项目名称:Movie-Notifier-Android,代码行数:17,代码来源:DBHelper.java

示例3: insert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的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

示例4: updateOrInsertBookSync

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int updateOrInsertBookSync(
        SQLiteDatabase db,
        long bookId,
        String repoUrl,
        String rookUrl,
        String revision,
        long mtime) {

    long repoUrlId = getOrInsertRepoUrl(db, repoUrl);
    long rookUrlId = DbRookUrl.getOrInsert(db, rookUrl);
    long rookId = getOrInsertRook(db, rookUrlId, repoUrlId);
    long rookRevisionId = getOrInsertVersionedRook(db, rookId, revision, mtime);

    ContentValues values = new ContentValues();
    values.put(DbBookSync.BOOK_VERSIONED_ROOK_ID, rookRevisionId);
    values.put(DbBookSync.BOOK_ID, bookId);

    long id = DatabaseUtils.getId(db, DbBookSync.TABLE, DbBookSync.BOOK_ID + "=" + bookId, null);
    if (id != 0) {
        db.update(DbBookSync.TABLE, values, DbBookSync._ID + "=" + id, null);
    } else {
        db.insertOrThrow(DbBookSync.TABLE, null, values);
    }

    return 1;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:27,代码来源:Provider.java

示例5: setValue

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void setValue(String key, String value) {
    SQLiteDatabase writableDatabase = this.openHelper.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(DBConstants.SETTING_COL_KEY, key);
        contentValues.put(DBConstants.SETTING_COL_VALUE, value);
        if (getValue(key) == null) {
            writableDatabase.insertOrThrow(DBConstants.TABLE_SETTING, null, contentValues);
        } else {
            writableDatabase.update(DBConstants.TABLE_SETTING, contentValues, "key='" + key + "'", null);
        }
        writableDatabase.setTransactionSuccessful();
    } finally {
        writableDatabase.endTransaction();
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:18,代码来源:SettingManager.java

示例6: getOrInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static long getOrInsert(SQLiteDatabase db, String rookUrl) {
    long id = DatabaseUtils.getId(
            db,
            TABLE,
            ROOK_URL + "=?",
            new String[] { rookUrl });

    if (id == 0) {
        ContentValues values = new ContentValues();
        values.put(ROOK_URL, rookUrl);

        id = db.insertOrThrow(TABLE, null, values);
    }

    return id;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:17,代码来源:DbRookUrl.java

示例7: getOrInsertOrgRange

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Gets {@link OrgDateTime} from database or inserts a new record if it doesn't exist.
 * @return {@link OrgDateTime} database ID
 */
private long getOrInsertOrgRange(SQLiteDatabase db, OrgRange range) {
    long id = DatabaseUtils.getId(
            db,
            DbOrgRange.TABLE,
            DbOrgRange.STRING + "=?",
            new String[] { range.toString() });

    if (id == 0) {
        ContentValues values = new ContentValues();

        long startTimestampId = getOrInsertOrgTime(db, range.getStartTime());

        long endTimestampId = 0;
        if (range.getEndTime() != null) {
            endTimestampId = getOrInsertOrgTime(db, range.getEndTime());
        }

        DbOrgRange.toContentValues(values, range, startTimestampId, endTimestampId);

        id = db.insertOrThrow(DbOrgRange.TABLE, null, values);
    }

    return id;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:29,代码来源:Provider.java

示例8: getOrInsertOrgRange

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Gets {@link OrgDateTime} from database or inserts a new record if it doesn't exist.
 * @return {@link OrgDateTime} database ID
 */
private static long getOrInsertOrgRange(SQLiteDatabase db, OrgRange range) {
    long id = DatabaseUtils.getId(
            db,
            DbOrgRange.TABLE,
            DbOrgRange.STRING + "=?",
            new String[] { range.toString() });

    if (id == 0) {
        ContentValues values = new ContentValues();

        long startTimestampId = getOrInsertOrgTime(db, range.getStartTime());

        long endTimestampId = 0;
        if (range.getEndTime() != null) {
            endTimestampId = getOrInsertOrgTime(db, range.getEndTime());
        }

        DbOrgRange.toContentValues(values, range, startTimestampId, endTimestampId);

        id = db.insertOrThrow(DbOrgRange.TABLE, null, values);
    }

    return id;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:29,代码来源:DbNote.java

示例9: getOrInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static long getOrInsert(SQLiteDatabase db, String value) {
    long id = DatabaseUtils.getId(
            db,
            TABLE,
            VALUE + " = ?",
            new String[] { value });

    if (id == 0) {
        ContentValues values = new ContentValues();
        values.put(VALUE, value);

        id = db.insertOrThrow(TABLE, null, values);
    }

    return id;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:17,代码来源:DbPropertyValue.java

示例10: addRule

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addRule(FileSynchronizerRule rule){
	SQLiteDatabase db = getWritableDatabase();
	ContentValues values = new ContentValues();

	values.clear();
	//values.put("id", rule.getId());
	values.put("id", rule.getId());
	values.put("volumeNameToSync", rule.getVolumeNameToSync());
	values.put("volumePassword", rule.getVolumePassword());
	values.put("volumePathToSync", rule.getVolumePathToSync());
	values.put("deleteSrcFileAfterSync", rule.getDeleteSrcFileAfterSync());
	values.put("syncOnlyOnWifi", rule.getSyncOnlyOnWifi());
	values.put("localPathToSync", rule.getLocalPathToSync());

	Log.d(TAG, "addRule()");

	db.insertOrThrow("SYNC_RULES", null, values);
	
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:20,代码来源:EDDBHelper.java

示例11: getOrInsertRepoUrl

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private long getOrInsertRepoUrl(SQLiteDatabase db, String repoUrl) {
    long id = DatabaseUtils.getId(
            db,
            DbRepo.TABLE,
            DbRepo.REPO_URL + "=?",
            new String[] { repoUrl });

    if (id == 0) {
        ContentValues values = new ContentValues();
        values.put(DbRepo.REPO_URL, repoUrl);
        values.put(DbRepo.IS_REPO_ACTIVE, 0);

        id = db.insertOrThrow(DbRepo.TABLE, null, values);
    }

    return id;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:18,代码来源:Provider.java

示例12: updateOrInsertBookLink

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private int updateOrInsertBookLink(SQLiteDatabase db, long bookId, String repoUrl, String rookUrl) {
    long repoUrlId = getOrInsertRepoUrl(db, repoUrl);
    long rookUrlId = DbRookUrl.getOrInsert(db, rookUrl);
    long rookId = getOrInsertRook(db, rookUrlId, repoUrlId);

    ContentValues values = new ContentValues();
    values.put(DbBookLink.BOOK_ID, bookId);
    values.put(DbBookLink.ROOK_ID, rookId);

    long id = DatabaseUtils.getId(db, DbBookLink.TABLE, DbBookLink.BOOK_ID + "=" + bookId, null);
    if (id != 0) {
        db.update(DbBookLink.TABLE, values, DbBookLink._ID + "=" + id, null);
    } else {
        db.insertOrThrow(DbBookLink.TABLE, null, values);
    }

    return 1;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:19,代码来源:Provider.java

示例13: addAtividade

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addAtividade(Atividade atividade) throws SQLiteException {
    SQLiteDatabase db = this.getWritableDatabase();
    db.insertOrThrow(TABLE_ATIVIDADE, null, getAtividadeRow(atividade));
    db.close(); // Closing database connection

    addMinistrantes(atividade);
}
 
开发者ID:secompufscar,项目名称:app_secompufscar,代码行数:8,代码来源:DatabaseHandler.java

示例14: cacheTransaltion

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
protected void cacheTransaltion(Context context, String key, String value, String lang){
    // Create new helper
    IATDatabaseHelper dbHelper = new IATDatabaseHelper(context);
    // Get the database. If it does not exist, this is where it will
    // also be created.
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // Create insert entries
    ContentValues values = new ContentValues();
    values.put(IATTranslationContract.Translation.COLUMN_KEY, key);
    values.put(IATTranslationContract.Translation.COLUMN_VALUE, value);
    values.put(IATTranslationContract.Translation.COLUMN_LANG, lang);

    // Insert the new row, returning the primary key value of the new row
    try{
        long newRowId;
        newRowId = db.insertOrThrow(
                TABLE_NAME,
                null,
                values);
    }catch(SQLiteConstraintException sce){
        Log.d(TAG, "key(" + key + ") already exist for lang(" + lang + ")");
        //android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: Translation.key, Translation.lang (code 2067)
    }catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:mizutori,项目名称:InAppTranslation_Android,代码行数:28,代码来源:InAppTranslation.java

示例15: insertRootNote

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private long insertRootNote(SQLiteDatabase db, long bookId) {
    Note rootNote = Note.newRootNote(bookId);

    ContentValues values = new ContentValues();
    NotesClient.toContentValues(values, rootNote);
    replaceTimestampRangeStringsWithIds(db, values);

    return db.insertOrThrow(DbNote.TABLE, null, values);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:10,代码来源:Provider.java


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