本文整理汇总了Java中net.sqlcipher.database.SQLiteStatement类的典型用法代码示例。如果您正苦于以下问题:Java SQLiteStatement类的具体用法?Java SQLiteStatement怎么用?Java SQLiteStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLiteStatement类属于net.sqlcipher.database包,在下文中一共展示了SQLiteStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:requery,项目名称:requery,代码行数:22,代码来源:SqlCipherStatement.java
示例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;
}
开发者ID:requery,项目名称:requery,代码行数:22,代码来源:SqlCipherStatement.java
示例3: updateHasPhoneNumber
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/**
* Updates the {@link RawContacts#HAS_PHONE_NUMBER} flag for the aggregate contact containing the
* specified raw contact.
*/
public void updateHasPhoneNumber(SQLiteDatabase db, long rawContactId) {
final SQLiteStatement hasPhoneNumberUpdate = db.compileStatement(
"UPDATE " + Tables.RAW_CONTACTS +
" SET " + RawContacts.HAS_PHONE_NUMBER + "="
+ "(SELECT (CASE WHEN COUNT(*)=0 THEN 0 ELSE 1 END)"
+ " FROM " + Tables.DATA_JOIN_RAW_CONTACTS
+ " WHERE " + DataColumns.MIMETYPE_ID + "=?"
+ " AND " + Phone.NUMBER + " NOT NULL)" +
" WHERE " + RawContacts._ID + "=?");
try {
hasPhoneNumberUpdate.bindLong(1, mDbHelper.getMimeTypeId(Phone.CONTENT_ITEM_TYPE));
hasPhoneNumberUpdate.bindLong(2, rawContactId);
hasPhoneNumberUpdate.execute();
} finally {
hasPhoneNumberUpdate.close();
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:23,代码来源:SimpleRawContactAggregator.java
示例4: insertNameLookup
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
private void insertNameLookup(SQLiteDatabase db) {
db.execSQL("DELETE FROM " + Tables.NAME_LOOKUP);
SQLiteStatement nameLookupInsert = db.compileStatement(
"INSERT OR IGNORE INTO " + Tables.NAME_LOOKUP + "("
+ NameLookupColumns.RAW_CONTACT_ID + ","
+ NameLookupColumns.DATA_ID + ","
+ NameLookupColumns.NAME_TYPE + ","
+ NameLookupColumns.NORMALIZED_NAME +
") VALUES (?,?,?,?)");
try {
insertStructuredNameLookup(db, nameLookupInsert);
insertEmailLookup(db, nameLookupInsert);
// insertNicknameLookup(db, nameLookupInsert);
} finally {
nameLookupInsert.close();
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:20,代码来源:ScContactsDatabaseHelper.java
示例5: insertStructuredNameLookup
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/**
* Inserts name lookup rows for all structured names in the database.
*/
private void insertStructuredNameLookup(SQLiteDatabase db, SQLiteStatement nameLookupInsert) {
NameSplitter nameSplitter = createNameSplitter();
NameLookupBuilder nameLookupBuilder = new StructuredNameLookupBuilder(nameSplitter, /* new CommonNicknameCache(db), */
nameLookupInsert);
final long mimeTypeId = lookupMimeTypeId(db, StructuredName.CONTENT_ITEM_TYPE);
Cursor cursor = db.query(StructuredNameQuery.TABLE, StructuredNameQuery.COLUMNS, StructuredNameQuery.SELECTION,
new String[] { String.valueOf(mimeTypeId) }, null, null, null);
try {
while (cursor.moveToNext()) {
long dataId = cursor.getLong(StructuredNameQuery.ID);
long rawContactId = cursor.getLong(StructuredNameQuery.RAW_CONTACT_ID);
String name = cursor.getString(StructuredNameQuery.DISPLAY_NAME);
int fullNameStyle = nameSplitter.guessFullNameStyle(name);
fullNameStyle = nameSplitter.getAdjustedFullNameStyle(fullNameStyle);
nameLookupBuilder.insertNameLookup(rawContactId, dataId, name, fullNameStyle);
}
}
finally {
cursor.close();
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:26,代码来源:ScContactsDatabaseHelper.java
示例6: insertEmailLookup
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/**
* Inserts name lookup rows for all email addresses in the database.
*/
private void insertEmailLookup(SQLiteDatabase db, SQLiteStatement nameLookupInsert) {
final long mimeTypeId = lookupMimeTypeId(db, Email.CONTENT_ITEM_TYPE);
Cursor cursor = db.query(EmailQuery.TABLE, EmailQuery.COLUMNS, EmailQuery.SELECTION,
new String[] { String.valueOf(mimeTypeId) }, null, null, null);
try {
while (cursor.moveToNext()) {
long dataId = cursor.getLong(EmailQuery.ID);
long rawContactId = cursor.getLong(EmailQuery.RAW_CONTACT_ID);
String address = cursor.getString(EmailQuery.ADDRESS);
address = extractHandleFromEmailAddress(address);
insertNameLookup(nameLookupInsert, rawContactId, dataId, NameLookupType.EMAIL_BASED_NICKNAME, address);
}
}
finally {
cursor.close();
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:21,代码来源:ScContactsDatabaseHelper.java
示例7: 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);
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:33,代码来源:ScContactsDatabaseHelper.java
示例8: lookupMimeTypeId
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
private long lookupMimeTypeId(String mimetype, SQLiteDatabase db) {
final SQLiteStatement mimetypeQuery = db.compileStatement(
"SELECT " + MimetypesColumns._ID +
" FROM " + Tables.MIMETYPES +
" WHERE " + MimetypesColumns.MIMETYPE + "=?");
final SQLiteStatement mimetypeInsert = db.compileStatement(
"INSERT INTO " + Tables.MIMETYPES + "("
+ MimetypesColumns.MIMETYPE +
") VALUES (?)");
try {
return lookupAndCacheId(mimetypeQuery, mimetypeInsert, mimetype, mMimetypeCache);
} finally {
mimetypeQuery.close();
mimetypeInsert.close();
}
}
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:19,代码来源:ScContactsDatabaseHelper.java
示例9: 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;
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:30,代码来源:AbstractDao.java
示例10: 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;
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:24,代码来源:AbstractDao.java
示例11: deleteByKey
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/** Deletes an entity with the given PK from the database. Currently, only single value PK entities are supported. */
public void deleteByKey(K key) {
assertSinglePk();
SQLiteStatement stmt = statements.getDeleteStatement();
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
deleteByKeyInsideSynchronized(key, stmt);
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
deleteByKeyInsideSynchronized(key, stmt);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (identityScope != null) {
identityScope.remove(key);
}
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:25,代码来源:AbstractDao.java
示例12: update
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
public void update(T entity) {
assertSinglePk();
SQLiteStatement stmt = statements.getUpdateStatement();
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
updateInsideSynchronized(entity, stmt, true);
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
updateInsideSynchronized(entity, stmt, true);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:21,代码来源:AbstractDao.java
示例13: updateInTx
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/**
* Updates the given entities in the database using a transaction.
*
* @param entities
* The entities to insert.
*/
public void updateInTx(Iterable<T> entities) {
SQLiteStatement stmt = statements.getUpdateStatement();
db.beginTransaction();
try {
synchronized (stmt) {
if (identityScope != null) {
identityScope.lock();
}
try {
for (T entity : entities) {
updateInsideSynchronized(entity, stmt, false);
}
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:30,代码来源:AbstractDao.java
示例14: getStatement
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
private SQLiteStatement getStatement(boolean allowReplace) throws SQLException {
if (allowReplace) {
if (mReplaceStatement == null) {
if (mInsertSQL == null) buildSQL();
// chop "INSERT" off the front and prepend "INSERT OR REPLACE" instead.
String replaceSQL = "INSERT OR REPLACE" + mInsertSQL.substring(6);
mReplaceStatement = mDb.compileStatement(replaceSQL);
}
return mReplaceStatement;
} else {
if (mInsertStatement == null) {
if (mInsertSQL == null) buildSQL();
mInsertStatement = mDb.compileStatement(mInsertSQL);
}
return mInsertStatement;
}
}
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:18,代码来源:DatabaseUtils.java
示例15: 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();
}
}
}
开发者ID:d-tarasov,项目名称:ormlite-android-sqlcipher,代码行数:26,代码来源:AndroidDatabaseConnection.java
示例16: bindValues
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
@Override protected final void bindValues(SQLiteStatement stmt, User entity) {
stmt.clearBindings();
stmt.bindLong(1, entity.getId());
String name = entity.getName();
if (name != null) {
stmt.bindString(2, name);
}
stmt.bindLong(3, entity.getAge());
}
开发者ID:liuguoquan727,项目名称:android-study,代码行数:11,代码来源:UserDao.java
示例17: executeUpdateDelete
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
/**
* See {@link #executeUpdateDelete(String, SQLiteStatement)} for usage. This overload allows for triggering multiple tables.
*
* @see BriteDatabase#executeUpdateDelete(String, SQLiteStatement)
*/
@WorkerThread
@RequiresApi(Build.VERSION_CODES.HONEYCOMB)
public int executeUpdateDelete(Set<String> tables, SQLiteStatement statement) {
if (logging) log("EXECUTE\n %s", statement);
int rows = statement.executeUpdateDelete();
if (rows > 0) {
// Only send a table trigger if rows were affected.
sendTableTrigger(tables);
}
return rows;
}
开发者ID:jiechic,项目名称:sqlbrite-sqlcipher,代码行数:18,代码来源:BriteDatabase.java
示例18: 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;
}
开发者ID:jiechic,项目名称:sqlbrite-sqlcipher,代码行数:17,代码来源:BriteDatabase.java
示例19: bulkKeyStore
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
private void bulkKeyStore(int c, String dbid, String values[]) {
if(database !=null && database.isOpen()) {
SQLiteStatement statement =
database.compileStatement("INSERT INTO " +
TABLE_KEYS + " VALUES (null, ?, ?, ?, ?);");
database.beginTransaction();
while (c < (values.length - 1)) {
statement.clearBindings();
statement.bindString(1, values[c]);
statement.bindString(2, dbid);
statement.bindString(3, values[c + 1]);
statement.bindString(4, values[c + 2]);
statement.execute();
c = c + 3;
}
database.setTransactionSuccessful();
database.endTransaction();
//disable adding contact if over
Cursor contactCount = database.rawQuery("SELECT * FROM " + TABLE_CONTACTS, null);
int max_contacts = context.getResources().getInteger(R.integer.config_max_contacts);
if (contactCount.getCount() >= max_contacts) {
prefs.edit().putBoolean(CONST.PREFS_CONTACTADD, false).apply();
}
contactCount.close();
}
}
开发者ID:gtom1984,项目名称:Eulen,代码行数:33,代码来源:EulenDatabase.java
示例20: getIndexSpanningIteratorOrNull
import net.sqlcipher.database.SQLiteStatement; //导入依赖的package包/类
protected SqlStorageIterator<T> getIndexSpanningIteratorOrNull(SQLiteDatabase db, boolean includeData) {
//If we're just iterating over ID's, we may want to use a different, much
//faster method depending on our stats. This method retrieves the
//index records that _don't_ exist so we can assume the spans that
//do.
if (!includeData && STORAGE_OPTIMIZATIONS_ACTIVE) {
SQLiteStatement min = db.compileStatement("SELECT MIN(" + DatabaseHelper.ID_COL + ") from " + table);
SQLiteStatement max = db.compileStatement("SELECT MAX(" + DatabaseHelper.ID_COL + ") from " + table);
SQLiteStatement count = db.compileStatement("SELECT COUNT(" + DatabaseHelper.ID_COL + ") from " + table);
int minValue = (int)min.simpleQueryForLong();
int maxValue = (int)max.simpleQueryForLong() + 1;
int countValue = (int)count.simpleQueryForLong();
min.close();
max.close();
count.close();
double density = countValue / (maxValue - minValue * 1.0);
//Ok, so basic metrics:
//1) Only use a covering iterator if the number of records is > 1k
//2) Only use a covering iterator if the number of records is less than 100k (vital, hard limit)
//3) Only use a covering iterator if the record density is 50% or more
if (countValue > 1000 &&
countValue < 100000 &&
density >= 0.5) {
return getCoveringIndexIterator(db, minValue, maxValue, countValue);
}
}
return null;
}
开发者ID:dimagi,项目名称:commcare-android,代码行数:36,代码来源:SqlStorage.java
注:本文中的net.sqlcipher.database.SQLiteStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论