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


Java SQLiteStatement.executeInsert方法代码示例

本文整理汇总了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;
}
 
开发者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: 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

示例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;
}
 
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:30,代码来源:AbstractDao.java

示例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;
}
 
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:24,代码来源:AbstractDao.java

示例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();
		}
	}
}
 
开发者ID:d-tarasov,项目名称:ormlite-android-sqlcipher,代码行数:26,代码来源:AndroidDatabaseConnection.java

示例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;
}
 
开发者ID:jiechic,项目名称:sqlbrite-sqlcipher,代码行数:17,代码来源:BriteDatabase.java

示例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();
}
 
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:10,代码来源:ScContactsDatabaseHelper.java

示例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();
    }
}
 
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:29,代码来源:AbstractDao.java


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