本文整理汇总了Java中net.sqlcipher.database.SQLiteStatement.executeInsert方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteStatement.executeInsert方法的具体用法?Java SQLiteStatement.executeInsert怎么用?Java SQLiteStatement.executeInsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sqlcipher.database.SQLiteStatement
的用法示例。
在下文中一共展示了SQLiteStatement.executeInsert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
return true;
} else {
statement.execute();
}
} catch (SQLiteException e) {
SqlCipherConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return false;
}
示例2: executeUpdate
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
return 1;
} else {
return updateCount = statement.executeUpdateDelete();
}
} catch (SQLiteException e) {
SqlCipherConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return 0;
}
示例3: lookupAndCacheId
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* Perform an internal string-to-integer lookup using the compiled
* {@link SQLiteStatement} provided. If a mapping isn't found in database, it will be
* created. All new, uncached answers are added to the cache automatically.
*
* @param query Compiled statement used to query for the mapping.
* @param insert Compiled statement used to insert a new mapping when no
* existing one is found in cache or from query.
* @param value Value to find mapping for.
* @param cache In-memory cache of previous answers.
* @return An unique integer mapping for the given value.
*/
private long lookupAndCacheId(SQLiteStatement query, SQLiteStatement insert, String value, HashMap<String, Long> cache) {
long id = -1;
try {
// Try searching database for mapping
DatabaseUtils.bindObjectToProgram(query, 1, value);
id = query.simpleQueryForLong();
} catch (SQLiteDoneException e) {
// Nothing found, so try inserting new mapping
DatabaseUtils.bindObjectToProgram(insert, 1, value);
id = insert.executeInsert();
}
if (id != -1) {
// Cache and return the new answer
cache.put(value, id);
return id;
} else {
// Otherwise throw if no mapping found or created
throw new IllegalStateException("Couldn't find or create internal lookup table entry for value " + value);
}
}
示例4: insertWithoutSettingPk
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* Insert an entity into the table associated with a concrete DAO <b>without</b> setting key property. Warning: This
* may be faster, but the entity should not be used anymore. The entity also won't be attached to identy scope.
*
* @return row ID of newly inserted entity
*/
public long insertWithoutSettingPk(T entity) {
SQLiteStatement stmt = statements.getInsertStatement();
long rowId;
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
bindValues(stmt, entity);
rowId = stmt.executeInsert();
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
bindValues(stmt, entity);
rowId = stmt.executeInsert();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
return rowId;
}
示例5: executeInsert
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
private long executeInsert(T entity, SQLiteStatement stmt) {
long rowId;
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
bindValues(stmt, entity);
rowId = stmt.executeInsert();
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
bindValues(stmt, entity);
rowId = stmt.executeInsert();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
updateKeyAfterInsertAndAttach(entity, rowId, true);
return rowId;
}
示例6: insert
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
public int insert(String statement, Object[] args, FieldType[] argFieldTypes, GeneratedKeyHolder keyHolder)
throws SQLException {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement(statement);
bindArgs(stmt, args, argFieldTypes);
long rowId = stmt.executeInsert();
if (keyHolder != null) {
keyHolder.addKey(rowId);
}
/*
* I've decided to not do the CHANGES() statement here like we do down below in UPDATE because we know that
* it worked (since it didn't throw) so we know that 1 is right.
*/
int result = 1;
logger.trace("{}: insert statement is compiled and executed, changed {}: {}", this, result, statement);
return result;
} catch (android.database.SQLException e) {
throw SqlExceptionUtil.create("inserting to database failed: " + statement, e);
} finally {
if (stmt != null) {
stmt.close();
}
}
}
示例7: executeInsert
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* See {@link #executeInsert(String, SQLiteStatement)} for usage. This overload allows for triggering multiple tables.
*
* @see BriteDatabase#executeInsert(String, SQLiteStatement)
*/
@WorkerThread
public long executeInsert(Set<String> tables, SQLiteStatement statement) {
if (logging) log("EXECUTE\n %s", statement);
long rowId = statement.executeInsert();
if (rowId != -1) {
// Only send a table trigger if the insert was successful.
sendTableTrigger(tables);
}
return rowId;
}
示例8: insertNormalizedNameLookup
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
private void insertNormalizedNameLookup(SQLiteStatement stmt, long rawContactId, long dataId, int lookupType,
String normalizedName) {
stmt.bindLong(1, rawContactId);
stmt.bindLong(2, dataId);
stmt.bindLong(3, lookupType);
stmt.bindString(4, normalizedName);
stmt.executeInsert();
}
示例9: executeInsertInTx
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
private void executeInsertInTx(SQLiteStatement stmt, Iterable<T> entities, boolean setPrimaryKey) {
db.beginTransaction();
try {
synchronized (stmt) {
if (identityScope != null) {
identityScope.lock();
}
try {
for (T entity : entities) {
bindValues(stmt, entity);
if (setPrimaryKey) {
long rowId = stmt.executeInsert();
updateKeyAfterInsertAndAttach(entity, rowId, false);
} else {
stmt.execute();
}
}
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}