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


Java SQLiteStatement类代码示例

本文整理汇总了Java中net.sqlcipher.database.SQLiteStatement的典型用法代码示例。如果您正苦于以下问题:Java SQLiteStatement类的具体用法?Java SQLiteStatement怎么用?Java SQLiteStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SQLiteStatement类属于net.sqlcipher.database包,在下文中一共展示了SQLiteStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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