gpt4 book ai didi

android - 已达到数据库的已编译 sql 语句缓存的最大大小

转载 作者:IT王子 更新时间:2023-10-29 06:21:19 26 4
gpt4 key购买 nike

我的代码是

ContentValues values; 
values = new ContentValues();
values.put(SQLHelper.EMPLOYEE_LPN, jsObj.getString("lpn"));
db.update(SQLHelper.EMPLOYEE_TABLE, values,
"EMPLOYEE_LPN ='" + jsObj.getString("lpn") + "'",
null);

Log Cat 中显示警告

08-31 15:19:45.297: WARN/Database(2868): Reached MAX size for compiled-sql statement cache for database /data/data/org.sipdroid.sipua/databases/test.db; i.e., 
NO space for this sql statement in cache:
SELECT EMPLOYEE_NAME FROM eyemployee WHERE EMPLOYEE_LPN ='1169162'.
Please change your sql statements to use '?' for bindargs, instead of using actual values

如何解决?

最佳答案

看例子8-3和8-4 here .

示例 8-3。使用更新方法

/**
* Update a job in the database.
* @param job_id The job id of the existing job
* @param employer_id The employer offering the job
* @param title The job title
* @param description The job description
*/
public void editJob(long job_id, long employer_id, String title, String description) {
ContentValues map = new ContentValues();
map.put("employer_id", employer_id);
map.put("title", title);
map.put("description", description);
String[] whereArgs = new String[]{Long.toString(job_id)};
try{
getWritableDatabase().update("jobs", map, "_id=?", whereArgs);
} catch (SQLException e) {
Log.e("Error writing new job", e.toString());
}
}

下面是示例 8-3 中代码的一些要点:

例 8-4 展示了如何使用 execSQL 方法。
例 8-4。使用 execSQL 方法

/**
* Update a job in the database.
* @param job_id The job id of the existing job
* @param employer_id The employer offering the job
* @param title The job title
* @param description The job description
*/
public void editJob(long job_id, long employer_id, String title, String description) {
String sql =
"UPDATE jobs " +
"SET employer_id = ?, "+
" title = ?, "+
" description = ? "+
"WHERE _id = ? ";
Object[] bindArgs = new Object[]{employer_id, title, description, job_id};
try{
getWritableDatabase().execSQL(sql, bindArgs);
} catch (SQLException e) {
Log.e("Error writing new job", e.toString());
}
}

该消息要求您使参数使用 sql 变量而不是 sql 文字。

解析每个sql查询,生成计划,并存储在sql语句缓存中。

从缓存中获取具有相同文本的查询。

  --One query
SELECT * FROM Customers WHERE Id = @1 (@1 = 3)
SELECT * FROM Customers WHERE Id = @1 (@1 = 4)
SELECT * FROM Customers WHERE Id = @1 (@1 = 5)

在缓存中找不到具有不同文本(包括文字)的查询,并且(无用地)添加到缓存中。

  --Three Queries.
SELECT * FROM Customers WHERE Id = 3
SELECT * FROM Customers WHERE Id = 4
SELECT * FROM Customers WHERE Id = 5

关于android - 已达到数据库的已编译 sql 语句缓存的最大大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com