android – 达到数据库的编译SQL语句高速缓存的MAX大小

前端之家收集整理的这篇文章主要介绍了android – 达到数据库的编译SQL语句高速缓存的MAX大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码
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,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
原文链接:https://www.f2er.com/android/310722.html

猜你在找的Android相关文章