数据库的已编译SQL语句高速缓存达到的最大大小

数据库的已编译SQL语句高速缓存达到的最大大小,第1张

数据库的已编译SQL语句高速缓存达到的最大大小

在这里查看示例8-3和8-4 。

示例8-3 使用更新方法

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方法

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 querySELECT * 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 = 3SELECt * FROM Customers WHERe Id = 4SELECt * FROM Customers WHERe Id = 5


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4980431.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存