android ormlite 查询,带引号的ORMLite查询,Android

我正在使用ORMLite,使用Table RecentSearch:

@DatabaseTable(tableName = LocalStorageConfig.sql_RECENTS_TABLE_NAME)

public class RecentSearch {

@DatabaseField

public String search_text;

public static String sql_SEARCH_FIELD = "search_text";

@DatabaseField

public String location_text;

public static String sql_LOCATION_FIELD = "location_text";

@DatabaseField

public Date creation_date = new Date();

public static String sql_CREATION_DATE_FIELD = "creation_date";

它几乎一直在工作,但当我发现包含’的字符串的情况时,它似乎是一个问题.你知道怎么解决这个问题吗?我找不到我要找的东西.

这是我删除最近的功能

public boolean deleteRecent(RecentSearch search) {

try {

Dao recentsDao = recentssqlManager.getRecentsDao();

DeleteBuilder deleteBuilder = recentsDao.deleteBuilder();

deleteBuilder.where().eq(RecentSearch.sql_SEARCH_FIELD,search.getSearch_text()).and().eq(RecentSearch.sql_LOCATION_FIELD,search.location_text);

recentsDao.delete(deleteBuilder.prepare());

return true;

} catch (Exception e) {

Log.e(TAG,"Database exception",e);

return false;

}

}

这是我得到的例外情况:

java.sql.sqlException: Problems executing Android statement: DELETE FROM `recent_searches` WHERE (`search_text` = '' AND `location_text` = 'Villefranche-d'Allier,Allier' )

at com.j256.ormlite.misc.sqlExceptionUtil.create(sqlExceptionUtil.java:22)

at com.j256.ormlite.android.AndroidCompiledStatement.runUpdate(AndroidCompiledStatement.java:66)

at com.j256.ormlite.stmt.StatementExecutor.delete(StatementExecutor.java:425)

at com.j256.ormlite.dao.BaseDaoImpl.delete(BaseDaoImpl.java:347)

...

Caused by: android.database.sqlite.sqliteException: near "Allier": Syntax error:,while compiling: DELETE FROM `recent_searches` WHERE (`search_text` = '' AND `location_text` = 'Villefranche-d'Allier,Allier' )

at android.database.sqlite.sqliteCompiledsql.native_compile(Native Method)

at android.database.sqlite.sqliteCompiledsql.compile(sqliteCompiledsql.java:92)

at android.database.sqlite.sqliteCompiledsql.(sqliteCompiledsql.java:65)

at android.database.sqlite.sqliteProgram.(sqliteProgram.java:83)

at android.database.sqlite.sqliteStatement.(sqliteStatement.java:41)

at android.database.sqlite.sqliteDatabase.compileStatement(sqliteDatabase.java:1149)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值