对于与查询相关的数据库问题,已达到已编译 SQL 语句缓存的最大大小?

发布于 2024-11-07 21:07:20 字数 1311 浏览 0 评论 0原文

朋友们,

我写了以下sqlite插入语句,这似乎是错误的。 在插入行之前,我检查记录是否存在,然后不要插入(ATM 数据超过 600 条记录)

已达到数据库编译 sql 语句缓存的最大大小。缓存中没有此 sql 语句的空间。从 atm where atmid 选择 1 =251 请更改您的sql语句以使用“?”对于bindargs,而不是

public void addAtm(ATM atm)
    {

db.execSQL("INSERT INTO " + AtmsTable.NAME + 
        "(" +AtmsTable.COL_ID + ","
        +AtmsTable.COL_BankID +"," 
        + AtmsTable.COL_BankNAME+","
        + AtmsTable.COL_BankPhone+","
        + AtmsTable.COL_BankAddress+","
        + AtmsTable.COL_BankCoordinates+","
        + AtmsTable.COL_BankCity+","
        + AtmsTable.COL_BankWebaddress+") Values (" 
        +atm.getAtmID()+","
        +atm.getBankID()
        + ",'" + atm.getBankName().trim()
        +"','" + atm.getPhone()
        +"','" + atm.getAddress()
        +"','" + atm.getCoordinates()
        +"','" + atm.getCity()
        +"','" + atm.getWebAddress()+ "');");

}

并且

public boolean atmExists(int atmId)
    {
        OpenIfNotOpened();
         Cursor cursor = db.rawQuery("select 1 from " + AtmsTable.NAME  +" where " + AtmsTable.COL_ID + "=" + atmId,null);
               boolean exists = (cursor.getCount() > 0);
               cursor.close();
               return exists;
    }

我收到以下错误消息

任何帮助将不胜感激。

friends,

i have written following sqlite insert statement which seems to be wrong.
before inserting row i am checking if record exists then dont insert(ATM data is more than 600 records)

Reached max size for compiled sql statement cache for database.no space for this sql statement in cache.select 1 from atm where atmid=251 please change your sql statment to use "?" for bindargs, instead of

public void addAtm(ATM atm)
    {

db.execSQL("INSERT INTO " + AtmsTable.NAME + 
        "(" +AtmsTable.COL_ID + ","
        +AtmsTable.COL_BankID +"," 
        + AtmsTable.COL_BankNAME+","
        + AtmsTable.COL_BankPhone+","
        + AtmsTable.COL_BankAddress+","
        + AtmsTable.COL_BankCoordinates+","
        + AtmsTable.COL_BankCity+","
        + AtmsTable.COL_BankWebaddress+") Values (" 
        +atm.getAtmID()+","
        +atm.getBankID()
        + ",'" + atm.getBankName().trim()
        +"','" + atm.getPhone()
        +"','" + atm.getAddress()
        +"','" + atm.getCoordinates()
        +"','" + atm.getCity()
        +"','" + atm.getWebAddress()+ "');");

}

and

public boolean atmExists(int atmId)
    {
        OpenIfNotOpened();
         Cursor cursor = db.rawQuery("select 1 from " + AtmsTable.NAME  +" where " + AtmsTable.COL_ID + "=" + atmId,null);
               boolean exists = (cursor.getCount() > 0);
               cursor.close();
               return exists;
    }

and i am getting following error message

any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2024-11-14 21:07:20

公共无效execSQL(字符串sql)

自:API 级别 1 执行单个
不是 SELECT 或的 SQL 语句
任何其他返回的 SQL 语句
数据。它没有办法返回任何
数据(例如受影响的人数)
行)。相反,我们鼓励您
使用插入(字符串,字符串,
内容值),更新(字符串,
ContentValues、字符串、字符串[])等
等,如果可能的话。

只需使用:

ContentValues vals = new ContentValues();
vals.put(AtmsTable.COL_BankID, atm.getBankID());
vals.put(AtmsTable.COL_BankNAME, atm.getBankName().trim());
/...
if(db.update(AtmsTable.NAME, vals, AtmsTable.COL_ID + "=?", new String[]{Integer.toString(atm.getAtmID())}) == 0){
  vals.put(AtmsTable.COL_ID, atm.getAtmID());
  db.insert(AtmsTable.NAME, null, vals);
}

public void execSQL (String sql)

Since: API Level 1 Execute a single
SQL statement that is NOT a SELECT or
any other SQL statement that returns
data. It has no means to return any
data (such as the number of affected
rows). Instead, you're encouraged to
use insert(String, String,
ContentValues), update(String,
ContentValues, String, String[]), et
al, when possible.

just use:

ContentValues vals = new ContentValues();
vals.put(AtmsTable.COL_BankID, atm.getBankID());
vals.put(AtmsTable.COL_BankNAME, atm.getBankName().trim());
/...
if(db.update(AtmsTable.NAME, vals, AtmsTable.COL_ID + "=?", new String[]{Integer.toString(atm.getAtmID())}) == 0){
  vals.put(AtmsTable.COL_ID, atm.getAtmID());
  db.insert(AtmsTable.NAME, null, vals);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文